diff --git a/packages/bundler-webpack/src/config/definePlugin.test.ts b/packages/bundler-webpack/src/config/definePlugin.test.ts index b5cec2f603e1..cf977ba9b63e 100644 --- a/packages/bundler-webpack/src/config/definePlugin.test.ts +++ b/packages/bundler-webpack/src/config/definePlugin.test.ts @@ -11,6 +11,7 @@ test('normal', () => { NODE_ENV: '"test"', PUBLIC_PATH: '"/"', }, + 'process.env.SSR_MANIFEST': 'process.env.SSR_MANIFEST', }); }); @@ -27,5 +28,6 @@ test('env variables', () => { UMI_APP_FOO: '"BAR"', PUBLIC_PATH: '"/"', }, + 'process.env.SSR_MANIFEST': 'process.env.SSR_MANIFEST', }); }); diff --git a/packages/bundler-webpack/src/config/definePlugin.ts b/packages/bundler-webpack/src/config/definePlugin.ts index ad646fc2552e..c4b49031f5ee 100644 --- a/packages/bundler-webpack/src/config/definePlugin.ts +++ b/packages/bundler-webpack/src/config/definePlugin.ts @@ -37,7 +37,7 @@ export function resolveDefine(opts: { define: any; publicPath?: string }) { return { 'process.env': env, - 'process.env.SSR_RESOURCE_DIR': 'process.env.SSR_RESOURCE_DIR', + 'process.env.SSR_MANIFEST': 'process.env.SSR_MANIFEST', ...define, }; } diff --git a/packages/preset-umi/templates/server.tpl b/packages/preset-umi/templates/server.tpl index c6a9a9eccb1b..322c46939eff 100644 --- a/packages/preset-umi/templates/server.tpl +++ b/packages/preset-umi/templates/server.tpl @@ -23,16 +23,17 @@ const routesWithServerLoader = { export function getManifest(sourceDir) { let manifestPath; - if (process.env.SSR_RESOURCE_DIR) { - manifestPath = path.join(process.env.SSR_RESOURCE_DIR,'build-manifest.json') - } else if (sourceDir) { + if (process.env.SSR_MANIFEST) { + return JSON.parse(process.env.SSR_MANIFEST) + } + if (sourceDir) { manifestPath = path.join(sourceDir,'build-manifest.json') } - else { + else { manifestPath = '{{{ assetsPath }}}' - } + } - return JSON.parse(fs.readFileSync(manifestPath), 'utf-8'); + return JSON.parse(fs.readFileSync(manifestPath), 'utf-8'); } export function createHistory(opts) { diff --git a/packages/renderer-react/src/html.tsx b/packages/renderer-react/src/html.tsx index 219032f2cb2e..c5aa0714d696 100644 --- a/packages/renderer-react/src/html.tsx +++ b/packages/renderer-react/src/html.tsx @@ -68,9 +68,13 @@ const HydrateMetadata = (props: IHtmlProps) => { {htmlPageOpts?.headScripts?.map((script: IScript, key: number) => { const { content, ...rest } = normalizeScripts(script); return ( - + +