vue.config.js 3.4 KB

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