webpack.base.conf.js 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. },
  80. plugins: [new VueLoaderPlugin()],
  81. node: {
  82. // prevent webpack from injecting useless setImmediate polyfill because Vue
  83. // source contains it (although only uses it if it's native).
  84. setImmediate: false,
  85. // prevent webpack from injecting mocks to Node native modules
  86. // that does not make sense for the client
  87. dgram: 'empty',
  88. fs: 'empty',
  89. net: 'empty',
  90. tls: 'empty',
  91. child_process: 'empty'
  92. }
  93. }