Skip to content

Commit

Permalink
chore: ssr html hash (umijs#4903)
Browse files Browse the repository at this point in the history
  • Loading branch information
ycjcl868 authored Jun 23, 2020
1 parent 46f6f0b commit 90ceef3
Showing 1 changed file with 10 additions and 14 deletions.
24 changes: 10 additions & 14 deletions packages/preset-built-in/src/plugins/features/ssr/ssr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,28 +24,24 @@ export const onBuildComplete = (api: IApi, _isTest = false) => async ({
stats,
}: any) => {
if (!err && stats?.stats) {
const HTML_REG = /<html.*?<\/html>/m;
const [clientStats] = stats.stats;
const html = getHtmlGenerator({ api });
const placeholderHTML = JSON.stringify(
await html.getContent({
route: { path: api.config.publicPath },
noChunk: true,
}),
);
const defaultHTML = JSON.stringify(
await html.getContent({
route: { path: api.config.publicPath },
chunks: clientStats.compilation.chunks,
}),
);
const [defaultHTML] =
JSON.stringify(
await html.getContent({
route: { path: api.config.publicPath },
chunks: clientStats.compilation.chunks,
}),
).match(HTML_REG) || [];
const serverPath = path.join(
api.paths.absOutputPath!,
OUTPUT_SERVER_FILENAME,
);
if (fs.existsSync(serverPath)) {
if (fs.existsSync(serverPath) && defaultHTML) {
const serverContent = fs
.readFileSync(serverPath, 'utf-8')
.replace(placeholderHTML, defaultHTML);
.replace(HTML_REG, defaultHTML);
// for test case
if (_isTest) {
return serverContent;
Expand Down

0 comments on commit 90ceef3

Please sign in to comment.