diff --git a/src/build.ts b/src/build.ts index 73eaa661..bbd8a72e 100644 --- a/src/build.ts +++ b/src/build.ts @@ -102,6 +102,7 @@ async function _build( emitCJS: false, cjsBridge: false, inlineDependencies: false, + preserveDynamicImports: true, // Plugins replace: { preventAssignment: true, diff --git a/src/builder/rollup.ts b/src/builder/rollup.ts index 082f73d6..617adbed 100644 --- a/src/builder/rollup.ts +++ b/src/builder/rollup.ts @@ -349,8 +349,7 @@ export function getRollupOptions(ctx: BuildContext): RollupOptions { ...ctx.options.rollup.commonjs, }), - // Preserve dynamic imports for CommonJS - { + ctx.options.rollup.preserveDynamicImports && { renderDynamicImport() { return { left: "import(", right: ")" }; }, diff --git a/src/types.ts b/src/types.ts index ada31558..af25f445 100644 --- a/src/types.ts +++ b/src/types.ts @@ -47,6 +47,7 @@ export type BuildEntry = export interface RollupBuildOptions { emitCJS?: boolean; cjsBridge?: boolean; + preserveDynamicImports?: boolean; inlineDependencies?: boolean; output?: OutputOptions; // Plugins