Files
copilotkit__copilotkit/packages/vue/vite.config.ts
Benjamin Taylor 0d551822dd fix(vue): externalize @copilotkit/web-components in the library build [ENT-1051]
The drawer wrapper loads the Lit `<copilotkit-threads-drawer>` element via a
client-only dynamic import of @copilotkit/web-components/threads-drawer. That
package was not in rollupOptions.external, so vite bundled the whole element +
a second copy of lit-html inline into the vue dist (a ~1MB chunk).

Under Vite/Nuxt consumers this inlined duplicate lit-html produced a fatal
"Identifier 'h' has already been declared" parse error (h = lit-html's minified
`html`), and it also risks double custom-element registration. Externalizing it
(as @copilotkit/core, @copilotkit/shared, @copilotkit/web-inspector already are)
makes the dynamic import resolve to the single real package at runtime.

Verified live: the redesigned drawer now renders + operates in the Nuxt vue demo
(licensed, real threads, kebab Archive/Delete, top-layer delete dialog, mobile
off-canvas + sidebar-glyph close). Vue wrapper unit tests: 29/29 pass.
2026-07-06 17:14:40 -05:00

57 lines
1.6 KiB
TypeScript

import { resolve } from "node:path";
import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
export default defineConfig({
plugins: [vue()],
resolve: {
alias: {
"@": resolve(__dirname, "./src"),
},
},
build: {
lib: {
entry: {
index: resolve(__dirname, "src/index.ts"),
"v2/index": resolve(__dirname, "src/v2/index.ts"),
},
name: "CopilotKitVue",
formats: ["es", "cjs"],
fileName: (format, entryName) =>
format === "es" ? `${entryName}.mjs` : `${entryName}.cjs`,
},
rollupOptions: {
external: [
"vue",
"@a2ui/web_core",
"@a2ui/web_core/v0_9",
"@a2ui/web_core/v0_9/basic_catalog",
"@ag-ui/client",
"@ag-ui/core",
"@copilotkit/core",
"@copilotkit/shared",
"@copilotkit/web-inspector",
// Keep @copilotkit/web-components (the Lit drawer element) + its subpaths
// external. It's a runtime dependency loaded via the drawer wrapper's
// client-only dynamic import; bundling it inline would ship a duplicate
// element + a second copy of lit-html, which breaks Vite/Nuxt consumers
// (duplicate top-level lit binding → "Identifier 'h' has already been
// declared") and risks double custom-element registration.
/^@copilotkit\/web-components(\/.*)?$/,
"@jetbrains/websandbox",
"streamdown-vue",
"katex",
"lucide-vue-next",
"zod",
"zod-to-json-schema",
],
output: {
globals: { vue: "Vue" },
},
},
outDir: "dist",
emptyOutDir: true,
sourcemap: true,
},
});