vue.config.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. const { defineConfig } = require('@vue/cli-service')
  2. module.exports = defineConfig({
  3. transpileDependencies: true,
  4. lintOnSave: false,
  5. // 生产环境不生成 source map,减小包体积
  6. productionSourceMap: false,
  7. devServer: {
  8. port: 8080,
  9. open: true,
  10. proxy: {
  11. // /dev-api/auth/** → auth 服务
  12. '/dev-api/auth': {
  13. target: process.env.VUE_APP_AUTH_TARGET || 'http://localhost:8080',
  14. changeOrigin: true,
  15. pathRewrite: { '^/dev-api': '' }
  16. },
  17. // /dev-api/laboratory/** → laboratory 服务
  18. '/dev-api/laboratory': {
  19. target: process.env.VUE_APP_LAB_TARGET || 'http://localhost:8080',
  20. changeOrigin: true,
  21. pathRewrite: { '^/dev-api': '' }
  22. }
  23. }
  24. },
  25. css: {
  26. loaderOptions: {
  27. sass: {
  28. additionalData: `@import "@/styles/variables.scss";`
  29. }
  30. }
  31. },
  32. // 按需加载:将第三方库单独分包
  33. configureWebpack: {
  34. optimization: {
  35. splitChunks: {
  36. chunks: 'all',
  37. cacheGroups: {
  38. echarts: {
  39. name: 'chunk-echarts',
  40. test: /[\\/]node_modules[\\/]echarts[\\/]/,
  41. priority: 20
  42. },
  43. elementUI: {
  44. name: 'chunk-element-ui',
  45. test: /[\\/]node_modules[\\/]element-ui[\\/]/,
  46. priority: 15
  47. },
  48. vendors: {
  49. name: 'chunk-vendors',
  50. test: /[\\/]node_modules[\\/]/,
  51. priority: 10
  52. }
  53. }
  54. }
  55. }
  56. }
  57. })