Skip to content

Commit

Permalink
feat(config): exclude option
Browse files Browse the repository at this point in the history
add extra option excluding external module from the deployment package

closes #23
  • Loading branch information
uneco authored Jul 1, 2020
1 parent 1229d59 commit 38c6934
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ custom:
minify: false
```

The `aws-sdk` module is exluded from bundle by default, and you can exclude additional dependencies using `external` option.
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']`.

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

Expand Down
10 changes: 8 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,16 @@ interface ServiceExtended extends Service {
functions?: Record<string, Serverless.FunctionDefinition>;
}

interface Configuration extends BuildOptions {
export interface Configuration extends BuildOptions {
packager: 'npm' | 'yarn';
exclude: string[];
}

const DEFAULT_BUILD_OPTIONS: Partial<Configuration> = {
bundle: true,
target: 'es2017',
external: ['aws-sdk'],
external: [],
exclude: ['aws-sdk'],
packager: 'npm',
};

Expand Down Expand Up @@ -132,6 +134,10 @@ export class EsbuildPlugin implements Plugin {
await Promise.all(this.rootFileNames.map(entry => {
const config: BuildOptions = {
...this.buildOptions,
external: [
...this.buildOptions.external,
...this.buildOptions.exclude,
],
entryPoints: [entry],
outdir: path.join(this.originalServicePath, BUILD_FOLDER, path.dirname(entry)),
platform: 'node',
Expand Down
2 changes: 1 addition & 1 deletion src/packExternalModules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ function getProdModules(externalModules: { external: string }[], packagePath: st
* and performance.
*/
export async function packExternalModules() {
const externals = without(['aws-sdk'], this.buildOptions.external);
const externals = without(this.buildOptions.exclude, this.buildOptions.external);

if (!externals) {
return;
Expand Down

0 comments on commit 38c6934

Please sign in to comment.