Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(ssr): correct logic for get dist path #11729

Merged
merged 1 commit into from
Oct 12, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions packages/preset-umi/src/features/ssr/utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { join } from 'path';
import { existsSync } from 'fs';
import { basename, join } from 'path';
import { IApi } from '../../types';

/** esbuild plugin for resolving umi imports */
Expand Down Expand Up @@ -29,6 +29,11 @@ export function absServerBuildPath(api: IApi) {
);
}

// server output path will not be removed before compile
// so remove require cache to avoid outdated asset path when enable hash
delete require.cache[manifestPath];
const manifest = require(manifestPath);
return join(api.paths.cwd, 'server', manifest.assets['umi.js'])
// basename use to strip public path
// ex. /foo/umi.xxx.js -> umi.xxx.js
return join(api.paths.cwd, 'server', basename(manifest.assets['umi.js']));
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里应该还有一个优化,就是把 absServerBuildPath 的返回值的 require.cache 删了,因为基本上调用 absServerBuildPath 的地方后续都手动删除了这个 cache ,多此一举。

Loading