Skip to content

Commit

Permalink
#FIX: 解决 headScripts 链接与 publicPath 不匹配
Browse files Browse the repository at this point in the history
  • Loading branch information
wsafight committed Jul 16, 2024
1 parent 559c01d commit 800a9ea
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 模式
Expand All @@ -15,6 +22,9 @@ export default defineConfig({
*/
hash: true,

...PUBLIC_PATH ? { publicPath: `${PUBLIC_PATH}${PUBLIC_PATH.endsWith('/') ? '' : '/'}` } : {},


/**
* @name 兼容性设置
* @description 设置 ie11 不一定完美兼容,需要检查自己使用的所有依赖
Expand Down Expand Up @@ -125,7 +135,7 @@ export default defineConfig({
*/
headScripts: [
// 解决首次加载时白屏的问题
{ src: '/scripts/loading.js', async: true },
{ src: `${PUBLIC_PATH}${PUBLIC_PATH.endsWith('/') ? '' : '/'}scripts/loading.js`, async: true },
],
//================ pro 插件配置 =================
presets: ['umi-presets-pro'],
Expand Down

0 comments on commit 800a9ea

Please sign in to comment.