-
Notifications
You must be signed in to change notification settings - Fork 119
Expand file tree
/
Copy pathcompile-images.ts
More file actions
34 lines (30 loc) · 1.17 KB
/
compile-images.ts
File metadata and controls
34 lines (30 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import fs from "node:fs";
import path from "node:path";
import { fileURLToPath } from "node:url";
import type { BuildOptions } from "@opennextjs/aws/build/helper.js";
import { build } from "esbuild";
/**
* Compiles the initialization code for the workerd runtime
*/
export async function compileImages(options: BuildOptions) {
const currentDir = path.join(path.dirname(fileURLToPath(import.meta.url)));
const templatesDir = path.join(currentDir, "../../templates");
const imagesPath = path.join(templatesDir, "images.js");
const imagesManifestPath = path.join(options.appBuildOutputPath, ".next/images-manifest.json");
const imagesManifest = fs.existsSync(imagesManifestPath)
? JSON.parse(fs.readFileSync(imagesManifestPath, { encoding: "utf-8" }))
: {};
await build({
entryPoints: [imagesPath],
outdir: path.join(options.outputDir, "cloudflare"),
bundle: false,
minify: false,
format: "esm",
target: "esnext",
platform: "node",
define: {
__IMAGES_REMOTE_PATTERNS__: JSON.stringify(imagesManifest?.images?.remotePatterns ?? []),
__IMAGES_LOCAL_PATTERNS__: JSON.stringify(imagesManifest?.images?.localPatterns ?? []),
},
});
}