diff --git a/src/index.ts b/src/index.ts index fe29634..c3f3d5b 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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, @@ -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)}) diff --git a/src/utils/vitePluginOverrideModule.ts b/src/utils/vitePluginOverrideModule.ts index 50eec62..5079a0f 100644 --- a/src/utils/vitePluginOverrideModule.ts +++ b/src/utils/vitePluginOverrideModule.ts @@ -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 (