-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvite.lib.config.ts
64 lines (59 loc) · 1.51 KB
/
vite.lib.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
import path from "path";
import { defineConfig } from "vite";
import react from "@vitejs/plugin-react";
import banner from "vite-plugin-banner";
import styleInject from "./plugins/style-inject";
import pkg from "./package.json";
const packageName = "editor";
const fileNames = {
es: `${packageName}.es.js`,
iife: `${packageName}.iife.js`,
umd: `${packageName}.umd.js`,
};
const getPackageNameCamelCase = () => {
try {
return packageName.replace(/-./g, (char) => char[1].toUpperCase());
} catch (err) {
throw new Error("Name property in package.json is missing.");
}
};
const pkgInfo = `/**
* name: ${pkg.name}
* version: ${pkg.version}
* description: ${pkg.description}
* author: ${pkg.author}
* homepage: ${pkg.homepage}
* repository: ${pkg.repository.url}
*/`;
module.exports = defineConfig({
base: "./",
build: {
outDir: "lib",
lib: {
entry: path.resolve(__dirname, "src/index.tsx"),
name: getPackageNameCamelCase(),
formats: ["es", "iife", "umd"],
fileName: (format) => fileNames[format],
},
rollupOptions: {
external: ["react", "react-dom"],
output: {
assetFileNames: `${packageName}.[ext]`,
globals: {
react: "React",
"react-dom": "ReactDOM",
},
exports: "named",
},
},
cssCodeSplit: true,
emptyOutDir: true,
assetsDir: "assets",
},
plugins: [react({}), banner(pkgInfo), styleInject()],
resolve: {
alias: {
"@/*": path.resolve(__dirname, "src"),
},
},
});