webpack.base.conf.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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. function resolve(dir) {
  8. return path.join(__dirname, '..', dir)
  9. }
  10. module.exports = {
  11. context: path.resolve(__dirname, '../'),
  12. entry: {
  13. app: './src/main.js'
  14. },
  15. output: {
  16. path: config.build.assetsRoot,
  17. filename: '[name].js',
  18. publicPath:
  19. process.env.NODE_ENV === 'production'
  20. ? config.build.assetsPublicPath
  21. : config.dev.assetsPublicPath
  22. },
  23. resolve: {
  24. extensions: ['.js', '.vue', '.json'],
  25. alias: {
  26. '@': resolve('src'),
  27. }
  28. },
  29. module: {
  30. rules: [
  31. {
  32. test: /\.vue$/,
  33. loader: 'vue-loader',
  34. options: vueLoaderConfig
  35. },
  36. {
  37. test: /\.js$/,
  38. loader: 'babel-loader?cacheDirectory',
  39. include: [
  40. resolve('src'),
  41. resolve('test'),
  42. resolve('node_modules/webpack-dev-server/client')
  43. ]
  44. },
  45. {
  46. test: /\.svg$/,
  47. loader: 'svg-sprite-loader',
  48. include: [resolve('src/icons')],
  49. options: {
  50. symbolId: 'icon-[name]'
  51. }
  52. },
  53. {
  54. test: /\.(png|jpe?g|gif|svg)(\?.*)?$/,
  55. loader: 'url-loader',
  56. exclude: [resolve('src/icons')],
  57. options: {
  58. limit: 10000,
  59. name: utils.assetsPath('img/[name].[hash:7].[ext]')
  60. }
  61. },
  62. {
  63. test: /\.(mp4|webm|ogg|mp3|wav|flac|aac)(\?.*)?$/,
  64. loader: 'url-loader',
  65. options: {
  66. limit: 10000,
  67. name: utils.assetsPath('media/[name].[hash:7].[ext]')
  68. }
  69. },
  70. {
  71. test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/,
  72. loader: 'url-loader',
  73. options: {
  74. limit: 10000,
  75. name: utils.assetsPath('fonts/[name].[hash:7].[ext]')
  76. }
  77. },
  78. {
  79. test: /\.(xlsx|xls)$/, // 匹配 Excel 文件
  80. use: [
  81. {
  82. loader: 'file-loader',
  83. options: {
  84. name: '[name].[ext]', // 输出文件名
  85. outputPath: 'static/excels/', // 输出路径
  86. },
  87. },
  88. ],
  89. },
  90. ]
  91. },
  92. plugins: [new VueLoaderPlugin()],
  93. node: {
  94. // prevent webpack from injecting useless setImmediate polyfill because Vue
  95. // source contains it (although only uses it if it's native).
  96. setImmediate: false,
  97. // prevent webpack from injecting mocks to Node native modules
  98. // that does not make sense for the client
  99. dgram: 'empty',
  100. fs: 'empty',
  101. net: 'empty',
  102. tls: 'empty',
  103. child_process: 'empty'
  104. }
  105. }