-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathvite.config.ts
More file actions
61 lines (57 loc) · 1.68 KB
/
vite.config.ts
File metadata and controls
61 lines (57 loc) · 1.68 KB
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
import { defineConfig, type UserConfig } from "vite";
import { resolve } from "path";
// Chrome拡張のcontent scriptはESM importが使えないため、
// content/backgroundとoptionsを別々のビルドとして実行する
export default defineConfig(({ mode }) => {
const target = process.env.BUILD_TARGET;
const isDev = mode === "development";
const commonDefine = {
__DEV__: JSON.stringify(isDev),
};
if (target === "options") {
return {
base: "/",
define: commonDefine,
build: {
outDir: "dist",
emptyOutDir: false,
rollupOptions: {
input: {
options: resolve(__dirname, "src/options/index.html"),
},
output: {
entryFileNames: "[name].js",
assetFileNames: "[name].[ext]",
},
},
},
experimental: {
renderBuiltUrl(filename) {
// Chrome拡張ではルート相対パスを使う
return "/" + filename;
},
},
} satisfies UserConfig;
}
// content + background: IIFEで個別ビルド
return {
define: commonDefine,
build: {
outDir: "dist",
emptyOutDir: !target, // 最初のビルドのみクリア
lib: {
entry: target === "background"
? resolve(__dirname, "src/background/index.ts")
: resolve(__dirname, "src/content/index.ts"),
formats: ["iife"],
name: target === "background" ? "scwBg" : "scwContent",
fileName: () => target === "background" ? "background.js" : "content.js",
},
rollupOptions: {
output: {
inlineDynamicImports: true,
},
},
},
} satisfies UserConfig;
});