webpack.base.conf.js 2.8 KB

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