-
Notifications
You must be signed in to change notification settings - Fork 0
/
vite.config.ts
53 lines (51 loc) · 1.17 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
import fs from "fs";
import path from "path";
import { defineConfig, type Plugin } from "vite";
import { resolve } from "path";
import dts from "vite-plugin-dts";
export default defineConfig({
plugins: [
dts({
insertTypesEntry: true,
}),
mdts(),
],
resolve: {},
build: {
lib: {
entry: {
main: resolve(__dirname, "src/main.ts"),
"vite-plugin": resolve(__dirname, "src/vite-plugin.ts"),
},
name: "simple-worker-vite",
formats: ["es", "cjs"],
},
minify: false,
rollupOptions: {
external: ["vite", "esbuild", "path", "fs"],
output: {
globals: {},
},
},
},
});
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);
}
}
},
};
}