-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathvite.config.ts
51 lines (50 loc) · 1.67 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
import react from "@vitejs/plugin-react";
import { defineConfig, configDefaults } from "vitest/config";
import dts from "vite-plugin-dts";
import renameNodeModules from "rollup-plugin-rename-node-modules";
// https://vitejs.dev/config/
export default defineConfig({
plugins: [react(), dts()],
build: {
target: "modules",
lib: {
entry: [
"src/lib/index.ts",
"src/lib/hooks/index.ts",
"src/lib/apis/index.ts",
"src/lib/components/index.ts",
],
name: "airstack-web-sdk",
formats: ["es"],
fileName: "[name]",
},
minify: false,
rollupOptions: {
external: ["react", "react-dom"],
output: {
// we need to set preserveModules to true, so vite will not bundle the library
// and will preserve the folder stucture of the library, so the library can be tree-shaken
preserveModules: true,
// build files from src/lib to the dist folder
preserveModulesRoot: "src/lib",
entryFileNames: ({ name: fileName }) => {
return `${fileName}.js`;
},
globals: {
react: "React",
"react-dom": "ReactDOM",
},
// when we use preserveModules, vite will create a node_modules folder in the dist folder
// the node_modules folder will contain all the dependencies of the library
// we need to rename the node_modules folder to something else, because npm publish will ignore the node_modules folder
plugins: [renameNodeModules("external")],
},
},
},
test: {
exclude: [...configDefaults.exclude],
environment: "jsdom",
globals: true,
setupFiles: ["./setupTests.js"],
},
});