webpack.base.conf.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. 'use strict'
  2. const path = require('path')
  3. const utils = require('./utils')
  4. const config = require('../config')
  5. const vueLoaderConfig = require('./vue-loader.conf')
  6. const webpack = require('webpack')
  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. externals: {
  26. jquery: 'window.$',
  27. xlsx: 'window.XLSX',
  28. echarts: 'window.echarts',
  29. psl: 'window.psl'
  30. },
  31. output: {
  32. path: config.build.assetsRoot,
  33. filename: '[name].js',
  34. publicPath: ['production', 'test'].includes(process.env.NODE_ENV)
  35. ? config.build.assetsPublicPath
  36. : config.dev.assetsPublicPath
  37. },
  38. resolve: {
  39. extensions: ['.js', '.vue', '.json'],
  40. alias: {
  41. 'vue$': 'vue/dist/vue.esm.js',
  42. '@': resolve('src'),
  43. '~': resolve('')
  44. }
  45. },
  46. module: {
  47. rules: [
  48. ...(config.dev.useEslint ? [createLintingRule()] : []),
  49. {
  50. test: /\.vue$/,
  51. loader: 'vue-loader',
  52. options: vueLoaderConfig
  53. },
  54. {
  55. test: /\.js$/,
  56. loader: 'babel-loader?cacheDirectory',
  57. include: [resolve('src'), resolve('node_modules/ui-components'), resolve('node_modules/webpack-dev-server/client')]
  58. },
  59. {
  60. test: /\.svg$/,
  61. loader: 'svg-sprite-loader',
  62. include: [resolve('src/icons')],
  63. options: {
  64. symbolId: 'icon-[name]'
  65. }
  66. },
  67. {
  68. test: /\.(png|jpe?g|gif|svg)(\?.*)?$/,
  69. loader: 'url-loader',
  70. exclude: [resolve('src/icons')],
  71. options: {
  72. limit: 10000,
  73. name: utils.assetsPath('img/[name].[hash:7].[ext]')
  74. }
  75. },
  76. {
  77. test: /\.(mp4|webm|ogg|mp3|wav|flac|aac)(\?.*)?$/,
  78. loader: 'url-loader',
  79. options: {
  80. limit: 10000,
  81. name: utils.assetsPath('media/[name].[hash:7].[ext]')
  82. }
  83. },
  84. {
  85. test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/,
  86. loader: 'url-loader',
  87. options: {
  88. limit: 10000,
  89. name: utils.assetsPath('fonts/[name].[hash:7].[ext]')
  90. }
  91. }
  92. ]
  93. },
  94. plugins: [
  95. new webpack.ProvidePlugin({
  96. jQuery: 'jquery',
  97. $: 'jquery'
  98. })
  99. ],
  100. node: {
  101. // prevent webpack from injecting useless setImmediate polyfill because Vue
  102. // source contains it (although only uses it if it's native).
  103. setImmediate: false,
  104. // prevent webpack from injecting mocks to Node native modules
  105. // that does not make sense for the client
  106. dgram: 'empty',
  107. fs: 'empty',
  108. net: 'empty',
  109. tls: 'empty',
  110. child_process: 'empty'
  111. }
  112. }