Skip to content

Commit

Permalink
fix: 解决 exportStatic 文件冲突
Browse files Browse the repository at this point in the history
  • Loading branch information
jaykou25 committed Jul 30, 2024
1 parent 2fe9392 commit 1e7b0fb
Showing 1 changed file with 2 additions and 19 deletions.
21 changes: 2 additions & 19 deletions packages/preset-umi/src/features/exportStatic/exportStatic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,26 +66,9 @@ async function getPreRenderedHTML(api: IApi, htmlTpl: string, path: string) {

try {
const location = `${base.endsWith('/') ? base.slice(0, -1) : base}${path}`;
const markup = await markupRender(location);
const [mainTpl, extraTpl = ''] = markup.split('</html>');
// TODO: improve return type for markup generator
const helmetContent = mainTpl.match(
/<head>[^]*?(<[^>]+data-rh[^]+)<\/head>/,
)?.[1];
const bodyContent = mainTpl.match(/<body[^>]*>([^]+?)<\/body>/)?.[1];

htmlTpl = htmlTpl
// append helmet content
.replace('</head>', `${helmetContent || ''}</head>`)
// replace #root with pre-rendered body content
.replace(
new RegExp(`<div id="${api.config.mountElementId}"[^>]*>.*?</div>`),
bodyContent,
)
// append hidden templates
.replace(/$/, `${extraTpl}`);
const html = await markupRender(location);
logger.info(`Pre-render for ${path}`);
return htmlTpl;
return html;
} catch (err) {
logger.error(`Pre-render ${path} error: ${err}`);
if (!ignorePreRenderError) {
Expand Down

0 comments on commit 1e7b0fb

Please sign in to comment.