vue.config.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. const path = require('path')
  2. const sass = require('sass')
  3. const { defineConfig } = require('@vue/cli-service')
  4. const settings = require('./src/config')
  5. const isDev = process.env.NODE_ENV === 'development'
  6. function resolve(dir) {
  7. return path.join(__dirname, dir)
  8. }
  9. module.exports = defineConfig({
  10. publicPath: settings.contextPath,
  11. outputDir: 'dist',
  12. assetsDir: 'static',
  13. runtimeCompiler: true,
  14. lintOnSave: false,
  15. productionSourceMap: false,
  16. transpileDependencies: false,
  17. css: {
  18. loaderOptions: {
  19. css: {
  20. modules: {
  21. auto: /var.scss$/
  22. }
  23. },
  24. sass: {
  25. // https://github.com/sass/dart-sass/issues/1388#issuecomment-916125648
  26. sassOptions: {
  27. outputStyle: 'expanded',
  28. logger: sass.Logger.silent
  29. }
  30. }
  31. }
  32. },
  33. configureWebpack: {
  34. name: settings.title,
  35. resolve: {
  36. alias: {
  37. '@': resolve('src'),
  38. '@ele': resolve('element-ui-personal')
  39. }
  40. },
  41. devServer: {
  42. port: process.env.port || 8079,
  43. client: {
  44. overlay: {
  45. warnings: true,
  46. errors: true
  47. }
  48. },
  49. proxy: {
  50. [settings.apiPrefix]: {
  51. target: 'http://192.168.31.138:8081',
  52. ws: true,
  53. secure: false,
  54. changeOrigin: true,
  55. pathRewrite: {
  56. [`^${settings.apiPrefix}`]: ''
  57. }
  58. }
  59. }
  60. }
  61. },
  62. chainWebpack(config) {
  63. config.plugins.delete('preload')
  64. config.plugins.delete('prefetch')
  65. // set svg-sprite-loader
  66. config
  67. .module
  68. .rule('svg')
  69. .exclude.add(resolve('src/asset/icon'))
  70. .end()
  71. config
  72. .module
  73. .rule('icons')
  74. .test(/\.svg$/)
  75. .include.add(resolve('src/asset/icon'))
  76. .end()
  77. .use('svg-sprite-loader')
  78. .loader('svg-sprite-loader')
  79. .options({ symbolId: 'icon-[name]' })
  80. .end()
  81. config.when(!isDev, config => {
  82. //将css合并到一个文件中
  83. //https://github.com/vuejs/vue-cli/issues/2843
  84. config
  85. .optimization
  86. .removeEmptyChunks(true)
  87. .splitChunks({
  88. cacheGroups: {
  89. style: {
  90. name: 'style',
  91. type: 'css/mini-extract',
  92. chunks: 'all'
  93. }
  94. }
  95. })
  96. .end()
  97. })
  98. }
  99. })