webpack.base.conf.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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. const createLintingRule = () => ({
  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: './src/main.js'
  24. },
  25. output: {
  26. path: config.build.assetsRoot,
  27. filename: '[name].js',
  28. publicPath:
  29. process.env.NODE_ENV === 'production'
  30. ? config.build.assetsPublicPath
  31. : config.dev.assetsPublicPath
  32. },
  33. resolve: {
  34. extensions: ['.js', '.vue', '.json'],
  35. alias: {
  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: [
  51. resolve('src'),
  52. resolve('test'),
  53. resolve('mock'),
  54. resolve('node_modules/webpack-dev-server/client')
  55. ]
  56. },
  57. {
  58. test: /\.svg$/,
  59. loader: 'svg-sprite-loader',
  60. include: [resolve('src/icons')],
  61. options: {
  62. symbolId: 'icon-[name]'
  63. }
  64. },
  65. {
  66. test: /\.(png|jpe?g|gif|svg)(\?.*)?$/,
  67. loader: 'url-loader',
  68. exclude: [resolve('src/icons')],
  69. options: {
  70. limit: 10000,
  71. name: utils.assetsPath('img/[name].[hash:7].[ext]')
  72. }
  73. },
  74. {
  75. test: /\.(mp4|webm|ogg|mp3|wav|flac|aac)(\?.*)?$/,
  76. loader: 'url-loader',
  77. options: {
  78. limit: 10000,
  79. name: utils.assetsPath('media/[name].[hash:7].[ext]')
  80. }
  81. },
  82. {
  83. test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/,
  84. loader: 'url-loader',
  85. options: {
  86. limit: 10000,
  87. name: utils.assetsPath('fonts/[name].[hash:7].[ext]')
  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. }