-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathvite.config.ts
38 lines (35 loc) · 1.14 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
import { exec } from "node:child_process";
import { promisify } from "node:util";
import { UserConfig, defineConfig } from "vite";
import viteCompression from "vite-plugin-compression";
import pkg from "./package.json";
const $ = async (command: string, env = "") =>
process.env[env] ?? (await promisify(exec)(command)).stdout.trim();
const all = async (obj: Record<string, string | Promise<string>>) =>
Object.fromEntries(
await Promise.all(
Object.entries(obj).map(async ([k, v]) => [k, JSON.stringify(await v)]),
),
);
export default defineConfig(
async (): Promise<UserConfig> => ({
build: {
target: "es6",
lib: {
entry: "src/main.ts",
formats: ["es"],
},
},
esbuild: {
legalComments: "none",
},
plugins: [viteCompression({ verbose: false })],
define: await all({
__NAME__: pkg.name.toUpperCase(),
__BRANCH__: $("git rev-parse --abbrev-ref HEAD", "GITHUB_REF_NAME"),
__VERSION__: $("git describe --tags --dirty --always", "VERSION"),
__COMMIT__: $("git rev-parse HEAD", "GITHUB_SHA"),
__BUILD_TIME__: new Date().toISOString(),
}),
}),
);