Skip to content

Commit f25336c

Browse files
committed
Add bundling option for image handler function
Sharp recommends to exclude the library from bundling Reference: https://sharp.pixelplumbing.com/install#esbuild
1 parent 02eaed2 commit f25336c

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

source/constructs/lib/back-end/back-end-construct.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,20 @@ export class BackEnd extends Construct {
106106
DEFAULT_FALLBACK_IMAGE_BUCKET: props.fallbackImageS3Bucket,
107107
DEFAULT_FALLBACK_IMAGE_KEY: props.fallbackImageS3KeyBucket,
108108
},
109+
bundling: {
110+
externalModules: ["sharp"],
111+
commandHooks: {
112+
beforeBundling(inputDir: string, outputDir: string): string[] {
113+
return [];
114+
},
115+
beforeInstall(inputDir: string, outputDir: string): string[] {
116+
return [];
117+
},
118+
afterBundling(inputDir: string, outputDir: string): string[] {
119+
return [`cd ${outputDir}`, "npm install --arch=x64 --platform=linux sharp"];
120+
},
121+
},
122+
},
109123
});
110124

111125
const imageHandlerLogGroup = new LogGroup(this, "ImageHandlerLogGroup", {

0 commit comments

Comments
 (0)