vue.config.js 3.4 KB

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