-
Notifications
You must be signed in to change notification settings - Fork 4
/
vite.config.ts
70 lines (64 loc) · 1.92 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
import react from "@vitejs/plugin-react";
import "dotenv/config";
import { defineConfig } from "vite";
import { viteStaticCopy } from "vite-plugin-static-copy";
import zipPack from "vite-plugin-zip-pack";
import packageJson from "./package.json";
const platform = process.env.PLATFORM ?? "chrome";
// https://vitejs.dev/config/
export default defineConfig((env) => ({
build: {
emptyOutDir: true,
rollupOptions: {
input: ["index.html", "src/background.ts"],
output: {
entryFileNames: "[name].js",
},
},
},
plugins: [
react(),
viteStaticCopy({
targets: [
{
src: "src/manifest.json",
dest: ".",
transform: (content) => {
const manifest = JSON.parse(content);
if (packageJson.version.includes("-")) {
manifest.version = packageJson.version.split("-")[0];
manifest.version_name = packageJson.version;
} else {
manifest.version = packageJson.version;
}
if (env.mode === "development") {
manifest.version_name = packageJson.version + " (dev)";
}
if (platform === "chrome") {
manifest.background = {
service_worker: "background.js",
};
}
if (platform === "firefox") {
manifest.background = {
page: "background.js",
};
manifest.browser_specific_settings = {
gecko: {
id: "{ea2ad5bc-e458-414d-8565-5cfe9f7cf0c2}",
strict_min_version: "109.0",
},
};
}
return JSON.stringify(manifest, null, 4);
},
},
],
}),
zipPack({
outDir: "releases",
outFileName: `${packageJson.name}-v${packageJson.version}-${platform}.zip`,
enableLogging: false,
}),
],
}));