-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvite.config.ts
More file actions
53 lines (47 loc) · 1.46 KB
/
vite.config.ts
File metadata and controls
53 lines (47 loc) · 1.46 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
import { fileURLToPath, URL } from "node:url";
import { defineConfig } from "vite";
import type { LibraryFormats } from "vite";
export default defineConfig(({ mode }) =>
{
const isBundler = (mode === "bundler");
const isDev = (mode === "development");
const isProd = (mode === "production");
let suffix: string;
if (isBundler) { suffix = "bundler."; }
else if (isProd) { suffix = "prod."; }
else { suffix = ""; }
const formats: LibraryFormats[] = [];
if (isBundler) { formats.push("es"); }
else
{
formats.push("cjs");
if (isProd) { formats.push("iife"); }
}
return {
define: { "import.meta.env.DEV": isBundler ? "import.meta.env.DEV" : JSON.stringify(isDev) },
build: {
minify: isProd,
lib: {
entry: fileURLToPath(new URL("src/index.ts", import.meta.url)),
fileName: (format) =>
{
if (format === "cjs") { return `micro-ecs.${suffix}cjs`; }
if (format === "es") { return `micro-ecs.esm.${suffix}js`; }
if (format === "iife") { return `micro-ecs.global.${suffix}js`; }
if (format === "umd") { return `micro-ecs.umd.${suffix}cjs`; }
throw new Error(`Unknown build format: ${format}`);
},
formats: formats,
name: "MicroECS"
},
rollupOptions: {
external: ["@byloth/core"],
output: {
exports: "named",
globals: { "@byloth/core": "Core" }
}
},
emptyOutDir: isProd
}
};
});