diff --git a/craco.config.js b/craco.config.js index 6da6ae88..9072329a 100644 --- a/craco.config.js +++ b/craco.config.js @@ -2,6 +2,9 @@ const path = require('path'); const webpack = require('webpack'); const { BundleAnalyzerPlugin } = process.env.ANALYZE ? require('webpack-bundle-analyzer') : { BundleAnalyzerPlugin: null }; +// 检查是否为 Mock 模式(与 src/utils/apiConfig.js 保持一致) +const isMockMode = () => process.env.REACT_APP_ENABLE_MOCK === 'true'; + module.exports = { webpack: { configure: (webpackConfig, { env, paths }) => { @@ -27,7 +30,7 @@ module.exports = { chunks: 'all', maxInitialRequests: 30, minSize: 20000, - maxSize: 244000, // 限制单个 chunk 最大大小(约 244KB) + maxSize: 512000, // 限制单个 chunk 最大大小(512KB,与 performance.maxAssetSize 一致) cacheGroups: { // React 核心库单独分离 react: { @@ -47,7 +50,7 @@ module.exports = { chakraUI: { test: /[\\/]node_modules[\\/](@chakra-ui|@emotion)[\\/]/, name: 'chakra-ui', - priority: 22, + priority: 23, // 从 22 改为 23,避免与 antd 优先级冲突 reuseExistingChunk: true, }, // Ant Design @@ -236,21 +239,31 @@ module.exports = { devMiddleware: { writeToDisk: false, }, - // 代理配置:将 /api 请求代理到后端服务器 - proxy: { - '/api': { - target: 'http://49.232.185.254:5001', - changeOrigin: true, - secure: false, - logLevel: 'debug', - }, - '/concept-api': { - target: 'http://49.232.185.254:6801', - changeOrigin: true, - secure: false, - logLevel: 'debug', - pathRewrite: { '^/concept-api': '' }, - }, + + // 调试日志 + onListening: (devServer) => { + console.log(`[CRACO] Mock Mode: ${isMockMode() ? 'Enabled ✅' : 'Disabled ❌'}`); + console.log(`[CRACO] Proxy: ${isMockMode() ? 'Disabled (MSW intercepts)' : 'Enabled (forwarding to backend)'}`); }, + + // 代理配置:将 /api 请求代理到后端服务器 + // 注意:Mock 模式下禁用 proxy,让 MSW 拦截请求 + ...(isMockMode() ? {} : { + proxy: { + '/api': { + target: 'http://49.232.185.254:5001', + changeOrigin: true, + secure: false, + logLevel: 'debug', + }, + '/concept-api': { + target: 'http://49.232.185.254:6801', + changeOrigin: true, + secure: false, + logLevel: 'debug', + pathRewrite: { '^/concept-api': '' }, + }, + }, + }), }, };