-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvite.config.ts
55 lines (52 loc) · 1.41 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import path from "path";
import fs from "fs";
import { defineConfig } from "vite";
import react from "@vitejs/plugin-react";
import dts from "vite-plugin-dts";
import exported from "./exports.json";
const entries = Object.values(exported).map(({ entry }) =>
path.resolve(__dirname, entry)
);
const inputs: { [component: string]: string } = {};
Object.entries(exported).forEach(([component, value]) => {
inputs[component] = path.resolve(__dirname, value.input);
/** Generate entry points for each export file with a type */
if ("types" in value) {
fs.writeFileSync(
path.resolve(`./${component}.d.ts`),
`export * from "${value.types}";`
);
fs.writeFileSync(
path.resolve(`./${component}.js`),
`module.exports = require("${value.entry}");`
);
}
});
export default defineConfig({
build: {
outDir: "build",
/** Docs - https://vitejs.dev/guide/build.html#library-mode */
lib: {
entry: entries,
name: "@ouellettec/design-system",
},
ssr: true,
rollupOptions: {
external: ["react"],
input: inputs,
output: {
globals: {
react: "React",
},
},
},
},
plugins: [react(), dts()],
resolve: {
alias: {
"@Components": path.resolve(__dirname, "./src/components"),
"@Utilities": path.resolve(__dirname, "./src/utilities"),
"@Lib": path.resolve(__dirname, "./src/lib"),
},
},
});