vue.config.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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 || 'vue Admin Template' // page title
  8. const port = 9528 // dev port
  9. module.exports = {
  10. publicPath: '/',
  11. outputDir: 'dist',
  12. assetsDir: 'static',
  13. lintOnSave: process.env.NODE_ENV === 'development',
  14. productionSourceMap: false,
  15. devServer: {
  16. port: port,
  17. open: true,
  18. overlay: {
  19. warnings: false,
  20. errors: true
  21. },
  22. proxy: {
  23. '/apis': {
  24. target: `http://zhihui-test.intra.xiaojukeji.com`,
  25. changeOrigin: true,
  26. pathRewrite: {
  27. '^/apis': '' // 需要rewrite的,
  28. }
  29. }
  30. }
  31. },
  32. configureWebpack: {
  33. name: name,
  34. resolve: {
  35. alias: {
  36. '@': resolve('src')
  37. }
  38. }
  39. },
  40. chainWebpack(config) {
  41. config.plugins.delete('preload') // TODO: need test
  42. config.plugins.delete('prefetch') // TODO: need test
  43. config.module
  44. .rule('svg')
  45. .exclude.add(resolve('src/icons'))
  46. .end()
  47. config.module
  48. .rule('icons')
  49. .test(/\.svg$/)
  50. .include.add(resolve('src/icons'))
  51. .end()
  52. .use('svg-sprite-loader')
  53. .loader('svg-sprite-loader')
  54. .options({
  55. symbolId: 'icon-[name]'
  56. })
  57. .end()
  58. config.module
  59. .rule('vue')
  60. .use('vue-loader')
  61. .loader('vue-loader')
  62. .tap(options => {
  63. options.compilerOptions.preserveWhitespace = true
  64. return options
  65. })
  66. .end()
  67. config
  68. .when(process.env.NODE_ENV === 'development',
  69. config => config.devtool('cheap-source-map')
  70. )
  71. config
  72. .when(process.env.NODE_ENV !== 'development',
  73. config => {
  74. config
  75. .plugin('ScriptExtHtmlWebpackPlugin')
  76. .after('html')
  77. .use('script-ext-html-webpack-plugin', [{
  78. inline: /runtime\..*\.js$/
  79. }])
  80. .end()
  81. config
  82. .optimization.splitChunks({
  83. chunks: 'all',
  84. cacheGroups: {
  85. libs: {
  86. name: 'chunk-libs',
  87. test: /[\\/]node_modules[\\/]/,
  88. priority: -10,
  89. chunks: 'initial' // only package third parties that are initially dependent
  90. }
  91. }
  92. })
  93. config.optimization.runtimeChunk('single')
  94. }
  95. )
  96. }
  97. }