-
-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathvite.config.lib.ts
More file actions
59 lines (56 loc) · 1.6 KB
/
vite.config.lib.ts
File metadata and controls
59 lines (56 loc) · 1.6 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
54
55
56
57
58
59
import react from "@vitejs/plugin-react";
import { readFileSync } from "fs";
import path from "path";
import { fileURLToPath } from "url";
import { defineConfig } from "vite";
// ESM-compatible __dirname replacement
const __dirname = path.dirname(fileURLToPath(import.meta.url));
// Read version from package.json for consistent versioning (absolute path for CI/monorepo robustness)
const pkg = JSON.parse(
readFileSync(path.resolve(__dirname, "package.json"), "utf-8"),
) as {
version: string;
};
/**
* Vite configuration for building the npm library package.
*
* This produces an ES module build of the CIA Compliance Manager
* that can be consumed by other React applications.
*
* The standard app build (vite.config.ts) remains unchanged.
*/
export default defineConfig({
plugins: [react()],
define: {
APP_VERSION: JSON.stringify(pkg.version),
},
build: {
outDir: "dist",
sourcemap: process.env.BUILD_DEBUG === "true",
target: "es2025",
minify: process.env.BUILD_DEBUG !== "true",
lib: {
entry: path.resolve(__dirname, "src/index.ts"),
formats: ["es"],
fileName: () => "index.js",
},
rollupOptions: {
// Externalize peer dependencies - they should not be bundled
external: [
"react",
"react-dom",
"react/jsx-runtime",
"react-dom/client",
"chart.js",
"chart.js/auto",
"react-error-boundary",
],
output: {
// Preserve module structure for tree-shaking
preserveModules: true,
preserveModulesRoot: "src",
entryFileNames: "[name].js",
},
},
},
});