Skip to content

Commit

Permalink
fix: modules should not be externalized in iife format
Browse files Browse the repository at this point in the history
  • Loading branch information
egoist committed Sep 26, 2021
1 parent eceda2f commit f29ec8f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/esbuild/external.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 4 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}),
Expand Down Expand Up @@ -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}`)
}
Expand Down

1 comment on commit f29ec8f

@vercel
Copy link

@vercel vercel bot commented on f29ec8f Sep 26, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.