| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- // vue.config.js
- const { defineConfig } = require("@vue/cli-service");
- module.exports = defineConfig({
- transpileDependencies: true,
- //跨域
- // --- 核心配置开始 ---
- devServer: {
- proxy: {
- "/api": {
- // ⚠️【重要】这里必须改成你真实的后端地址!
- // 如果后端在本地,可能是 http://localhost:8000
- // 如果是线上测试服,可能是 http://47.100.xx.xx
- //'http://63.141.230.43:57676',
- // 'http://backend.66linknow.com'
- target: "http://63.141.230.43:57676", // ✅ 必须加上协议
- changeOrigin: true, // 允许跨域
- },
- // 2.【新增】WebSocket 代理配置
- "/ws/kline": {
- target: "ws://backend.66linknow.com", // 后端 IP
- changeOrigin: true,
- ws: true, // ⚠️ 开启 WebSocket 支持
- // 这里是否需要 pathRewrite 取决于后端路径有没有 /ws
- },
- },
- },
- // 1. 基础路径 (解决白屏问题)
- publicPath: "./",
- // 2. 关闭 SourceMap (最简单粗暴的减体积)
- // 生产环境不生成 .map 文件,体积能减少 50% 以上,且防源码泄露
- productionSourceMap: false,
- // 3. Webpack 核心优化 (代码分割)
- configureWebpack: (config) => {
- // 只有在打包生产环境 (npm run build) 时才运行优化
- if (process.env.NODE_ENV === "production") {
- // 开启代码分割 (SplitChunks)
- config.optimization.splitChunks = {
- chunks: "all", // 对所有代码进行分割 (无论是异步还是同步)
- // 缓存组配置:决定什么代码打包到什么文件里
- cacheGroups: {
- // 组1: 第三方库 (node_modules)
- // 作用:把所有 node_modules 里的东西拆出来
- libs: {
- name: "chunk-libs",
- test: /[\\/]node_modules[\\/]/,
- priority: 10,
- chunks: "initial", // 只打包初始依赖
- },
- // 组2: Vant UI 组件库 (单独拆分)
- // 作用:Vant 体积较大,单独打包有利于缓存
- vant: {
- name: "chunk-vant",
- priority: 20, // 优先级更高,会先被提取
- test: /[\\/]node_modules[\\/]_?vant(.*)/,
- },
- // 组3: 公共代码
- // 作用:如果你的多个页面都引用了同一个组件,提取出来公用
- commons: {
- name: "chunk-commons",
- test: /[\\/]src[\\/]components[\\/]/, // 匹配 src/components 下的组件
- minChunks: 2, // 只要被引用2次及以上就提取
- priority: 5,
- reuseExistingChunk: true,
- },
- },
- };
- }
- },
- });
|