From 2e487c3209d151c0ac0db54ec94f5307906324e8 Mon Sep 17 00:00:00 2001 From: Brendon Matos Date: Mon, 30 Oct 2023 14:21:09 -0300 Subject: [PATCH] feat: support disabling `preserveDynamicImports` (#322) --- src/build.ts | 1 + src/builder/rollup.ts | 3 +-- src/types.ts | 1 + 3 files changed, 3 insertions(+), 2 deletions(-) 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