vue.config.js 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. const { defineConfig } = require("@vue/cli-service");
  2. module.exports = defineConfig({
  3. transpileDependencies: true,
  4. devServer: {
  5. proxy: {
  6. "/api": {
  7. // http://63.141.230.43:57676
  8. // http://backend.66linknow.com
  9. // https://test2.66linknow.com
  10. target: "https://test2.66linknow.com",
  11. changeOrigin: true, // 允许跨域
  12. },
  13. // 2.【新增】WebSocket 代理配置
  14. "/ws/kline": {
  15. target: "wss://test2.66linknow.com", // 后端 IP
  16. changeOrigin: true,
  17. ws: true, // ⚠️ 开启 WebSocket 支持
  18. // 这里是否需要 pathRewrite 取决于后端路径有没有 /ws
  19. },
  20. "/ws/custom_chat": {
  21. target: "wss://test2.66linknow.com", // 后端 IP
  22. changeOrigin: true,
  23. ws: true, // ⚠️ 开启 WebSocket 支持
  24. // 这里是否需要 pathRewrite 取决于后端路径有没有 /ws
  25. },
  26. },
  27. },
  28. // 1. 基础路径 (解决白屏问题)
  29. publicPath: "./",
  30. // 2. 关闭 SourceMap (最简单粗暴的减体积)
  31. // 生产环境不生成 .map 文件,体积能减少 50% 以上,且防源码泄露
  32. productionSourceMap: false,
  33. // 3. Webpack 核心优化 (代码分割)
  34. configureWebpack: (config) => {
  35. // 只有在打包生产环境 (npm run build) 时才运行优化
  36. if (process.env.NODE_ENV === "production") {
  37. // 开启代码分割 (SplitChunks)
  38. config.optimization.splitChunks = {
  39. chunks: "all", // 对所有代码进行分割 (无论是异步还是同步)
  40. // 缓存组配置:决定什么代码打包到什么文件里
  41. cacheGroups: {
  42. // 组1: 第三方库 (node_modules)
  43. // 作用:把所有 node_modules 里的东西拆出来
  44. libs: {
  45. name: "chunk-libs",
  46. test: /[\\/]node_modules[\\/]/,
  47. priority: 10,
  48. chunks: "initial", // 只打包初始依赖
  49. },
  50. // 组2: Vant UI 组件库 (单独拆分)
  51. // 作用:Vant 体积较大,单独打包有利于缓存
  52. vant: {
  53. name: "chunk-vant",
  54. priority: 20, // 优先级更高,会先被提取
  55. test: /[\\/]node_modules[\\/]_?vant(.*)/,
  56. },
  57. // 组3: 公共代码
  58. // 作用:如果你的多个页面都引用了同一个组件,提取出来公用
  59. commons: {
  60. name: "chunk-commons",
  61. test: /[\\/]src[\\/]components[\\/]/, // 匹配 src/components 下的组件
  62. minChunks: 2, // 只要被引用2次及以上就提取
  63. priority: 5,
  64. reuseExistingChunk: true,
  65. },
  66. },
  67. };
  68. }
  69. },
  70. });