-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvite.config.js
57 lines (51 loc) · 1.34 KB
/
vite.config.js
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
import { viteRuntimeNode } from 'vite-runtime-node-plugin';
import { viteRuntimeWorkerd } from 'vite-runtime-workerd-plugin';
export function exampleFramework({ entrypoint }) {
return {
name: 'example-framework-plugin',
configureServer(server) {
return async () => {
const ssrRuntime = await server.ssrRuntime$;
const dispatchRequest = await ssrRuntime.createRequestDispatcher({
entrypoint,
});
server.middlewares.use(async (req, res) => {
const resp = await dispatchRequest(req);
const html = await resp.text();
const transformedHtml = await server.transformIndexHtml(
req.url,
html,
);
res.end(transformedHtml);
});
};
},
};
}
const runtimeInfos = {
node: {
plugin: viteRuntimeNode,
entrypoint: './entry-node.ts',
},
workerd: {
plugin: viteRuntimeWorkerd,
entrypoint: './entry-workerd.ts',
},
};
const runtimeInfo =
runtimeInfos[process.env._VITE_TARGET_RUNTIME] ?? runtimeInfos['node'];
const { plugin, entrypoint } = runtimeInfo;
/** @type {import('vite').UserConfig} */
export default {
appType: 'custom',
ssr: {
target: 'webworker',
},
optimizeDeps: {
include: [],
},
plugins: [plugin(), exampleFramework({ entrypoint })],
build: {
minify: false,
},
};