vue.config.js 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. 'use strict'
  2. const path = require('path')
  3. const defaultSettings = require('./src/settings.js')
  4. function resolve(dir) {
  5. return path.join(__dirname, dir)
  6. }
  7. const name = defaultSettings.title || '缴费后台' // page title
  8. module.exports = {
  9. publicPath: './',
  10. outputDir: 'dist',
  11. assetsDir: 'static',
  12. lintOnSave: process.env.NODE_ENV === 'development',
  13. productionSourceMap: false,
  14. devServer: {
  15. open: true,
  16. overlay: {
  17. warnings: false,
  18. errors: true
  19. },
  20. proxy: {
  21. '/api': {
  22. target: 'http://192.168.0.15',
  23. changeOrigin: true
  24. }
  25. }
  26. },
  27. configureWebpack: {
  28. name: name,
  29. resolve: {
  30. alias: {
  31. '@': resolve('src')
  32. }
  33. }
  34. },
  35. chainWebpack(config) {
  36. config.plugins.delete('preload') // TODO: need test
  37. config.plugins.delete('prefetch') // TODO: need test
  38. // set preserveWhitespace
  39. config.module
  40. .rule('vue')
  41. .use('vue-loader')
  42. .loader('vue-loader')
  43. .tap(options => {
  44. options.compilerOptions.preserveWhitespace = true
  45. return options
  46. })
  47. .end()
  48. config
  49. .when(process.env.NODE_ENV === 'development',
  50. config => config.devtool('cheap-source-map')
  51. )
  52. config
  53. .when(process.env.NODE_ENV !== 'development',
  54. config => {
  55. config
  56. .plugin('ScriptExtHtmlWebpackPlugin')
  57. .after('html')
  58. .use('script-ext-html-webpack-plugin', [{
  59. // `runtime` must same as runtimeChunk name. default is `runtime`
  60. inline: /runtime\..*\.js$/
  61. }])
  62. .end()
  63. config
  64. .optimization.splitChunks({
  65. chunks: 'all',
  66. cacheGroups: {
  67. libs: {
  68. name: 'chunk-libs',
  69. test: /[\\/]node_modules[\\/]/,
  70. priority: 10,
  71. chunks: 'initial' // only package third parties that are initially dependent
  72. },
  73. elementUI: {
  74. name: 'chunk-elementUI', // split elementUI into a single package
  75. priority: 20, // the weight needs to be larger than libs and app or it will be packaged into libs or app
  76. test: /[\\/]node_modules[\\/]_?element-ui(.*)/ // in order to adapt to cnpm
  77. },
  78. commons: {
  79. name: 'chunk-commons',
  80. test: resolve('src/components'), // can customize your rules
  81. minChunks: 3, // minimum common number
  82. priority: 5,
  83. reuseExistingChunk: true
  84. }
  85. }
  86. })
  87. config.optimization.runtimeChunk('single')
  88. }
  89. )
  90. }
  91. }