Repository navigation
Expand file tree
/
Copy pathvite.config.ts
More file actions
53 lines (49 loc) · 1.66 KB
/
Copy pathvite.config.ts
File metadata and controls
53 lines (49 loc) · 1.66 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 { readFileSync } from "node:fs"
import { resolve } from "node:path"
import react from "@vitejs/plugin-react"
import { defineConfig } from "vite"
const pkg = JSON.parse(readFileSync(new URL("./package.json", import.meta.url), "utf8")) as {
dependencies?: Record<string, string>
peerDependencies?: Record<string, string>
}
const externals = [...Object.keys(pkg.dependencies ?? {}), ...Object.keys(pkg.peerDependencies ?? {})]
const isExternal = (id: string) =>
externals.some((dep) => id === dep || id.startsWith(`${dep}/`)) ||
/^(react|react-dom|@testing-library\/react)(\/|$)/.test(id)
/** Library entry points, mirrored by package.json `exports`. */
export const entries: Record<string, string> = {
index: "src/index.ts",
html: "src/html.ts",
onu: "src/onu.ts",
"onu-editor": "src/onu-editor.ts",
"onu-maps": "src/onu-maps.ts",
testing: "src/testing.ts",
inertia: "src/inertia.ts",
shadcn: "src/shadcn.ts",
}
const output = {
preserveModules: true,
preserveModulesRoot: "src",
// Every module may run on the client; mark them for React Server Components.
banner: '"use client";',
}
export default defineConfig({
plugins: [react()],
build: {
reportCompressedSize: false,
outDir: "dist",
emptyOutDir: true,
sourcemap: true,
minify: false,
lib: {
entry: Object.fromEntries(Object.entries(entries).map(([k, v]) => [k, resolve(import.meta.dirname, v)])),
},
rollupOptions: {
external: isExternal,
output: [
{ ...output, format: "es" as const, entryFileNames: "[name].js" },
{ ...output, format: "cjs" as const, entryFileNames: "[name].cjs", exports: "named" as const },
],
},
},
})