refactor(api): 统一API路径配置并优化相关服务调用
All checks were successful
test/timeline-frontend/pipeline/head This commit looks good

feat: 添加API URL全局配置文件
fix: 修复SSR环境下的窗口对象检查
perf: 优化代理配置路径匹配顺序
style: 移除无用注释和未使用的类型声明
This commit is contained in:
2026-02-27 10:07:03 +08:00
parent 97e4a135e1
commit c1a88ea4da
29 changed files with 392 additions and 225 deletions

View File

@@ -160,56 +160,56 @@ export default defineConfig({
* @name Webpack configuration
* @description Custom webpack configuration for code splitting and optimization
*/
chainWebpack: (config: any) => {
// Ignore Windows system files to prevent Watchpack errors
config.watchOptions({
ignored: [
'**/node_modules',
'**/.git',
'**/C:/DumpStack.log.tmp',
'**/C:/pagefile.sys',
'**/C:/swapfile.sys',
'**/C:/System Volume Information',
'**/C:/$*', // Ignore all system files starting with $
],
});
// chainWebpack: (config: any) => {
// // Ignore Windows system files to prevent Watchpack errors
// config.watchOptions({
// ignored: [
// '**/node_modules',
// '**/.git',
// '**/C:/DumpStack.log.tmp',
// '**/C:/pagefile.sys',
// '**/C:/swapfile.sys',
// '**/C:/System Volume Information',
// '**/C:/$*', // Ignore all system files starting with $
// ],
// });
// Split large vendor libraries into separate chunks
config.optimization.splitChunks({
chunks: 'all',
cacheGroups: {
// Ant Design and related libraries
antd: {
name: 'antd',
test: /[\\/]node_modules[\\/](@ant-design|antd|@antv|rc-)/,
priority: 20,
},
// React and related libraries
react: {
name: 'react',
test: /[\\/]node_modules[\\/](react|react-dom|react-router|react-router-dom)/,
priority: 20,
},
// Other vendor libraries
vendors: {
name: 'vendors',
test: /[\\/]node_modules[\\/]/,
priority: 10,
},
},
});
// // Split large vendor libraries into separate chunks
// config.optimization.splitChunks({
// chunks: 'all',
// cacheGroups: {
// // Ant Design and related libraries
// antd: {
// name: 'antd',
// test: /[\\/]node_modules[\\/](@ant-design|antd|@antv|rc-)/,
// priority: 20,
// },
// // React and related libraries
// react: {
// name: 'react',
// test: /[\\/]node_modules[\\/](react|react-dom|react-router|react-router-dom)/,
// priority: 20,
// },
// // Other vendor libraries
// vendors: {
// name: 'vendors',
// test: /[\\/]node_modules[\\/]/,
// priority: 10,
// },
// },
// });
// Optimize images
config.module
.rule('images')
.test(/\.(png|jpe?g|gif|webp|svg)$/)
.use('url-loader')
.loader('url-loader')
.options({
limit: 8192, // Inline images smaller than 8KB
name: 'static/images/[name].[hash:8].[ext]',
});
// // Optimize images
// config.module
// .rule('images')
// .test(/\.(png|jpe?g|gif|webp|svg)$/)
// .use('url-loader')
// .loader('url-loader')
// .options({
// limit: 8192, // Inline images smaller than 8KB
// name: 'static/images/[name].[hash:8].[ext]',
// });
return config;
},
// return config;
// },
});

View File

@@ -15,13 +15,22 @@ export default {
// 如果需要自定义本地开发服务器 请取消注释按需调整
dev: {
// localhost:8000/api/** -> https://preview.pro.ant.design/api/**
// 注意:更具体的路径应该放在前面,避免被通用路径覆盖
'/api/story/': {
// 要代理的地址
target: basePath,
// 配置了这个可以从 http 代理到 https
// 依赖 origin 的功能可能需要这个,比如 cookie
changeOrigin: true,
pathRewrite: { '^/api/story': '/api/story' },
pathRewrite: { '^/api/story': '/story' },
},
'/api/user/': {
// 要代理的地址
target: basePath,
// 配置了这个可以从 http 代理到 https
// 依赖 origin 的功能可能需要这个,比如 cookie
changeOrigin: true,
pathRewrite: { '^/api/user': '/user' },
},
'/file/': {
// 要代理的地址
@@ -39,10 +48,11 @@ export default {
changeOrigin: true,
pathRewrite: { '^/user-api': '/user' },
},
// 通用 /api/ 代理放在最后,避免覆盖上面的具体配置
'/api/': {
target: 'https://proapi.azurewebsites.net',
target: basePath,
changeOrigin: true,
pathRewrite: { '^': '' },
pathRewrite: { '^/api': '/api' },
},
},