Skip to content

Commit

Permalink
chore: 优先从环境变量读取 manifest 路径
Browse files Browse the repository at this point in the history
  • Loading branch information
Jinbao1001 committed May 6, 2024
1 parent e0972d3 commit 8dad511
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions packages/preset-umi/templates/server.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { createHistory as createClientHistory } from './core/history';
import { ServerInsertedHTMLContext } from './core/serverInsertedHTMLContext';
import { createPluginManager } from './core/plugin';
import createRequestHandler, { createMarkupGenerator, createUmiHandler, createUmiServerLoader, createAppRootElement } from '{{{ umiServerPath }}}';
import fs from 'fs';
import path from 'path';
{{{ imports }}}
{{{ entryCodeAhead }}}
let helmetContext;
Expand All @@ -20,8 +22,17 @@ const routesWithServerLoader = {
};

export function getManifest(sourceDir) {
return JSON.parse(require('fs').readFileSync(
sourceDir ? require('path').join(sourceDir,'build-manifest.json') : '{{{ assetsPath }}}', 'utf-8'));
let manifestPath;
if (process.env.SSR_RESOURCE_DIR) {
manifestPath = path.join(process.env.SSR_RESOURCE_DIR,'build-manifest.json')
} else if (sourceDir) {
manifestPath = path.join(sourceDir,'build-manifest.json')
}
else {
manifestPath = '{{{ assetsPath }}}'
}

return JSON.parse(fs.readFileSync(manifestPath), 'utf-8');
}

export function createHistory(opts) {
Expand Down

0 comments on commit 8dad511

Please sign in to comment.