-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvite.config.ts
101 lines (96 loc) · 2.29 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
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
import fs from "fs";
import { fileURLToPath } from "node:url";
import { defaultAssetName } from "@vite-pwa/assets-generator/config";
import vue from "@vitejs/plugin-vue";
import { RollupOptions } from "rollup";
import { defineConfig } from "vite";
import { analyzer } from "vite-bundle-analyzer";
import { VitePWA, VitePWAOptions } from "vite-plugin-pwa";
await fs.promises.mkdir(`${import.meta.dirname}/public/assets/pwa`, { recursive: true });
const rollupOptions: RollupOptions = {
output: {
assetFileNames: "assets/[ext]/[name].[hash:20][extname]",
chunkFileNames: `assets/js/[name].[hash:20].js`,
entryFileNames: `assets/js/[name].[hash:20].js`,
hashCharacters: "hex",
manualChunks: (id) => {
if (id.includes("node_modules")) {
return "vendor";
}
return null;
},
},
};
const vitePWAOptions: Partial<VitePWAOptions> = {
filename: "service-worker.ts",
injectRegister: false,
injectManifest: {
globPatterns: [
"**/*.{js,css,html,woff2}",
"favicon.{ico,svg}",
],
},
manifest: {
name: "Morbo",
short_name: "Morbo",
lang: "en",
display: "standalone",
start_url: ".",
theme_color: "#ffffff",
},
pwaAssets: {
preset: {
assetName: (type, size) => {
return `assets/pwa/${defaultAssetName(type, size)}`;
},
transparent: {
sizes: [64, 192, 512],
favicons: [[48, "favicon.ico"]],
padding: 0,
},
maskable: {
sizes: [512],
padding: 0,
},
apple: {
sizes: [180],
padding: 0,
},
},
},
srcDir: "src",
strategies: "injectManifest",
};
export default defineConfig(({ mode }) => {
const developmentMode = mode === "development";
const analyzeMode = mode === "analyze";
return {
base: "./",
build: {
minify: !developmentMode && "esbuild",
sourcemap: developmentMode,
rollupOptions,
},
server: {
host: true,
},
define: {
DEV_MODE: developmentMode,
},
esbuild: {
supported: {
"top-level-await": true,
},
},
plugins: [
...analyzeMode ? [analyzer()] : [],
VitePWA(vitePWAOptions),
vue(),
],
resolve: {
alias: {
"@": fileURLToPath(new URL("./src", import.meta.url)),
},
},
};
});