webpack.base.conf.js 2.6 KB

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