vue.config.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. const path = require('path')
  2. const defaultSettings = require('./src/settings.js')
  3. function resolve(dir) {
  4. return path.join(__dirname, dir)
  5. }
  6. module.exports = {
  7. publicPath: './',
  8. outputDir: 'dist',
  9. assetsDir: 'static',
  10. lintOnSave: process.env.NODE_ENV === 'development',
  11. productionSourceMap: false,
  12. devServer: {
  13. port: 9527,
  14. open: true,
  15. overlay: {
  16. warnings: false,
  17. errors: true
  18. },
  19. proxy: {
  20. [process.env.VUE_APP_BASE_API]: {
  21. // target: 'https://api.admin.jiuweiyun.cn/api',
  22. target: 'http://192.168.0.15:8016/api',
  23. changeOrigin: true,
  24. pathRewrite: {
  25. ['^' + process.env.VUE_APP_BASE_API]: ''
  26. }
  27. }
  28. }
  29. },
  30. configureWebpack: {
  31. name: defaultSettings.title,
  32. resolve: {
  33. alias: {
  34. '@': resolve('src')
  35. }
  36. }
  37. },
  38. chainWebpack(config) {
  39. config.plugins.delete('preload')
  40. config.plugins.delete('prefetch')
  41. config.module
  42. .rule('svg')
  43. .exclude.add(resolve('src/icons'))
  44. .end()
  45. config.module
  46. .rule('icons')
  47. .test(/\.svg$/)
  48. .include.add(resolve('src/icons'))
  49. .end()
  50. .use('svg-sprite-loader')
  51. .loader('svg-sprite-loader')
  52. .options({
  53. symbolId: 'icon-[name]'
  54. })
  55. .end()
  56. config.module
  57. .rule('vue')
  58. .use('vue-loader')
  59. .loader('vue-loader')
  60. .tap(options => {
  61. options.compilerOptions.preserveWhitespace = true
  62. return options
  63. })
  64. .end()
  65. config
  66. .when(process.env.NODE_ENV === 'development',
  67. config => config.devtool('cheap-source-map')
  68. )
  69. config
  70. .when(process.env.NODE_ENV !== 'development',
  71. config => {
  72. config
  73. .plugin('ScriptExtHtmlWebpackPlugin')
  74. .after('html')
  75. .use('script-ext-html-webpack-plugin', [{
  76. // `runtime` must same as runtimeChunk name. default is `runtime`
  77. inline: /runtime\..*\.js$/
  78. }])
  79. .end()
  80. config
  81. .optimization.splitChunks({
  82. chunks: 'all',
  83. cacheGroups: {
  84. libs: {
  85. name: 'chunk-libs',
  86. test: /[\\/]node_modules[\\/]/,
  87. priority: 10,
  88. chunks: 'initial' // only package third parties that are initially dependent
  89. },
  90. elementUI: {
  91. name: 'chunk-elementUI', // split elementUI into a single package
  92. priority: 20, // the weight needs to be larger than libs and app or it will be packaged into libs or app
  93. test: /[\\/]node_modules[\\/]_?element-ui(.*)/ // in order to adapt to cnpm
  94. },
  95. commons: {
  96. name: 'chunk-commons',
  97. test: resolve('src/components'), // can customize your rules
  98. minChunks: 3, // minimum common number
  99. priority: 5,
  100. reuseExistingChunk: true
  101. }
  102. }
  103. })
  104. config.optimization.runtimeChunk('single')
  105. }
  106. )
  107. }
  108. }