-
Notifications
You must be signed in to change notification settings - Fork 43
Expand file tree
/
Copy pathvite.config.ts
More file actions
56 lines (53 loc) · 1.64 KB
/
Copy pathvite.config.ts
File metadata and controls
56 lines (53 loc) · 1.64 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
55
56
import { defineConfig } from "vite";
import dts from "vite-plugin-dts";
import path from "node:path";
import { viteStaticCopy } from "vite-plugin-static-copy";
import fs from "node:fs";
export default defineConfig({
build: {
lib: {
entry: path.resolve(import.meta.dirname, "src/index.ts"),
formats: ["es"],
fileName: () => "index.js",
},
rollupOptions: {
external: ["astro"],
},
},
plugins: [
dts({
afterBuild: () => {
const indexDtsPath = path.resolve(import.meta.dirname, "dist/index.d.ts");
if (fs.existsSync(indexDtsPath)) {
const currentContent = fs.readFileSync(indexDtsPath, "utf-8");
const referenceLine = `/// <reference path="./public.d.ts" />`;
if (!currentContent.includes(referenceLine)) {
const newContent = `${referenceLine}\n${currentContent}`;
fs.writeFileSync(indexDtsPath, newContent);
}
}
},
}),
viteStaticCopy({
targets: [
{
src: "src/live-preview/middleware.ts",
dest: "live-preview",
rename: { stripBase: true },
},
{ src: "src/dev-toolbar/toolbarApp.ts", dest: "dev-toolbar", rename: { stripBase: true } },
{
src: ["src/lib/client.ts"],
dest: "lib",
rename: { stripBase: true },
},
{ src: "src/public.d.ts", dest: ".", rename: { stripBase: true } },
{
src: ["src/components/**/*.astro"],
dest: "components",
rename: { stripBase: 2 }, // strip the `src/components` prefix, preserve any nesting below it
},
],
}),
],
});