-
Notifications
You must be signed in to change notification settings - Fork 4
/
vite.config.ts
74 lines (69 loc) · 1.68 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
/// <reference types="vitest" />
import path, { resolve } from "path";
import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
import { vitePluginForArco } from "@arco-plugins/vite-vue";
import manifest from "./manifest.json";
let sourcemap = false;
if (process.env.npm_lifecycle_event?.endsWith(":test")) {
sourcemap = true;
}
const getCRXVersion = () => {
if (process.env.CRX_VER) {
let ver = process.env.CRX_VER;
if (ver.startsWith("v")) {
ver = ver.slice(1);
}
return ver.slice(0, 14);
}
return "0.0.0-dev";
};
// https://vitejs.dev/config/
export default defineConfig({
plugins: [
vue(),
vitePluginForArco({
style: "css",
}),
{
name: "manifest",
generateBundle(outputOption, bundle) {
const entry = Object.values(bundle).find(
(chunk) =>
chunk.type == "chunk" && chunk.isEntry && chunk.name == "background"
);
manifest.version = getCRXVersion().split("-", 1)[0];
manifest.version_name = getCRXVersion();
manifest.background.service_worker = (entry as any).fileName;
this.emitFile({
type: "asset",
fileName: "manifest.json",
source: JSON.stringify(manifest, undefined, 2),
});
},
},
],
css: {
preprocessorOptions: {
scss: {
api: "modern-compiler",
},
},
},
test: {},
resolve: {
alias: {
"@": path.resolve(__dirname, "./src"),
},
},
build: {
rollupOptions: {
input: {
index: resolve(__dirname, "index.html"),
popup: resolve(__dirname, "popup.html"),
background: "src/background.ts",
},
},
sourcemap,
},
});