From f29ec8fca8dade37b2e9fefef24e3fa5fb1010d5 Mon Sep 17 00:00:00 2001 From: EGOIST <0x142857@gmail.com> Date: Sun, 26 Sep 2021 20:42:05 +0800 Subject: [PATCH] fix: modules should not be externalized in iife format --- src/esbuild/external.ts | 4 ++++ src/index.ts | 6 ++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/esbuild/external.ts b/src/esbuild/external.ts index 5a58d87..94d3478 100644 --- a/src/esbuild/external.ts +++ b/src/esbuild/external.ts @@ -6,14 +6,18 @@ const NON_NODE_MODULE_RE = /^[^.\/]|^\.[^.\/]|^\.\.[^\/]/ export const externalPlugin = ({ patterns, skipNodeModulesBundle, + disabled, }: { patterns?: (string | RegExp)[] skipNodeModulesBundle?: boolean + disabled?: boolean }): Plugin => { return { name: `external`, setup(build) { + if (disabled) return + if (skipNodeModulesBundle) { build.onResolve({ filter: NON_NODE_MODULE_RE }, (args) => ({ path: args.path, diff --git a/src/index.ts b/src/index.ts index cfc3873..91d1e01 100644 --- a/src/index.ts +++ b/src/index.ts @@ -184,6 +184,8 @@ export async function runEsbuild( // esbuild's `external` option doesn't support RegExp // So here we use a custom plugin to implement it externalPlugin({ + // everything should be bundled for iife format + disabled: format === 'iife', patterns: external, skipNodeModulesBundle: options.skipNodeModulesBundle, }), @@ -360,8 +362,8 @@ const normalizeOptions = async ( log('CLI', 'info', `Building entry: ${options.entryPoints.join(', ')}`) } } else { - Object.keys(input).forEach(alias => { - const filename = input[alias]!; + Object.keys(input).forEach((alias) => { + const filename = input[alias]! if (!fs.existsSync(filename)) { throw new PrettyError(`Cannot find ${alias}: ${filename}`) }