From e48e3143c2faad93213dc871e0c17549ca9497b2 Mon Sep 17 00:00:00 2001 From: jump-and-jump <984292420@qq.com> Date: Sat, 31 Aug 2024 21:00:17 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E8=A7=A3=E5=86=B3=20headScripts=20?= =?UTF-8?q?=E9=93=BE=E6=8E=A5=E4=B8=8E=20publicPath=20=E4=B8=8D=E5=8C=B9?= =?UTF-8?q?=E9=85=8D=20(#11289)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/config.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/config/config.ts b/config/config.ts index f0004a8512..d6b86175c8 100644 --- a/config/config.ts +++ b/config/config.ts @@ -7,6 +7,13 @@ import routes from './routes'; const { REACT_APP_ENV = 'dev' } = process.env; +/** + * @name 使用公共路径 + * @description 部署时的路径,如果部署在非根目录下,需要配置这个变量 + * @doc https://umijs.org/docs/api/config#publicpath + */ +const PUBLIC_PATH: string = '/'; + export default defineConfig({ /** * @name 开启 hash 模式 @@ -15,6 +22,8 @@ export default defineConfig({ */ hash: true, + publicPath: PUBLIC_PATH, + /** * @name 兼容性设置 * @description 设置 ie11 不一定完美兼容,需要检查自己使用的所有依赖 @@ -125,7 +134,7 @@ export default defineConfig({ */ headScripts: [ // 解决首次加载时白屏的问题 - { src: '/scripts/loading.js', async: true }, + { src: join(PUBLIC_PATH, 'scripts/loading.js'), async: true }, ], //================ pro 插件配置 ================= presets: ['umi-presets-pro'],