-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvite.config.lib.ts
More file actions
57 lines (55 loc) · 1.37 KB
/
vite.config.lib.ts
File metadata and controls
57 lines (55 loc) · 1.37 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
/// <reference types="vitest" />
import { nxViteTsPaths } from "@nx/vite/plugins/nx-tsconfig-paths.plugin";
import dts from "vite-plugin-dts";
import { defineConfig, type UserConfig } from "vite";
import { resolve } from "node:path";
/**
* Shared Vite configuration for library builds.
* Generates ES modules with TypeScript declarations.
*/
export function createLibConfig(options: {
root: string;
name: string;
entry?: string;
external?: string[];
}): UserConfig {
const { root, name, entry = "src/index.ts", external = [] } = options;
return defineConfig({
root,
plugins: [
nxViteTsPaths(),
dts({
include: ["src/**/*"],
exclude: ["**/*.test.ts", "**/*.spec.ts"],
outDir: "dist",
rollupTypes: true,
tsconfigPath: resolve(root, "tsconfig.json"),
}),
],
build: {
lib: {
entry: resolve(root, entry),
name,
formats: ["es"],
fileName: () => "index.js",
},
sourcemap: true,
emptyOutDir: true,
target: "esnext",
rollupOptions: {
external: [
// Node built-ins
/^node:/,
// All workspace packages
/^@bibgraph\//,
// Common externals
...external,
],
output: {
preserveModules: true,
preserveModulesRoot: "src",
},
},
},
});
}