forked from loczek/ExtensionV3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vite.config.ts
146 lines (131 loc) · 3.22 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
import { BranchName, getManifest } from "./manifest.config";
import { version } from "./package.json";
import vue from "@vitejs/plugin-vue";
import { spawn } from "child_process";
import fs from "fs-extra";
import path from "path";
import { defineConfig, loadEnv } from "vite";
const r = (...args: string[]) => path.resolve(__dirname, ...args);
const chunks = {
common: [
"./src/common/Async.ts",
"./src/common/Logger.ts",
"./src/common/Rand.ts",
"./src/common/Reflection.ts",
"./src/common/Transform.ts",
"./src/common/ReactHooks.ts",
],
store: ["./src/store/main.ts"],
db: [
"./src/db/idb.ts",
"./src/db/versions.idb.ts",
"./src/composable/useLiveQuery.ts",
"./src/composable/useSettings.ts",
],
tw_mod_chat: ["./src/site/twitch.tv/modules/chat/ChatModule.vue"],
tw_mod_chat_input: ["./src/site/twitch.tv/modules/chat-input/ChatInputModule.vue"],
tw_mod_emote_menu: ["./src/site/twitch.tv/modules/emote-menu/EmoteMenuModule.vue"],
tw_mod_settings: ["./src/site/twitch.tv/modules/settings/SettingsModule.vue"],
};
const ignoreHMR = [
"main.ts",
"idb.ts",
"versions.idb.ts",
"useModule.ts",
"useWorker.ts",
"App.vue",
"TwitchSite.vue",
"ChatModule.vue",
"ChatController.vue",
"ChatInputModule.vue",
"EmoteMenuModule.vue",
"SettingsModule.vue",
];
// https://vitejs.dev/config/
export default defineConfig(({ mode }) => {
const isDev = mode === "dev";
process.env = {
...process.env,
...loadEnv(mode, process.cwd()),
VITE_APP_VERSION: version,
};
return {
server: {
port: 4777,
strictPort: true,
https: false,
hmr: {
port: 4778,
protocol: "ws",
},
},
base: isDev ? "http://localhost:4777/" : undefined,
resolve: {
alias: {
"@": path.resolve(__dirname, "src"),
},
},
root: ".",
publicDir: "public",
build: {
outDir: "dist",
emptyOutDir: true,
cssCodeSplit: false,
write: true,
sourcemap: isDev,
chunkSizeWarningLimit: 1000,
rollupOptions: {
input: {
background: r("src/background.ts"),
content: r("src/content/content.ts"),
site: r("src/site/site.ts"),
},
output: {
manualChunks: chunks,
entryFileNames: (info) => {
const name = path.basename(info.facadeModuleId.replace(".ts", ".js"));
return name;
},
assetFileNames: "assets/[name][extname]",
chunkFileNames: "assets/[name].js",
},
},
},
plugins: [
vue(),
{
name: "hmr-ignore",
handleHotUpdate(this, ctx) {
const base = path.basename(ctx.file);
// Ignore specific files in HMR
if (ignoreHMR.includes(base)) {
ctx.server.ws.send("full-reload");
return [];
}
return null;
},
},
{
name: "compile-manifest",
enforce: "post",
apply: "build",
async buildEnd() {
const man = await getManifest(
{
dev: isDev,
branch: process.env.BRANCH as BranchName,
mv2: isDev || !!process.env.MV2,
},
Object.keys(chunks)
.map((key) => [`assets/${key}.js`, `assets/${key}.js.map`])
.reduce((a, b) => [...a, ...b], []),
);
setTimeout(() => {
fs.writeJSON(r("dist/manifest.json"), man);
spawn("yarn", ["build:worker", "--mode", mode], { shell: true, stdio: "inherit" });
});
},
},
],
};
});