-
Notifications
You must be signed in to change notification settings - Fork 1
/
vite.config.ts
76 lines (68 loc) · 1.87 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
75
76
import { Plugin, defineConfig } from "vite";
import { createHtmlPlugin } from "vite-plugin-html";
import { VitePWA } from "vite-plugin-pwa";
import * as mdi from "@mdi/js";
import { manifest } from "./manifest";
import { themes } from "./src/theme-data";
export default defineConfig(({ command }) => ({
plugins: [
createHtmlPlugin({
inject: {
data: {
...mdi,
COMMAND: command,
DESCRIPTION: manifest.description,
TITLE: manifest.name,
BASE_URL: "https://othello-rust.web.app",
},
},
minify: {
collapseWhitespace: true,
collapseInlineTagWhitespace: true,
removeComments: true,
removeRedundantAttributes: true,
removeOptionalTags: true,
removeScriptTypeAttributes: true,
removeStyleLinkTypeAttributes: true,
minifyCSS: true,
minifyJS: true,
},
}),
VitePWA({
manifest,
includeManifestIcons: false,
includeAssets: ["favicon.ico", "icons/any.svg"],
workbox: {
sourcemap: true,
globPatterns: ["**/*.{html,js,css,wasm,woff2}"],
},
}),
modulepreloadPlugin({ regex: /worker-[0-9a-f]+\.js$/ }),
],
build: {
target: "esnext",
modulePreload: { polyfill: false },
sourcemap: true,
},
define: {
__THEME_DATA__: JSON.stringify(themes, undefined, 2),
},
}));
function modulepreloadPlugin({ regex }: { regex: RegExp }): Plugin {
let baseUrl: string;
return {
name: "modulepreload",
configResolved({ base }) {
baseUrl = base;
},
transformIndexHtml(html, { bundle }) {
return Object.values(bundle ?? {})
.filter((chunk) => regex.test(chunk.fileName))
.map((chunk) => ({
tag: "link",
attrs: { rel: "modulepreload", href: baseUrl + chunk.fileName },
injectTo: "head",
}));
},
};
}