-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvite.config.ts
More file actions
150 lines (141 loc) · 5.4 KB
/
vite.config.ts
File metadata and controls
150 lines (141 loc) · 5.4 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
import { defineConfig, type Plugin } from "vite";
import path from "path";
import Vue from "@vitejs/plugin-vue";
import dts from "vite-plugin-dts";
import tailwindcss from "@tailwindcss/postcss";
/**
* Vite plugin: makes CSS <link> tags for lazy vendor chunks non-render-blocking.
* Converts `<link rel="stylesheet" href="...vendor-monaco...">` to use
* `media="print" onload="this.media='all'"` so they don't block first paint.
*/
function deferLazyCSSPlugin(patterns: string[]): Plugin {
return {
name: "defer-lazy-css",
enforce: "post",
transformIndexHtml(html) {
for (const pattern of patterns) {
const re = new RegExp(
`<link rel="stylesheet"([^>]*href="[^"]*${pattern}[^"]*"[^>]*)>`,
"g",
);
html = html.replace(re, (_, attrs) => {
return `<link rel="stylesheet"${attrs} media="print" onload="this.media='all'">`;
});
}
return html;
},
};
}
const defaultOptions = {
css: {
postcss: {
plugins: [tailwindcss()],
},
},
resolve: {
alias: {
"@src": path.resolve(import.meta.dirname, "src"),
"@styles": path.resolve(import.meta.dirname, "demo/@/styles"),
"@components": path.resolve(import.meta.dirname, "demo/@/components"),
"@utils": path.resolve(import.meta.dirname, "demo/@/utils"),
"@composables": path.resolve(import.meta.dirname, "demo/@/composables"),
"@assets": path.resolve(import.meta.dirname, "assets"),
"@mkbabb/keyframes.js": path.resolve(import.meta.dirname, "src/animation"),
},
},
};
const defaultPlugins = [Vue()];
export default defineConfig((mode) => {
if (mode.mode === "production") {
return {
...defaultOptions,
optimizeDeps: {},
build: {
minify: true,
lib: {
entry: path.resolve(import.meta.dirname, "src/animation/index.ts"),
name: "Keyframes",
fileName: "keyframes",
formats: ["es"],
},
rollupOptions: {
external: ["vue", "prettier", "@mkbabb/parse-that", "@mkbabb/value.js"],
},
},
esbuild: {
drop: ["console", "debugger"],
},
plugins: [...defaultPlugins, dts({ rollupTypes: true, include: ["src/"] })],
};
} else if (mode.mode === "gh-pages") {
// Heavy lazy chunks that should NOT be modulepreloaded or render-blocking
const lazyChunks = ["vendor-monaco", "vendor-three", "vendor-prettier", "vendor-highlight", "html2canvas"];
return {
...defaultOptions,
base: "./",
root: "./demo/app/",
build: {
outDir: path.resolve(import.meta.dirname, "./dist/"),
emptyOutDir: true,
minify: true,
sourcemap: false,
modulePreload: {
resolveDependencies(filename, deps) {
// Exclude heavy lazy-loaded vendor chunks from modulepreload.
// Without this, Vite injects <link rel="modulepreload"> for Monaco (3.7 MB),
// Three.js, Prettier etc. into the HTML, defeating code splitting.
return deps.filter(dep => !lazyChunks.some(c => dep.includes(c)));
},
},
cssCodeSplit: true,
rollupOptions: {
output: {
manualChunks(id) {
if (id.includes("node_modules")) {
if (id.includes("three")) return "vendor-three";
if (id.includes("monaco")) return "vendor-monaco";
if (id.includes("prettier")) return "vendor-prettier";
if (id.includes("highlight")) return "vendor-highlight";
if (id.includes("reka-ui")) return "vendor-reka-ui";
if (id.includes("lucide")) return "vendor-lucide";
}
},
},
},
},
plugins: [...defaultPlugins, deferLazyCSSPlugin(["vendor-monaco"])],
};
} else if (mode.mode === "playground") {
// Playground demo: asset manager + multi-element animations
return {
...defaultOptions,
root: "./demo/playground/",
optimizeDeps: {
include: [
"vue",
"reka-ui",
"@vueuse/core",
"lucide-vue-next",
"vue-sonner",
],
},
plugins: [...defaultPlugins],
};
} else {
// Dev mode: serve the demo app with HMR
return {
...defaultOptions,
root: "./demo/app/",
optimizeDeps: {
include: [
"vue",
"reka-ui",
"@vueuse/core",
"lucide-vue-next",
"vue-sonner",
],
},
plugins: [...defaultPlugins],
};
}
});