-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvite.config.ts
More file actions
35 lines (32 loc) · 1022 Bytes
/
vite.config.ts
File metadata and controls
35 lines (32 loc) · 1022 Bytes
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
import { defineConfig, loadEnv } from "vite";
import react from "@vitejs/plugin-react";
import tsconfigPaths from "vite-tsconfig-paths";
import path from "path";
import fs from "fs";
function userScriptPlugin(appUrl: string): any {
return {
name: "userscript-plugin",
writeBundle() {
const filePath = path.resolve(__dirname, "dist/static/install.user.js");
if (fs.existsSync(filePath)) {
let content = fs.readFileSync(filePath, "utf-8");
content = content.replace("{VITE_APP_URL}", appUrl);
fs.writeFileSync(filePath, content);
}
},
};
}
export default defineConfig(({ mode }) => {
const env = loadEnv(mode, process.cwd(), "");
const appUrl =
process.env.VITE_APP_URL || env.VITE_APP_URL || "http://localhost:3000";
const appBase = process.env.VITE_APP_BASE || env.VITE_APP_BASE || "./";
return {
plugins: [react(), tsconfigPaths(), userScriptPlugin(appUrl)],
server: {
port: 3000,
cors: true,
},
base: appBase,
};
});