webpack.base.conf.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. 'use strict'
  2. const path = require('path')
  3. const utils = require('./utils')
  4. const config = require('../config')
  5. const {
  6. VueLoaderPlugin
  7. } = require('vue-loader')
  8. const vueLoaderConfig = require('./vue-loader.conf')
  9. function resolve(dir) {
  10. return path.join(__dirname, '..', dir)
  11. }
  12. module.exports = {
  13. context: path.resolve(__dirname, '../'),
  14. entry: {
  15. app: './src/main.js'
  16. },
  17. output: {
  18. path: config.build.assetsRoot,
  19. filename: '[name].js',
  20. publicPath: config.build.assetsPublicPath //process.env.NODE_ENV === 'production' ? config.build.assetsPublicPath : config.dev.assetsPublicPath
  21. },
  22. resolve: {
  23. extensions: ['mjs', '.js', '.vue', '.json'],
  24. alias: {
  25. '@': resolve('src'),
  26. 'vue$': 'vue/dist/vue.runtime.esm.js'
  27. }
  28. },
  29. module: {
  30. rules: [{
  31. test: /\.vue$/,
  32. loader: 'vue-loader',
  33. options: vueLoaderConfig
  34. },
  35. {
  36. test: /\.js$/,
  37. loader: 'babel-loader',
  38. include: [
  39. resolve('src'),
  40. resolve('test'),
  41. resolve('node_modules/webpack-dev-server/client')
  42. ]
  43. },
  44. {
  45. test: /\.svg$/,
  46. loader: 'svg-sprite-loader',
  47. include: [resolve('src/icons')],
  48. options: {
  49. symbolId: 'icon-[name]'
  50. }
  51. },
  52. {
  53. test: /\.(png|jpe?g|gif|svg)(\?.*)?$/,
  54. loader: 'url-loader',
  55. exclude: [resolve('src/icons')],
  56. options: {
  57. //esModule: false,
  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: /\.mjs$/,
  80. include: /node_modules/,
  81. type: 'javascript/auto'
  82. },
  83. ]
  84. },
  85. plugins: [new VueLoaderPlugin()],
  86. node: {
  87. // prevent webpack from injecting useless setImmediate polyfill because Vue
  88. // source contains it (although only uses it if it's native).
  89. setImmediate: false,
  90. // prevent webpack from injecting mocks to Node native modules
  91. // that does not make sense for the client
  92. dgram: 'empty',
  93. fs: 'empty',
  94. net: 'empty',
  95. tls: 'empty',
  96. child_process: 'empty'
  97. }
  98. }