Skip to content

Commit

Permalink
fix(mfsu): src compiled twice when use APP_ROOT (#9885)
Browse files Browse the repository at this point in the history
* fix: 🐛  src code compiled twice problme

* refactor: 🎨 umi-docs 开启 mfsu normal

Co-authored-by: pshu <pishu.spf@antfin.com>
  • Loading branch information
stormslowly and stormslowly authored Dec 1, 2022
1 parent 901aa3d commit 63d4de7
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .umirc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ export default {
favicons: [
'https://img.alicdn.com/tfs/TB1YHEpwUT1gK0jSZFhXXaAtVXa-28-27.svg',
],
mfsu: false,
mfsu: { strategy: 'normal' },
routePrefetch: {},
manifest: {},
plugins: ['@umijs/plugin-docs'],
Expand Down
8 changes: 6 additions & 2 deletions packages/mfsu/src/babelPlugins/awaitImport/checkMatch.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,12 @@ test('start with mf/', () => {
expect(
checkMatch({
value: 'mf/foo',
}).isMatch,
).toEqual(false);
}),
).toEqual({
isMatch: true,
value: 'foo',
replaceValue: 'mf/foo',
});
});

test('babel/svgr-webpack', () => {
Expand Down
15 changes: 12 additions & 3 deletions packages/mfsu/src/babelPlugins/awaitImport/checkMatch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,13 @@ export function checkMatch({

const unMatchLibsRegex = genUnMatchLibsRegex(opts.unMatchLibs);

const mfPathInitial = `${remoteName}/`;

if (
// unMatch specified libs
unMatchLibsRegex?.test(value) ||
// do not match bundler-webpack/client/client/client.js
value.includes('client/client/client.js') ||
// already handled
value.startsWith(`${remoteName}/`) ||
// don't match dynamic path
// e.g. @umijs/deps/compiled/babel/svgr-webpack.js?-svgo,+titleProp,+ref!./umi.svg
winPath(value).includes('babel/svgr-webpack') ||
Expand All @@ -83,6 +83,9 @@ export function checkMatch({
value.startsWith('.')
) {
isMatch = false;
// already handled
} else if (value.startsWith(mfPathInitial)) {
isMatch = true;
} else if (isAbsolute(value)) {
isMatch = RE_NODE_MODULES.test(value) || isUmiLocalDev(value);
} else {
Expand Down Expand Up @@ -110,7 +113,13 @@ export function checkMatch({
}

if (isMatch) {
replaceValue = `${remoteName}/${winPath(value)}`;
// in case src file compiled twice or more
if (value.startsWith(mfPathInitial)) {
replaceValue = value;
value = value.replace(mfPathInitial, '');
} else {
replaceValue = `${remoteName}/${winPath(value)}`;
}
}

// @ts-ignore
Expand Down

1 comment on commit 63d4de7

@vercel
Copy link

@vercel vercel bot commented on 63d4de7 Dec 1, 2022

Choose a reason for hiding this comment

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

Please sign in to comment.