Skip to content

Commit

Permalink
fix(preset-umi): wrong async script mark when enable exportStatic (#1…
Browse files Browse the repository at this point in the history
  • Loading branch information
PeachScript committed Mar 21, 2024
1 parent f03915a commit eb3ea75
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions packages/preset-umi/src/features/exportStatic/exportStatic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,15 +148,21 @@ export default (api: IApi) => {
const { publicPath } = api.config;
const htmlData = api.appData.exportHtmlData;
const htmlFiles: { path: string; content: string }[] = [];
const { markupArgs: defaultMarkupArgs } = opts;
let asyncMarkupArgs: typeof defaultMarkupArgs;

for (const { file, route, prerender } of htmlData) {
let { markupArgs } = opts;
let markupArgs = defaultMarkupArgs;

// mark async for the scripts of pre-rendered html
if (api.config.ssr && prerender) {
markupArgs.scripts.forEach((script: any) => {
if (script.src) {
script.async = true;
}
});
// copy args to avoid affect original object
markupArgs = asyncMarkupArgs ??= {
...markupArgs,
scripts: markupArgs.scripts.map((script: any) =>
script.src ? { ...script, async: true } : script,
),
};
}

// handle relative publicPath, such as `./`
Expand Down

0 comments on commit eb3ea75

Please sign in to comment.