vue.config.js 3.2 KB

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