-
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathvite.config.ts
More file actions
92 lines (89 loc) · 2.81 KB
/
vite.config.ts
File metadata and controls
92 lines (89 loc) · 2.81 KB
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
84
85
86
87
88
89
90
91
92
// vite.config.ts
import mdx from "@mdx-js/rollup";
import { tanstackRouter } from "@tanstack/router-vite-plugin";
import react from "@vitejs/plugin-react";
import path from "path";
import { defineConfig } from "vite";
// import { vitePluginMdToHTML } from "vite-plugin-md-to-html";
import { nodePolyfills } from "vite-plugin-node-polyfills";
import svgr from "vite-plugin-svgr";
// Service Worker Configuration (Development Watch)
export default defineConfig(({ command, mode }) => {
const isDev = command === "serve";
const isProd = mode === "production";
return {
build: {
assetsDir: "@static",
minify: isProd ? "esbuild" : false,
...(isProd && {
rollupOptions: {
output: {
manualChunks: undefined,
},
},
}),
},
esbuild: isProd
? {
pure: ["console.log", "console.debug", "console.info", "console.trace"],
}
: undefined,
// Disable Hot Module Replacement
plugins: [
mdx(),
// vitePluginMdToHTML({
// resolveImageLinks: false,
// }),
react({
babel: {
plugins: ["babel-plugin-react-compiler"],
},
// Exclude service worker and web worker files from React plugin
exclude: [/\.ww\.(ts|js)$/, /sw\.(ts|js)$/],
}),
tanstackRouter({
routeToken: "layout",
}),
// This plugin provides polyfills for Node.js core modules and globals.
// It handles both development (esbuild) and production (rollup) builds.
nodePolyfills({
// Whether to polyfill `node:` protocol imports.
protocolImports: false,
}),
svgr(),
],
resolve: {
alias: {
"@": path.resolve(__dirname, "./src"),
},
},
server: {
port: 3000,
headers: {
// Allow service workers to control the entire site scope
"Service-Worker-Allowed": "/",
"Access-Control-Allow-Origin": "*",
},
},
preview: {
headers: {
// Allow service workers to control the entire site scope in preview mode too
"Service-Worker-Allowed": "/",
// "Origin-Agent-Cluster": "?1",
},
},
// The `optimizeDeps` and `build.rollupOptions.plugins` sections
// for polyfills are no longer needed. The plugin handles it.
optimizeDeps: {
exclude: ["fsevents"], // Still a good idea to exclude this
},
// The `define` section for process.env is still useful.
// The plugin will handle polyfilling `process` and `global`.
define: {
"process.env.NODE_ENV": JSON.stringify(process.env.NODE_ENV || "development"),
"process.version": JSON.stringify("v18.18.0"),
__ENABLE_LOG__: JSON.stringify(isDev || process.env.ENABLE_LOG === "true"),
__LOG_LEVEL__: JSON.stringify(isProd ? "warn" : "debug"),
},
};
});