Skip to content

Commit 555ca9b

Browse files
authored
feat: add forceExternalList option
1 parent b95749d commit 555ca9b

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

esbuild-node-externals/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,10 @@ Make package.json `optionalDependencies` external.
8282

8383
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.
8484

85+
#### `options.forceExternalList` (default to `[]`)
86+
87+
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.
88+
8589
#### `options.allowWorkspaces` (default to `false`)
8690

8791
Automatically exclude all packages defined as workspaces (`workspace:*`) in a monorepo.

esbuild-node-externals/src/index.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export interface Options {
1414
peerDependencies?: boolean;
1515
optionalDependencies?: boolean;
1616
allowList?: AllowList;
17+
forceExternalList?: AllowList;
1718
allowWorkspaces?: boolean;
1819
cwd?: string;
1920
}
@@ -44,7 +45,8 @@ export const nodeExternalsPlugin = (paramsOptions: Options = {}): Plugin => {
4445

4546
const allowPredicate =
4647
options.allowList && createAllowPredicate(options.allowList);
47-
48+
const externalPredicate =
49+
options.forceExternalList && createAllowPredicate(options.forceExternalList);
4850

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

87+
// Allow one last override to force a path/package to be treated as external
88+
if (externalPredicate?.(args.path)) {
89+
return { path: args.path, external: true };
90+
}
91+
8592
return null;
8693
});
8794
},

0 commit comments

Comments
 (0)