Skip to content

Commit

Permalink
fix: dynamic import
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangHongEn committed Aug 5, 2024
1 parent 0435fc0 commit 038d375
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
7 changes: 7 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,11 @@ function wrapShare(
strictVersion: ${JSON.stringify(shareConfig.strictVersion)},
requiredVersion: ${JSON.stringify(shareConfig.requiredVersion)}
}}})
// TODO: syntheticNamedExports not equal to 'default' will cause dynamic import to fail
// TODO: The current settings will result in the inability to directly import the default key of the npm module
// if vue = {default: 1, a: 2}
// import module from 'vue' --> module: {default: 1, a: 2}
// import {a} from 'vue' --> a: 2
export default res()
`,
map: null,
Expand All @@ -145,6 +150,8 @@ function wrapRemote(id: string): { code: string; map: null; syntheticNamedExport
return {
code: `
import {loadRemote} from "@module-federation/runtime"
// TODO: syntheticNamedExports not equal to 'default' will cause dynamic import to fail
// TODO: The current settings will cause dynamic import to fail, and pr vite/rollup may be required
export ${
command !== 'build' ? 'default' : 'const dynamicExport = '
} await loadRemote(${JSON.stringify(id)})
Expand Down
8 changes: 2 additions & 6 deletions src/utils/vitePluginOverrideModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,10 @@ export function overrideModule(
if (node.type === 'ExportNamedDeclaration' || node.type === 'ExportAllDeclaration') {
replaceIfMatch(node.source);
}

if (
node.type === 'CallExpression' &&
node.callee.type === 'Import' &&
node.arguments.length &&
node.arguments[0].type === 'Literal'
node.type === 'ImportExpression'
) {
replaceIfMatch(node.arguments[0]);
replaceIfMatch(node.source);
}

if (
Expand Down

0 comments on commit 038d375

Please sign in to comment.