generated from stormkit-io/monorepo-template-react
-
Notifications
You must be signed in to change notification settings - Fork 1
/
vite.config.api.ts
72 lines (69 loc) · 1.77 KB
/
vite.config.api.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
import { fileURLToPath } from "node:url";
import path from "node:path";
import fs from "node:fs";
import * as glob from "glob";
import dotenv from "dotenv";
import { build } from "vite";
dotenv.config();
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const files = glob
.sync("src/api/**/*.ts")
// Filter out private files
.filter((file) => {
return file.indexOf("_") !== 0 && file.indexOf("/_") === -1;
})
.map((file: string) => ({
entry: `./${file}`,
distFileName: file.replace("src/api/", "").replace(".ts", ""),
}));
(async () => {
for (const file of files) {
await build({
ssr: {
noExternal: fs
.readdirSync(path.join(__dirname, "node_modules"), {
withFileTypes: true,
})
.filter(
(dirent) => dirent.isDirectory() && !dirent.name.startsWith(".")
)
.map((dirent) => new RegExp(dirent.name)),
},
configFile: false,
resolve: {
alias: [
{
find: /^~/,
replacement: path.resolve(__dirname, "src"),
},
],
extensions: [".ts", ".tsx"],
},
define: {
...Object.keys(process.env).reduce(
(obj: Record<string, string>, key: string) => {
obj[`process.env.${key}`] = JSON.stringify(process.env[key]);
return obj;
},
{}
),
},
build: {
ssr: true,
emptyOutDir: false,
copyPublicDir: false,
rollupOptions: {
input: {
[file.distFileName]: file.entry,
},
output: {
dir: ".stormkit/api",
format: "cjs",
manualChunks: () => "",
},
},
minify: false,
},
});
}
})();