import { defineConfig } from "vite"; import vue from "@vitejs/plugin-vue"; import dts from "vite-plugin-dts"; export default defineConfig({ plugins: [ vue(), dts({ tsconfigPath: "../../tsconfig.json", include: ["src"], entryRoot: "src", aliasesExclude: ["@heroui-vue/styles"], // ESM consumers using NodeNext require extensions even in declarations. // Foo.vue.js resolves Foo.vue.d.ts; plain Foo.vue only works in bundler mode. beforeWriteFile(filePath, content) { return { filePath, content: content.replace( /((?:from\s+|import\s*\(\s*)["'])(\.{1,2}\/[^"']+)(["'])/g, (_match, prefix: string, path: string, suffix: string) => { // TS may infer a barrel import such as import('../..'). // Appending '.js' would produce the invalid path '../...js'. const target = /(?:^|\/)\.{1,2}\/?$/.test(path) ? path.replace(/\/$/, "") + "/index.js" : /\.(?:[cm]?js|json|css)$/.test(path) ? path : /\.ts$/.test(path) ? path.slice(0, -3) + ".js" : path + ".js"; return prefix + target + suffix; }, ), }; }, }), ], build: { lib: { entry: "src/index.ts", formats: ["es"], fileName: "index" }, rollupOptions: { external: [ "vue", "reka-ui", "@heroui-vue/styles", "@vueuse/core", "@internationalized/date", ], }, }, });