-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvite.config.web.ts
47 lines (43 loc) · 1.08 KB
/
vite.config.web.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
import react from "@vitejs/plugin-react";
import fs from "node:fs";
import { defineConfig, Plugin } from "vite";
// https://vitejs.dev/config/
export default defineConfig(() => ({
plugins: [react(), pwaPlugin],
publicDir: "./public",
server: {
port: 3000,
strictPort: true,
watch: {
ignored: ["**/src-tauri/**"],
},
},
build: {
outDir: "./dist-web",
emptyOutDir: true,
minify: false,
sourcemap: true,
},
esbuild: {
define: {
"process.env.APP_ENV": "'web'",
},
},
}));
const pwaPlugin = {
name: "pwa",
async writeBundle() {
const outFiles = await fs.promises.readdir("./dist-web", { recursive: true });
const sw = await fs.promises.readFile("./dist-web/sw.js", "utf-8");
const excludeFiles = ["sw.js", "assets"];
const injectFilenames = outFiles
.filter((f) => !excludeFiles.includes(f))
.concat("") // Root
.map((f) => `"/${f}"`)
.join(",\n");
await fs.promises.writeFile(
"./dist-web/sw.js",
sw.replace("/* <INJECTED> */", injectFilenames)
);
},
} satisfies Plugin;