-
Notifications
You must be signed in to change notification settings - Fork 2
/
vite.config.ts
51 lines (49 loc) · 1.23 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 fs from "fs";
import path from "path";
import { defineConfig, type Plugin } from "vite";
import vue from "@vitejs/plugin-vue";
import dts from "vite-plugin-dts";
export default defineConfig({
plugins: [vue(), dts({ insertTypesEntry: true, rollupTypes: true }), mdts()],
build: {
lib: {
entry: {
main: path.resolve(__dirname, "lib/main.ts"),
"component-vue3": path.resolve(__dirname, "components/vue3/index.ts"),
},
name: "Graphly D3",
formats: ["es", "cjs"]
},
minify: false,
rollupOptions: {
external: ["d3", "ajv", "vue"],
output: {
globals: {
d3: "d3",
ajv: "ajv",
vue: "vue",
},
},
},
},
});
function mdts(): Plugin {
let distPath: string;
return {
name: "vite:dmts",
configResolved(getResolvedConfig) {
const resolvedConfig = getResolvedConfig;
distPath = path.join(resolvedConfig.root, resolvedConfig.build.outDir, resolvedConfig.base);
},
writeBundle() {
const files = fs.readdirSync(distPath);
for (const file of files) {
if (file.endsWith(".d.ts")) {
const filePath = path.join(distPath, file);
const content = fs.readFileSync(filePath, "utf-8");
fs.writeFileSync(filePath.replace(".d.ts", ".d.mts"), content);
}
}
},
};
}