-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvite.config.ts
74 lines (68 loc) · 2.04 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import react from "@vitejs/plugin-react";
import { defineConfig } from "vite";
import dtsPlugin from "vite-plugin-dts";
import preserveDirectives from "rollup-plugin-preserve-directives";
import entryPointsDtsPlugin from "./scripts/vite-plugin-entryPoints-dts";
import { peerDependencies, devDependencies } from "./package.json";
const entryPoints: Record<string, string> = {
index: "src/_root",
components: "src/_components",
element: "src/_element",
video: "src/_video",
};
const facadeModuleIdMap = new Map<string, boolean>();
const format = process.argv
.find((part) => part.startsWith("--format="))
?.split("=")[1] as "es" | "cjs" | undefined;
export default defineConfig({
build: {
lib: {
entry: entryPoints,
name: "react-scrolly-telling",
formats: format ? [format] : ["es", "cjs"],
fileName: (format, entry) => `${entry}.${format === "es" ? "js" : "cjs"}`,
},
chunkSizeWarningLimit: 5,
target: "es2016",
copyPublicDir: false,
rollupOptions: {
external: [
"react/jsx-runtime",
...Object.keys(peerDependencies),
...Object.keys(devDependencies),
],
output: {
exports: "named",
globals: {
react: "react",
"react-dom": "ReactDOM",
"react/jsx-runtime": "react/jsx-runtime",
},
preserveModules: true,
chunkFileNames: (info) => {
if (info.facadeModuleId) {
if (facadeModuleIdMap.has(info.facadeModuleId)) {
return `__[name]__.cjs`;
} else {
facadeModuleIdMap.set(info.facadeModuleId, true);
return `__[name]__.js`;
}
}
const cjs = info.exports.some((e) => e.length > 5);
return `__[name]__.${cjs ? "cjs" : "js"}`;
},
sourcemap: true,
},
plugins: [preserveDirectives()],
},
},
plugins: [
react(),
dtsPlugin({
entryRoot: "src",
noEmitOnError: true,
skipDiagnostics: true,
}),
entryPointsDtsPlugin(entryPoints),
],
});