Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ custom:
```

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.
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']`.
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`.

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

Expand Down
7 changes: 5 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export interface PackagerOptions {
export interface Configuration extends Omit<BuildOptions, 'nativeZip' | 'watch' | 'plugins'> {
packager: 'npm' | 'yarn';
packagePath: string;
exclude: string[];
exclude: '*' | string[];
nativeZip: boolean;
watch: WatchConfiguration;
plugins?: string;
Expand Down Expand Up @@ -248,7 +248,10 @@ export class EsbuildServerlessPlugin implements ServerlessPlugin {
this.rootFileNames.map(async ({ entry, func, functionAlias }) => {
const config: Omit<BuildOptions, 'watch'> = {
...this.buildOptions,
external: [...this.buildOptions.external, ...this.buildOptions.exclude],
external: [
...this.buildOptions.external,
...(this.buildOptions.exclude === '*' || this.buildOptions.exclude.includes('*') ? [] : this.buildOptions.exclude)
Copy link
Owner

Choose a reason for hiding this comment

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

here if exclude is * we must put all the dependencies as external otherwise they will be bundled which we do not need. in other words, if * it should behave like webpack-node-externals

],
entryPoints: [entry],
outdir: path.join(this.buildDirPath, path.dirname(entry)),
platform: 'node',
Expand Down
9 changes: 7 additions & 2 deletions src/pack-externals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,9 +205,14 @@ export async function packExternalModules(this: EsbuildServerlessPlugin) {
packagePaths: findPackagePaths(),
allowList: [],
});
}
}

let externals = [];

const externals = without(this.buildOptions.exclude, this.buildOptions.external);
// get the list of externals only if exclude is not set to *
if (this.buildOptions.exclude !== '*' && !this.buildOptions.exclude.includes('*')) {
externals = without(this.buildOptions.exclude, this.buildOptions.external);
}

if (!externals || !externals.length) {
return;
Expand Down
9 changes: 7 additions & 2 deletions src/pack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,13 @@ export async function pack(this: EsbuildServerlessPlugin) {
const buildResults = this.buildResults;
const bundlePathList = buildResults.map((b) => b.bundlePath);

// get a list of externals
const externals = without<string>(this.buildOptions.exclude, this.buildOptions.external);
let externals = [];

// get the list of externals to include only if exclude is not set to *
if (this.buildOptions.exclude !== '*' && !this.buildOptions.exclude.includes('*')) {
externals = without<string>(this.buildOptions.exclude, this.buildOptions.external);
}

const hasExternals = !!externals?.length;

// get a tree of all production dependencies
Expand Down