Skip to content
This repository was archived by the owner on Jan 28, 2025. It is now read-only.

Commit 7372bf2

Browse files
jvarhodphang
andauthored
Check if image component is used (#1065)
Co-authored-by: Daniel Phang <[email protected]>
1 parent 0a388c6 commit 7372bf2

File tree

4 files changed

+34
-4
lines changed

4 files changed

+34
-4
lines changed

packages/libs/lambda-at-edge/src/build.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1184,7 +1184,15 @@ class Builder {
11841184
const isDefaultLoader = !imageLoader || imageLoader === "default";
11851185
const hasImageOptimizer = hasImagesManifest && isDefaultLoader;
11861186

1187-
if (hasImageOptimizer) {
1187+
// ...nor if the image component is not used
1188+
const exportMarker = fse.existsSync(
1189+
join(this.dotNextDir, "export-marker.json")
1190+
)
1191+
? await fse.readJSON(path.join(this.dotNextDir, "export-marker.json"))
1192+
: {};
1193+
const isNextImageImported = exportMarker.isNextImageImported !== false;
1194+
1195+
if (hasImageOptimizer && isNextImageImported) {
11881196
await this.buildImageLambda(imageBuildManifest);
11891197
}
11901198

packages/libs/lambda-at-edge/tests/build/build-dynamic.test.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@ import { join } from "path";
22
import fse from "fs-extra";
33
import execa from "execa";
44
import Builder, { ASSETS_DIR } from "../../src/build";
5-
import { DEFAULT_LAMBDA_CODE_DIR, API_LAMBDA_CODE_DIR } from "../../src/build";
5+
import {
6+
DEFAULT_LAMBDA_CODE_DIR,
7+
API_LAMBDA_CODE_DIR,
8+
IMAGE_LAMBDA_CODE_DIR
9+
} from "../../src/build";
610
import { cleanupDir, removeNewLineChars } from "../test-utils";
711
import { OriginRequestDefaultHandlerManifest } from "../../src/types";
812

@@ -377,6 +381,18 @@ describe("Builder Tests (dynamic)", () => {
377381
});
378382
});
379383

384+
describe("Images Handler", () => {
385+
it("has empty images handler directory", async () => {
386+
expect.assertions(1);
387+
388+
const imageDir = await fse.readdir(
389+
join(outputDir, `${IMAGE_LAMBDA_CODE_DIR}`)
390+
);
391+
392+
expect(imageDir).toEqual([]);
393+
});
394+
});
395+
380396
describe("Default Handler", () => {
381397
it("copies build files", async () => {
382398
const files = await fse.readdir(

packages/libs/lambda-at-edge/tests/build/build-no-api.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,11 +153,11 @@ describe("Builder Tests (no API routes)", () => {
153153
it("has empty images handler directory", async () => {
154154
expect.assertions(1);
155155

156-
const apiDir = await fse.readdir(
156+
const imageDir = await fse.readdir(
157157
join(outputDir, `${IMAGE_LAMBDA_CODE_DIR}`)
158158
);
159159

160-
expect(apiDir).toEqual([]);
160+
expect(imageDir).toEqual([]);
161161
});
162162
});
163163

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"version": 1,
3+
"hasExportPathMap": false,
4+
"exportTrailingSlash": false,
5+
"isNextImageImported": false
6+
}

0 commit comments

Comments
 (0)