-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathvite.config.ts
More file actions
54 lines (52 loc) · 1.29 KB
/
vite.config.ts
File metadata and controls
54 lines (52 loc) · 1.29 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
import { execSync } from "node:child_process";
import { defineConfig } from "vite";
function modulePath(format: string, path: string) {
return (format === "es" ? "esm" : "cjs") + "/" + path;
}
export default defineConfig({
build: {
target: ["es2021", "esnext"],
outDir: "dist",
lib: {
entry: "src/index.ts",
formats: ["es", "cjs"],
fileName: (format, name) => modulePath(format, `${name}.js`),
},
sourcemap: true,
rollupOptions: {
output: { preserveModules: true },
},
minify: false,
},
plugins: [
{
name: "emit-package-json",
generateBundle({ format }) {
this.emitFile({
type: "asset",
fileName: modulePath(format, "package.json"),
source: JSON.stringify({
type: format === "es" ? "module" : "commonjs",
sideEffects: false,
}),
});
},
},
{
name: "emit-types",
closeBundle() {
execSync([
"tsc",
"--rootDir ./src",
"--emitDeclarationOnly",
"--declaration",
"--declarationMap",
"--declarationDir ./dist/types",
].join(" "));
console.log(
`\x1b[32m✓\x1b[0m declaration files emitted to ./dist/types.`,
);
},
},
],
});