Skip to content

Commit b5a233b

Browse files
authored
feat(bundle): remove rebuild because it causes slow performance on big… (#528)
* fix(bundle): remove rebuild because it causes slow performance on big projects * feat(bundle): add skipRebuild option * docs: add skipRebuild option
1 parent 7688e6f commit b5a233b

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ See [example folder](examples) for some example configurations.
8989
| `packagerOptions` | Extra options for packagers for `external` dependency resolution. | [Packager Options](#packager-options) |
9090
| `watch` | Watch options for `serverless-offline`. | [Watch Options](#watch-options) |
9191
| `skipBuild` | Avoid rebuilding lambda artifacts in favor of reusing previous build artifacts. | `false` |
92+
| `skipRebuild` | A boolean defining whether rebuild is avoided. Generally rebuild produces faster builds but in some context scenarios with many lambdas or low memory computer (like Github Actions) it can cause memory leaks. | `false` |
9293
| `skipBuildExcludeFns` | An array of lambda names that will always be rebuilt if `skipBuild` is set to `true` and bundling individually. This is helpful for dynamically generated functions like serverless-plugin-warmup. | `[]` |
9394
| `stripEntryResolveExtensions` | A boolean that determines if entrypoints using custom file extensions provided in the `resolveExtensions` ESbuild setting should be stripped of their custom extension upon packing the final bundle for that file. Example: `myLambda.custom.ts` would result in `myLambda.js` instead of `myLambda.custom.js`.
9495
| `disposeContext` | An option to disable the disposal of the context.(Functions can override the global `disposeContext` configuration by specifying their own `disposeContext` option in their individual configurations.) | `true`

src/bundle.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,13 @@ export async function bundle(this: EsbuildServerlessPlugin): Promise<void> {
108108
type WithContext = typeof pkg & { context?: ContextFn };
109109
const context = await (pkg as WithContext).context?.(options);
110110

111-
let result = await context?.rebuild();
112-
113-
if (!result) {
111+
let result;
112+
if (!buildOptions.skipRebuild) {
113+
result = await context?.rebuild();
114+
if (!result) {
115+
result = await pkg.build(options);
116+
}
117+
} else {
114118
result = await pkg.build(options);
115119
}
116120

src/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ export interface Configuration extends EsbuildOptions {
4646
outputFileExtension: '.js' | '.cjs' | '.mjs';
4747
nodeExternals?: NodeExternalsOptions;
4848
skipBuild?: boolean;
49+
skipRebuild?: boolean;
4950
skipBuildExcludeFns: string[];
5051
stripEntryResolveExtensions?: boolean;
5152
disposeContext?: boolean;

0 commit comments

Comments
 (0)