-
Notifications
You must be signed in to change notification settings - Fork 511
/
build.config.ts
84 lines (81 loc) · 1.95 KB
/
build.config.ts
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import { writeFile } from "node:fs/promises";
import { fileURLToPath } from "node:url";
import { resolve } from "pathe";
import { normalize } from "pathe";
import { defineBuildConfig } from "unbuild";
const srcDir = fileURLToPath(new URL("src", import.meta.url));
export const subpaths = [
"cli",
"config",
"core",
"kit",
"presets",
"rollup",
"runtime",
"meta",
"types",
];
export default defineBuildConfig({
declaration: true,
name: "nitro",
entries: [
// CLI
{ input: "src/cli/index.ts" },
// Config
{ input: "src/config/index.ts" },
// Core
{ input: "src/core/index.ts" },
// Runtime
{ input: "src/runtime/", outDir: "dist/runtime", format: "esm" },
// Kit
{ input: "src/kit/index.ts" },
// Meta
{ input: "src/meta/index.ts" },
// Presets
{ input: "src/presets/", outDir: "dist/presets", format: "esm" },
// Rollup
{ input: "src/rollup/index.ts" },
// Types
{ input: "src/types/index.ts" },
],
alias: {
nitropack: "nitropack",
"nitropack/meta": resolve(srcDir, "../meta.ts"),
"nitropack/runtime/meta": resolve(srcDir, "../runtime-meta.mjs"),
...Object.fromEntries(
subpaths.map((subpath) => [
`nitropack/${subpath}`,
resolve(srcDir, `${subpath}/index.ts`),
])
),
},
hooks: {
async "build:prepare"(ctx) {
for (const subpath of subpaths) {
await writeFile(
`./${subpath}.d.ts`,
`export * from "./dist/${subpath}/index";`
);
}
},
},
externals: [
"nitro",
"nitropack",
"nitropack/runtime/meta",
...subpaths.map((subpath) => `nitropack/${subpath}`),
"firebase-functions",
"@scalar/api-reference",
],
rollup: {
output: {
chunkFileNames(chunk: any) {
const id = normalize(chunk.moduleIds.at(-1));
if (id.includes("/src/cli/")) {
return "cli/[name].mjs";
}
return "_chunks/[name].mjs";
},
},
},
});