vue.config.js 3.4 KB

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