Skip to content

Commit

Permalink
feat: add forceExternalList option
Browse files Browse the repository at this point in the history
  • Loading branch information
gunsch authored Dec 17, 2024
1 parent b95749d commit 555ca9b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
4 changes: 4 additions & 0 deletions esbuild-node-externals/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ Make package.json `optionalDependencies` external.

An array for the externals to allow, so they will be included in the bundle. Can accept exact strings ('module_name'), regex patterns (/^module_name/), or a function that accepts the module name and returns whether it should be included.

#### `options.forceExternalList` (default to `[]`)

An array that forces packages to be treated as external, even if not in `package.json`, so they will be excluded from the bundle. Can accept exact strings ('module_name'), regex patterns (/^module_name/), or a function that accepts the module name and returns whether it should be externalized.

#### `options.allowWorkspaces` (default to `false`)

Automatically exclude all packages defined as workspaces (`workspace:*`) in a monorepo.
Expand Down
9 changes: 8 additions & 1 deletion esbuild-node-externals/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export interface Options {
peerDependencies?: boolean;
optionalDependencies?: boolean;
allowList?: AllowList;
forceExternalList?: AllowList;
allowWorkspaces?: boolean;
cwd?: string;
}
Expand Down Expand Up @@ -44,7 +45,8 @@ export const nodeExternalsPlugin = (paramsOptions: Options = {}): Plugin => {

const allowPredicate =
options.allowList && createAllowPredicate(options.allowList);

const externalPredicate =
options.forceExternalList && createAllowPredicate(options.forceExternalList);

return {
name: 'node-externals',
Expand Down Expand Up @@ -82,6 +84,11 @@ export const nodeExternalsPlugin = (paramsOptions: Options = {}): Plugin => {
return { path: args.path, external: true };
}

// Allow one last override to force a path/package to be treated as external
if (externalPredicate?.(args.path)) {
return { path: args.path, external: true };
}

return null;
});
},
Expand Down

0 comments on commit 555ca9b

Please sign in to comment.