webpack.base.conf.js 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. // ...(config.dev.useEslint ? [createLintingRule()] : []),
  32. {
  33. test: /\.vue$/,
  34. loader: 'vue-loader',
  35. options: vueLoaderConfig
  36. },
  37. {
  38. test: /\.js$/,
  39. loader: 'babel-loader',
  40. include: [
  41. resolve('src'),
  42. resolve('test'),
  43. resolve('node_modules/webpack-dev-server/client')
  44. ]
  45. },
  46. {
  47. test: /\.svg$/,
  48. loader: 'svg-sprite-loader',
  49. include: [resolve('src/icons')],
  50. options: {
  51. symbolId: 'icon-[name]'
  52. }
  53. },
  54. {
  55. test: /\.(png|jpe?g|gif|svg)(\?.*)?$/,
  56. loader: 'url-loader',
  57. exclude: [resolve('src/icons')],
  58. options: {
  59. limit: 10000,
  60. name: utils.assetsPath('img/[name].[hash:7].[ext]')
  61. }
  62. },
  63. {
  64. test: /\.(mp4|webm|ogg|mp3|wav|flac|aac)(\?.*)?$/,
  65. loader: 'url-loader',
  66. options: {
  67. limit: 10000,
  68. name: utils.assetsPath('media/[name].[hash:7].[ext]')
  69. }
  70. },
  71. {
  72. test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/,
  73. loader: 'url-loader',
  74. options: {
  75. limit: 10000,
  76. name: utils.assetsPath('fonts/[name].[hash:7].[ext]')
  77. }
  78. }
  79. ]
  80. },
  81. plugins: [new VueLoaderPlugin()],
  82. node: {
  83. // prevent webpack from injecting useless setImmediate polyfill because Vue
  84. // source contains it (although only uses it if it's native).
  85. setImmediate: false,
  86. // prevent webpack from injecting mocks to Node native modules
  87. // that does not make sense for the client
  88. dgram: 'empty',
  89. fs: 'empty',
  90. net: 'empty',
  91. tls: 'empty',
  92. child_process: 'empty'
  93. }
  94. }