Skip to content

Commit 8c33aa5

Browse files
committed
feat(exclude): exclude node_mdoules packaging with *
1 parent 67cfe7d commit 8c33aa5

File tree

4 files changed

+20
-7
lines changed

4 files changed

+20
-7
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ custom:
4545
```
4646

4747
Check [esbuild](https://github.com/evanw/esbuild#command-line-usage) documentation for the full list of available options. Note that some options like `entryPoints` or `outdir` cannot be overwritten.
48-
The package specified in the `exclude` option is passed to esbuild as `external`, but it is not included in the function bundle either. The default value for this option is `['aws-sdk']`.
48+
The package specified in the `exclude` option is passed to esbuild as `external`, but it is not included in the function bundle either. The default value for this option is `['aws-sdk']`. You can set `exclude` to `*` to disable packaging `node_modules`.
4949

5050
See [example folder](examples) for a minimal example.
5151

src/index.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export interface PackagerOptions {
3737
export interface Configuration extends Omit<BuildOptions, 'watch' | 'plugins'> {
3838
packager: 'npm' | 'yarn';
3939
packagePath: string;
40-
exclude: string[];
40+
exclude: '*' | string[];
4141
watch: WatchConfiguration;
4242
plugins?: string;
4343
keepOutputDirectory?: boolean;
@@ -246,7 +246,10 @@ export class EsbuildServerlessPlugin implements ServerlessPlugin {
246246
this.rootFileNames.map(async ({ entry, func, functionAlias }) => {
247247
const config: Omit<BuildOptions, 'watch'> = {
248248
...this.buildOptions,
249-
external: [...this.buildOptions.external, ...this.buildOptions.exclude],
249+
external: [
250+
...this.buildOptions.external,
251+
...(this.buildOptions.exclude === '*' || this.buildOptions.exclude.includes('*') ? [] : this.buildOptions.exclude)
252+
],
250253
entryPoints: [entry],
251254
outdir: path.join(this.buildDirPath, path.dirname(entry)),
252255
platform: 'node',

src/pack-externals.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,9 +205,14 @@ export async function packExternalModules(this: EsbuildServerlessPlugin) {
205205
packagePaths: findPackagePaths(),
206206
allowList: [],
207207
});
208-
}
208+
}
209+
210+
let externals = [];
209211

210-
const externals = without(this.buildOptions.exclude, this.buildOptions.external);
212+
// get the list of externals only if exclude is not set to *
213+
if (this.buildOptions.exclude !== '*' && !this.buildOptions.exclude.includes('*')) {
214+
externals = without(this.buildOptions.exclude, this.buildOptions.external);
215+
}
211216

212217
if (!externals || !externals.length) {
213218
return;

src/pack.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,13 @@ export async function pack(this: EsbuildServerlessPlugin) {
9595
const buildResults = this.buildResults;
9696
const bundlePathList = buildResults.map((b) => b.bundlePath);
9797

98-
// get a list of externals
99-
const externals = without<string>(this.buildOptions.exclude, this.buildOptions.external);
98+
let externals = [];
99+
100+
// get the list of externals to include only if exclude is not set to *
101+
if (this.buildOptions.exclude !== '*' && !this.buildOptions.exclude.includes('*')) {
102+
externals = without<string>(this.buildOptions.exclude, this.buildOptions.external);
103+
}
104+
100105
const hasExternals = !!externals?.length;
101106

102107
// get a tree of all production dependencies

0 commit comments

Comments
 (0)