Skip to content

Commit

Permalink
fix(preset-umi): wrong public path when preloading route chunks for q…
Browse files Browse the repository at this point in the history
…iankun app (#12234)

* fix:修改 routePreloadOnLoad.ts 插件,插入代码的优先级

* Update packages/preset-umi/src/features/routePreloadOnLoad/routePreloadOnLoad.ts

Co-authored-by: Peach <[email protected]>

---------

Co-authored-by: Peach <[email protected]>
  • Loading branch information
zkp442910864 and PeachScript authored Mar 28, 2024
1 parent d8feb8d commit 3de4a38
Showing 1 changed file with 40 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -219,44 +219,47 @@ export default (api: IApi) => {
api.config.routeLoader?.moduleType === 'esm',
});

api.addHTMLHeadScripts(() => {
if (api.name === 'build' && routeChunkFilesMap) {
// internal tern app use map mode
return api.config.tern
? // map mode
[
{
type: PRELOAD_ROUTE_MAP_SCP_TYPE,
content: JSON.stringify(routeChunkFilesMap),
},
]
: // script mode
[
{
content: readFileSync(
join(
TEMPLATES_DIR,
'routePreloadOnLoad/preloadRouteFilesScp.js',
),
'utf-8',
)
.replace(
'"{{routeChunkFilesMap}}"',
JSON.stringify(routeChunkFilesMap),
api.addHTMLHeadScripts({
fn: () => {
if (api.name === 'build' && routeChunkFilesMap) {
// internal tern app use map mode
return api.config.tern
? // map mode
[
{
type: PRELOAD_ROUTE_MAP_SCP_TYPE,
content: JSON.stringify(routeChunkFilesMap),
},
]
: // script mode
[
{
content: readFileSync(
join(
TEMPLATES_DIR,
'routePreloadOnLoad/preloadRouteFilesScp.js',
),
'utf-8',
)
.replace('{{basename}}', api.config.base)
.replace(
'"{{publicPath}}"',
`${
// handle runtimePublicPath
api.config.runtimePublicPath ? 'window.publicPath||' : ''
}"${api.config.publicPath}"`,
),
},
];
}

return [];
.replace(
'"{{routeChunkFilesMap}}"',
JSON.stringify(routeChunkFilesMap),
)
.replace('{{basename}}', api.config.base)
.replace(
'"{{publicPath}}"',
`${
// handle runtimePublicPath
api.config.runtimePublicPath ? 'window.publicPath||' : ''
}"${api.config.publicPath}"`,
),
},
];
}

return [];
},
stage: Infinity,
});

api.onBuildComplete(async ({ err, stats }) => {
Expand Down

0 comments on commit 3de4a38

Please sign in to comment.