-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvite.config.js
More file actions
84 lines (82 loc) · 2.32 KB
/
Copy pathvite.config.js
File metadata and controls
84 lines (82 loc) · 2.32 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import { defineConfig } from "vite";
import { svelte } from "@sveltejs/vite-plugin-svelte";
import { resolve } from "path";
import dts from "vite-plugin-dts";
import { copyFileSync, mkdirSync } from "fs";
export default defineConfig(({ mode }) => {
const isLibraryBuild =
mode === "production" || process.env.BUILD_MODE === "library";
if (isLibraryBuild) {
// Library build configuration
return {
plugins: [
svelte({
compilerOptions: {
customElement: true,
},
}),
dts({
insertTypesEntry: true,
outDir: "dist",
include: ["src/**/*.ts", "src/**/*.svelte"],
exclude: ["src/**/*.test.*", "docs/**/*", "test-app/**/*"],
}),
// Custom plugin to copy built files to docs/dist/
{
name: "copy-to-docs",
writeBundle() {
// Small delay to ensure files are fully written before copying
setTimeout(() => {
try {
mkdirSync("./docs/dist", { recursive: true });
copyFileSync(
"./dist/terminal-session.es.js",
"./docs/dist/terminal-session.es.js"
);
copyFileSync(
"./dist/terminal-session.umd.js",
"./docs/dist/terminal-session.umd.js"
);
console.log("✅ Copied build files to docs/dist/");
} catch (error) {
console.warn(
"⚠️ Failed to copy files to docs/dist/:",
error.message
);
}
}, 100);
},
},
],
build: {
outDir: "dist",
lib: {
entry: resolve(__dirname, "src/main.ts"),
name: "TerminalSession",
fileName: (format) => `terminal-session.${format}.js`,
},
rollupOptions: {
// Bundle everything for standalone web component
output: {
// No globals needed when everything is bundled
},
},
},
};
} else {
// Dev server configuration
return {
root: "docs",
plugins: [
svelte({
compilerOptions: {
customElement: true,
},
}),
],
server: {
open: true,
},
};
}
});