-
Notifications
You must be signed in to change notification settings - Fork 19
/
vite.config.mts
54 lines (50 loc) · 1.36 KB
/
vite.config.mts
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
import { defineConfig } from "vite";
import dts from "vite-plugin-dts";
import svgr from "vite-plugin-svgr";
import tailwindcss from "@tailwindcss/vite";
import { peerDependencies } from "./package.json";
import { Plugin } from "vite";
import fs from "fs";
const base64Loader: Plugin = {
name: "base64-loader",
transform(_: any, id: string) {
const [path, query] = id.split("?");
if (query != "base64") return null;
const data = fs.readFileSync(path);
const base64 = data.toString("base64");
const extension = path.split(".").pop();
return `export default 'data:image/${extension};base64,${base64}';`;
},
};
export default defineConfig({
build: {
lib: {
entry: {
index: "./src/index.ts",
providers: "./src/providers.index.ts",
},
name: "vite-react-ts-button",
fileName: (format, entryName) => `${entryName}.${format}.js`,
formats: ["cjs", "es"],
},
rollupOptions: {
/** "react/jsx-runtime" is needed to support both React 18 and 19, plus it makes the bundle smaller */
external: [
"react/jsx-runtime",
"wagmi/connectors",
"wagmi/chains",
...Object.keys(peerDependencies),
],
},
sourcemap: true,
emptyOutDir: true,
},
plugins: [
tailwindcss(),
dts(),
svgr({
include: "**/*.svg?react",
}),
base64Loader,
],
});