-
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathvite.lib.config.ts
More file actions
77 lines (71 loc) ยท 2.41 KB
/
vite.lib.config.ts
File metadata and controls
77 lines (71 loc) ยท 2.41 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import { readFileSync, readdirSync, writeFileSync } from "fs";
import { resolve } from "path";
import { defineConfig } from "vite";
import type { LibraryFormats, Plugin } from "vite";
import { appConfig } from "./vite.config";
const componentsDir = resolve(__dirname, "src/components");
const componentEntries = Object.fromEntries(
readdirSync(componentsDir, { withFileTypes: true })
.filter((d) => d.isDirectory() && d.name !== "shared")
.map((d) => [
`components/${d.name}/${d.name}`,
resolve(componentsDir, d.name, `${d.name}.tsx`),
]),
);
const libFormats: LibraryFormats[] = ["es"];
// ํฐํธ ํจํค์ง CSS๋ฅผ ๋น๋์ ์ธ๋ผ์ธํ์ง ์๊ณ @import๋ก ์ ์งํฉ๋๋ค.
const externalFontImports = [
"pretendard/dist/web/variable/pretendardvariable.css",
"@fontsource-variable/jetbrains-mono",
];
function keepFontImportsExternal(): Plugin {
return {
name: "keep-font-imports-external",
enforce: "pre",
transform(code, id) {
if (id.endsWith("index.css")) {
let result = code;
for (const imp of externalFontImports) {
result = result.replace(`@import "${imp}";`, "");
}
return result;
}
},
writeBundle(options) {
const outDir = options.dir ?? "dist";
const cssPath = resolve(outDir, "index.css");
const css = readFileSync(cssPath, "utf-8");
const imports = externalFontImports
.map((i) => `@import "${i}";`)
.join("\n");
writeFileSync(cssPath, imports + "\n" + css);
},
};
}
// https://vitejs.dev/config/
export default defineConfig({
...appConfig,
plugins: [...(appConfig.plugins ?? []), keepFontImportsExternal()],
build: {
lib: {
// ๋ผ์ด๋ธ๋ฌ๋ฆฌ ์ง์
์ ์ค์ ํฉ๋๋ค.
entry: {
// import { Button } from "daleui";
index: resolve(__dirname, "src/index.ts"),
// import { Button } from "daleui/button";
...componentEntries,
},
formats: libFormats,
},
rollupOptions: {
// ์ฌ์ฉํ๋ ์ชฝ ํ๋ก์ ํธ์ react๋ฅผ ๊ทธ๋๋ก ์ฌ์ฉํ๊ฒ ํฉ๋๋ค.
external: ["react", "react-dom", "react/jsx-runtime"],
output: {
// ๋ชจ๋ CSS ์์ฐ์ ํ๋์ ํ์ผ๋ก ๋ง๋ญ๋๋ค. (PandaCSS๋ ๋น๋ํ์์ css๋ฅผ ์์ฑํ๊ธฐ ๋๋ฌธ์)
assetFileNames: "index.css",
},
},
// public ๋๋ ํ ๋ฆฌ๋ฅผ ๋น๋ ๊ฒฐ๊ณผ๋ฌผ์ ๋ณต์ฌํ์ง ์์ต๋๋ค.
copyPublicDir: false,
},
});