-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvite.config.ts
74 lines (72 loc) · 1.94 KB
/
vite.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
import path from "path";
import pages from "@hono/vite-build/cloudflare-pages";
import devServer from "@hono/vite-dev-server";
import adapter from "@hono/vite-dev-server/cloudflare";
import { defineConfig, type UserConfig } from "vite";
import { NodeGlobalsPolyfillPlugin } from "@esbuild-plugins/node-globals-polyfill";
import { NodeModulesPolyfillPlugin } from "@esbuild-plugins/node-modules-polyfill";
import rollupNodePolyFill from "rollup-plugin-node-polyfills";
export default defineConfig(({ mode }) => {
const globalConfig: UserConfig = {
base: "/",
publicDir: "src/static",
optimizeDeps: {
esbuildOptions: {
define: {
global: "globalThis",
},
plugins: [
NodeGlobalsPolyfillPlugin({
process: true,
buffer: true,
}),
NodeModulesPolyfillPlugin() as any,
],
},
},
resolve: {
alias: {
"@": path.resolve(__dirname, "./src"),
stream: "rollup-plugin-node-polyfills/polyfills/stream",
util: "rollup-plugin-node-polyfills/polyfills/util",
events: "rollup-plugin-node-polyfills/polyfills/events",
"urbit-key-generation": path.resolve(
__dirname,
"src/shims/urbit-key-generation.js"
),
},
},
build: {
rollupOptions: {
plugins: [rollupNodePolyFill],
},
},
};
if (mode === "bundle") {
return {
...globalConfig,
build: {
...globalConfig.build,
rollupOptions: {
...globalConfig.build?.rollupOptions,
input: ["./src/bundle.ts", "./src/index.css"],
output: {
entryFileNames: "static/bundle.js",
assetFileNames: "static/[name].[ext]",
},
},
},
};
} else {
return {
...globalConfig,
plugins: [
pages(),
devServer({
adapter,
entry: "src/index.tsx",
}),
],
};
}
});