-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvite.config.ts
65 lines (64 loc) · 1.55 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
import { resolve } from "node:path";
import { readFile } from "fs/promises";
import { defineConfig } from "vite";
import copy from "rollup-plugin-copy";
export default defineConfig({
build: {
outDir: resolve("dist"),
emptyOutDir: true,
chunkSizeWarningLimit: 5 * 1024 * 1024,
rollupOptions: {
input: ["src/scripts/content.ts", "src/popup/index.tsx"],
output: {
entryFileNames: ({ name }) => {
if (name === "content") {
return `scripts/${name}.js`;
} else {
return `popup/${name}.js`;
}
},
},
onwarn: (warning) => {
if (warning.code === "MODULE_LEVEL_DIRECTIVE") return;
},
},
},
plugins: [
{
name: "hackly resolve modules for disabling code-splitting",
enforce: "pre",
resolveId(source, importer) {
if (
source.endsWith("presetColors") &&
importer?.endsWith("content.ts")
) {
return {
id: resolve("src/share/presetColors.ts?is_copied"),
};
}
},
load(id) {
if (id.endsWith("src/share/presetColors.ts?is_copied")) {
return readFile("src/share/presetColors.ts", "utf-8");
}
},
},
copy({
targets: [
{
src: "src/popup/index.html",
dest: "dist/popup/",
},
{
src: "manifest.json",
dest: "dist/",
},
{
src: "images/icons/",
dest: "dist/",
},
],
hook: "writeBundle",
}),
],
});