webpack.base.conf.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. 'use strict'
  2. const path = require('path')
  3. const utils = require('./utils')
  4. const config = require('../config')
  5. const HappyPack = require('happypack')
  6. const {
  7. VueLoaderPlugin
  8. } = require('vue-loader')
  9. const vueLoaderConfig = require('./vue-loader.conf')
  10. const os = require('os');
  11. const happyThreadPool = HappyPack.ThreadPool({ size: os.cpus().length });
  12. // el-bigdata-table babel-loader 配置
  13. const fs = require('fs')
  14. function resolve(dir) {
  15. return path.join(__dirname, '..', dir)
  16. }
  17. const createLintingRule = () => ({
  18. test: /\.(js|vue)$/,
  19. loader: 'eslint-loader',
  20. enforce: 'pre',
  21. include: [resolve('src'), resolve('test')],
  22. options: {
  23. formatter: require('eslint-friendly-formatter'),
  24. emitWarning: !config.dev.showEslintErrorsInOverlay
  25. }
  26. })
  27. // el-bigdata-table babel-loader 配置
  28. let bigTableDirName = fs.readdirSync(resolve('node_modules')).filter(dirName => /el-bigdata-table/.test(dirName))
  29. const bigTableDirs = bigTableDirName.map(dir => resolve(`node_modules/${dir}/src`))
  30. module.exports = {
  31. context: path.resolve(__dirname, '../'),
  32. entry: {
  33. app: ["babel-polyfill", "./src/main.js"],
  34. mobile: ["babel-polyfill", "./src/mobile/main.js"]
  35. },
  36. output: {
  37. path: config.build.assetsRoot,
  38. filename: '[name].js',
  39. publicPath:
  40. process.env.NODE_ENV === 'production'
  41. ? config.build.assetsPublicPath
  42. : config.dev.assetsPublicPath
  43. },
  44. resolve: {
  45. extensions: ['.js', '.vue', '.json'],
  46. alias: {
  47. '@': resolve('src')
  48. }
  49. },
  50. module: {
  51. rules: [
  52. ...(config.dev.useEslint ? [createLintingRule()] : []),
  53. {
  54. test: /\.vue$/,
  55. loader: 'vue-loader',
  56. options: vueLoaderConfig
  57. },
  58. {
  59. test: /\.js$/,
  60. loader: 'happypack/loader?id=happyBabel',
  61. include: [
  62. resolve('src'),
  63. resolve('test'),
  64. resolve('node_modules/webpack-dev-server/client'),
  65. resolve('node_modules/signature_pad/dist'),
  66. resolve('node_modules/element-ui/src'),
  67. resolve('node_modules/element-ui/packages'),
  68. ...bigTableDirs
  69. ]
  70. },
  71. {
  72. test: /\.svg$/,
  73. loader: 'svg-sprite-loader',
  74. include: [resolve('src/icons')],
  75. options: {
  76. symbolId: 'icon-[name]'
  77. }
  78. },
  79. {
  80. test: /\.(png|jpe?g|gif|svg)(\?.*)?$/,
  81. loader: 'url-loader',
  82. exclude: [resolve('src/icons')],
  83. options: {
  84. limit: 10000,
  85. name: utils.assetsPath('img/[name].[hash:7].[ext]')
  86. }
  87. },
  88. {
  89. test: /\.(mp4|webm|ogg|mp3|wav|flac|aac)(\?.*)?$/,
  90. loader: 'url-loader',
  91. options: {
  92. limit: 10000,
  93. name: utils.assetsPath('media/[name].[hash:7].[ext]')
  94. }
  95. },
  96. {
  97. test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/,
  98. loader: 'url-loader',
  99. options: {
  100. limit: 10000,
  101. name: utils.assetsPath('fonts/[name].[hash:7].[ext]')
  102. }
  103. }
  104. ]
  105. },
  106. plugins: [new VueLoaderPlugin(), new HappyPack({
  107. id: 'happyBabel',
  108. loaders: ['babel-loader?cacheDirectory=true'],
  109. threadPool: happyThreadPool,
  110. //允许 HappyPack 输出日志
  111. verbose: true,
  112. })],
  113. node: {
  114. // prevent webpack from injecting useless setImmediate polyfill because Vue
  115. // source contains it (although only uses it if it's native).
  116. setImmediate: false,
  117. // prevent webpack from injecting mocks to Node native modules
  118. // that does not make sense for the client
  119. dgram: 'empty',
  120. fs: 'empty',
  121. net: 'empty',
  122. tls: 'empty',
  123. child_process: 'empty'
  124. }
  125. }