vue.config.js 3.3 KB

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