-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathvite.config.ssr.ts
83 lines (80 loc) · 2.1 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
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,
manifest: true,
rollupOptions: {
preserveEntrySignatures: 'strict',
input: { server: 'src/entry-server.tsx' },
output: {
dir: '.stormkit/server',
format: 'esm',
entryFileNames: '[name].mjs',
preserveModules: true,
preserveModulesRoot: 'src',
exports: 'named',
},
// Material ui's "use client" directive causes a warning.
// This function ignores those warnings.
// See https://github.com/rollup/rollup/issues/4699#issuecomment-1571555307
// for more information.
onwarn(warning, warn) {
if (
warning.code === 'MODULE_LEVEL_DIRECTIVE' &&
warning.message.includes('use client')
) {
return
}
warn(warning)
},
},
},
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',
},
],
}),
],
})