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