vue.config.js 2.5 KB

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