generated from stormkit-io/monorepo-template-react
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvite.config.ssr.ts
68 lines (66 loc) · 1.66 KB
/
vite.config.ssr.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
import path from "node:path";
import fs from "node:fs";
import { fileURLToPath } from "node:url";
import { defineConfig } from "vite";
import { viteStaticCopy } from "vite-plugin-static-copy";
import react from "@vitejs/plugin-react";
import dotenv from "dotenv";
dotenv.config();
process.env.NODE_ENV = "production";
const __dirname = path.dirname(fileURLToPath(import.meta.url));
// https://vitejs.dev/config/
export default defineConfig({
ssr: {
noExternal: fs
.readdirSync(path.join(__dirname, "node_modules"), {
withFileTypes: true,
})
.filter((dirent) => dirent.isDirectory() && !dirent.name.startsWith("."))
.map((dirent) => new RegExp(dirent.name)),
},
resolve: {
alias: [
{
find: /^~/,
replacement: path.resolve(__dirname, "src"),
},
],
extensions: [".mjs", ".js", ".ts", ".jsx", ".tsx", ".json"],
},
build: {
ssr: true,
minify: false,
rollupOptions: {
preserveEntrySignatures: "strict",
input: { server: "src/entry-server.tsx" },
output: {
dir: ".stormkit/server",
format: "esm",
entryFileNames: "[name].mjs",
preserveModules: true,
preserveModulesRoot: "src",
exports: "named",
},
},
},
define: {
...Object.keys(process.env).reduce(
(obj: Record<string, string>, key: string) => {
obj[`process.env.${key}`] = JSON.stringify(process.env[key]);
return obj;
},
{}
),
},
plugins: [
react(),
viteStaticCopy({
targets: [
{
src: ".stormkit/public/index.html",
dest: "../.stormkit/server",
},
],
}),
],
});