人民医院前端

webpack.base.conf.js 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. 'use strict'
  2. const path = require('path')
  3. const utils = require('./utils')
  4. const config = require('../config')
  5. const { VueLoaderPlugin } = require('vue-loader')
  6. const vueLoaderConfig = require('./vue-loader.conf')
  7. const webpack = require('webpack')
  8. function resolve(dir) {
  9. return path.join(__dirname, '..', dir)
  10. }
  11. const createLintingRule = () => ({
  12. test: /\.(js|vue)$/,
  13. loader: 'eslint-loader',
  14. enforce: 'pre',
  15. include: [resolve('src'), resolve('test')],
  16. options: {
  17. formatter: require('eslint-friendly-formatter'),
  18. emitWarning: !config.dev.showEslintErrorsInOverlay
  19. }
  20. })
  21. module.exports = {
  22. context: path.resolve(__dirname, '../'),
  23. entry: {
  24. app: ["babel-polyfill", "./src/main.js"]
  25. },
  26. output: {
  27. path: config.build.assetsRoot,
  28. filename: '[name].js',
  29. publicPath: process.env.NODE_ENV === 'production'
  30. ? config.build.assetsPublicPath
  31. : config.dev.assetsPublicPath
  32. },
  33. resolve: {
  34. extensions: ['.js', '.vue', '.json'],
  35. alias: {
  36. 'vue$': 'vue/dist/vue.esm.js', // devtools 开发环境是开启状态 生产环境是关闭状态
  37. '@': resolve('src')
  38. // 'vue': 'vue/dist/vue.js' // devtools 是开启状态
  39. // 'vue': 'vue/dist/vue.min.js'// devtools 是关闭状态
  40. }
  41. },
  42. module: {
  43. rules: [
  44. ...(config.dev.useEslint ? [createLintingRule()] : []),
  45. {
  46. test: /\.vue$/,
  47. loader: 'vue-loader',
  48. options: vueLoaderConfig
  49. },
  50. {
  51. test: /\.js$/,
  52. loader: 'babel-loader',
  53. include: [
  54. resolve('src'),
  55. resolve('test'),
  56. resolve('node_modules/webpack-dev-server/client')
  57. ]
  58. },
  59. {
  60. test: /\.svg$/,
  61. loader: 'svg-sprite-loader',
  62. include: [resolve('src/icons')],
  63. options: {
  64. symbolId: 'icon-[name]'
  65. }
  66. },
  67. {
  68. test: /\.(png|jpe?g|gif|svg)(\?.*)?$/,
  69. loader: 'url-loader',
  70. exclude: [resolve('src/icons')],
  71. options: {
  72. limit: 10000,
  73. name: utils.assetsPath('img/[name].[hash:7].[ext]')
  74. }
  75. },
  76. {
  77. test: /\.(mp4|webm|ogg|mp3|wav|flac|aac)(\?.*)?$/,
  78. loader: 'url-loader',
  79. options: {
  80. limit: 10000,
  81. name: utils.assetsPath('media/[name].[hash:7].[ext]')
  82. }
  83. },
  84. {
  85. test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/,
  86. loader: 'url-loader',
  87. options: {
  88. limit: 10000,
  89. name: utils.assetsPath('fonts/[name].[hash:7].[ext]')
  90. }
  91. }
  92. ]
  93. },
  94. plugins: [
  95. new VueLoaderPlugin(),
  96. new webpack.ProvidePlugin({
  97. jQuery: 'jquery',
  98. $: 'jquery',
  99. jquery: 'jquery',
  100. 'window.jQuery': 'jquery'
  101. })
  102. ],
  103. node: {
  104. // prevent webpack from injecting useless setImmediate polyfill because Vue
  105. // source contains it (although only uses it if it's native).
  106. setImmediate: false,
  107. // prevent webpack from injecting mocks to Node native modules
  108. // that does not make sense for the client
  109. dgram: 'empty',
  110. fs: 'empty',
  111. net: 'empty',
  112. tls: 'empty',
  113. child_process: 'empty'
  114. }
  115. }