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

fix: add react-helmet-async for alias #12511

Open
wants to merge 23 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
b88f38b
fix(docs): 修复 umi 官方文档中《比 Vite 更快的 MFSU》部分的问题 (#12417)
Jinbao1001 May 22, 2024
697603f
fix(docs): 修复 Umi 官方文档中的问题
SK-Luffa May 27, 2024
fb9e7ec
Merge branch 'umijs:master' into master
SK-Luffa Jun 26, 2024
ac3f3c6
Merge branch 'umijs:master' into master
SK-Luffa Jun 29, 2024
3a277ee
1
SK-Luffa Jul 1, 2024
bf38d9c
Merge branch 'umijs:master' into master
SK-Luffa Jul 6, 2024
3435b00
fix(core): handle events on blur (close #10212)
SK-Luffa Jul 6, 2024
6fda717
fix(core): handle events on blur (close #10212)
SK-Luffa Jul 6, 2024
2e4ecf5
fix(core): handle events on blur (close #10212)
SK-Luffa Jul 6, 2024
b0bdf28
fix(core): handle events on blur (close #10212)
SK-Luffa Jul 6, 2024
06181b4
fix(core): handle events on blur (close #10212)
SK-Luffa Jul 6, 2024
9bb0976
fix(core): handle events on blur (close #10212)
SK-Luffa Jul 6, 2024
2b12a3a
Merge branch 'umijs:master' into master
SK-Luffa Jul 10, 2024
ae1f675
fix(build): add react-helmet-async for alias resolution
SK-Luffa Jul 10, 2024
ecad5f1
fix(build): add react-helmet-async for alias resolution
SK-Luffa Jul 10, 2024
6467991
fix(build): add react-helmet-async for alias resolution
SK-Luffa Jul 10, 2024
48875d9
fix(build): add react-helmet-async for alias resolution
SK-Luffa Jul 10, 2024
3aa7940
fix(build): add react-helmet-async for alias resolution
SK-Luffa Jul 10, 2024
54a197c
fix(preset-umi): resolve the path of react-helmet-async within render…
SK-Luffa Jul 11, 2024
e8d057f
Merge branch 'umijs:master' into master
SK-Luffa Jul 11, 2024
e1be908
fix(preset-umi): resolve the path of react-helmet-async within render
SK-Luffa Jul 11, 2024
21fcfe4
fix(preset-umi): resolve the path of react-helmet-async within render
SK-Luffa Jul 11, 2024
0cd1d05
fix(preset-umi): resolve the path of react-helmet-async within render
SK-Luffa Jul 11, 2024
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
45 changes: 44 additions & 1 deletion packages/preset-umi/src/features/vite/vite.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,44 @@
import { winPath } from '@umijs/utils';
import path from 'path';
import type { IApi } from '../../types';
import { isWindows } from '../../utils/platform';

// 解析 react-helmet-async 在 renderer-react 中的路径
const { dirname } = path;
let corePath: string | undefined;
const REACT_HELMET_ASYNC = 'react-helmet-async';
const RENDERER_REACT = '@umijs/renderer-react';
let pkgPath: string;
const getReactHelmetAsyncPath = () => {
if (corePath) {
return corePath;
}
const defaultPkgPath = winPath(
dirname(require.resolve(`${RENDERER_REACT}/package.json`)),
);
// 解析 renderer-react 包的路径
try {
const rendererReactPath = require.resolve(RENDERER_REACT);

pkgPath = rendererReactPath ? winPath(rendererReactPath) : defaultPkgPath;
} catch (e: any) {
throw new Error(
`[reactQuery] package '${RENDERER_REACT}' resolve failed, ${e.message}`,
);
}
// 基于 renderer-react 的路径找到 react-helmet-async
try {
corePath = winPath(
dirname(
require.resolve(`${REACT_HELMET_ASYNC}/package.json`, {
paths: [pkgPath],
}),
),
);
console.log(corePath);
} catch {}
return corePath;
};

export default (api: IApi) => {
api.describe({
Expand All @@ -13,12 +53,15 @@ export default (api: IApi) => {

api.modifyAppData((memo) => {
memo.bundler = 'vite';

return memo;
});

api.modifyConfig((memo) => {
// like vite, use to pre-bundling dependencies in vite mode
if (isWindows) {
const corePath = getReactHelmetAsyncPath();
memo.alias[REACT_HELMET_ASYNC] = corePath;
}
memo.alias['@fs'] = api.cwd;
return memo;
});
Expand Down
Loading