-
Notifications
You must be signed in to change notification settings - Fork 37
/
Copy pathvite.config.ts
51 lines (47 loc) · 1.14 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
import { defineConfig, Plugin } from "vite";
export default defineConfig({
plugins: [singleFile()],
base: "./",
build: {
polyfillModulePreload: false,
reportCompressedSize: false,
assetsInlineLimit: 0,
minify: "terser",
terserOptions: {
compress: {
unsafe_arrows: true,
passes: 2,
},
mangle: {
properties: {
// Glyph width overrides in font.json need to be preserved.
keep_quoted: true
},
},
},
rollupOptions: {
output: {
entryFileNames: `[name].js`,
chunkFileNames: `[name].js`,
assetFileNames: `[name].[ext]`,
},
},
},
});
function singleFile(): Plugin {
return {
name: "vite:single-file",
enforce: "post",
generateBundle(options, bundle) {
let html = bundle["index.html"] as any;
let js = bundle["index.js"] as any;
if (html.type === "asset") {
html.source = html.source
.replace(/<script.*<\/script>/, "")
.replace("</body>", () => `<script>${js.code}</script>`)
.replace(/\n+/g, "");
}
delete bundle[js.fileName];
}
};
}