vue.config.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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: `https://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. externals: {
  40. 'html2canvas': 'html2canvas'
  41. }
  42. },
  43. chainWebpack(config) {
  44. config.plugins.delete('preload') // TODO: need test
  45. config.plugins.delete('prefetch') // TODO: need test
  46. config.module
  47. .rule('svg')
  48. .exclude.add(resolve('src/icons'))
  49. .end()
  50. config.module
  51. .rule('icons')
  52. .test(/\.svg$/)
  53. .include.add(resolve('src/icons'))
  54. .end()
  55. .use('svg-sprite-loader')
  56. .loader('svg-sprite-loader')
  57. .options({
  58. symbolId: 'icon-[name]'
  59. })
  60. .end()
  61. config.module
  62. .rule('vue')
  63. .use('vue-loader')
  64. .loader('vue-loader')
  65. .tap(options => {
  66. options.compilerOptions.preserveWhitespace = true
  67. return options
  68. })
  69. .end()
  70. config
  71. .when(process.env.NODE_ENV === 'development',
  72. config => config.devtool('cheap-source-map')
  73. )
  74. config
  75. .when(process.env.NODE_ENV !== 'development',
  76. config => {
  77. config
  78. .plugin('ScriptExtHtmlWebpackPlugin')
  79. .after('html')
  80. .use('script-ext-html-webpack-plugin', [{
  81. inline: /runtime\..*\.js$/
  82. }])
  83. .end()
  84. config
  85. .optimization.splitChunks({
  86. chunks: 'all',
  87. cacheGroups: {
  88. libs: {
  89. name: 'chunk-libs',
  90. test: /[\\/]node_modules[\\/]/,
  91. priority: -10,
  92. chunks: 'initial' // only package third parties that are initially dependent
  93. }
  94. }
  95. })
  96. config.optimization.runtimeChunk('single')
  97. }
  98. )
  99. }
  100. }