import { resolve } from 'node:path' // import { fileURLToPath, URL } from 'node:url' import vue from '@vitejs/plugin-vue' import { defineConfig } from 'vite' import dts from 'vite-plugin-dts' import tsconfigPaths from 'vite-tsconfig-paths' const indexDir = resolve(import.meta.dirname, 'src') export default defineConfig({ plugins: [ tsconfigPaths({ root: indexDir, }), vue(), dts({ entryRoot: indexDir, copyDtsFiles: true, }), ], resolve: { alias: { '@bagelink/vue': indexDir, }, }, // experimental: { enableNativePlugin: true }, esbuild: { // Strip console.* from the published build; thrown errors are unaffected. drop: ['console', 'debugger'], }, build: { minify: 'esbuild', // Arrow functions should preserve scope even with minification lib: { entry: resolve(indexDir, 'index.ts'), formats: ['es', 'cjs'], fileName: (module, entry) => `${entry}.${module === 'es' ? 'mjs' : module}`, cssFileName: 'style', }, rollupOptions: { // external modules won't be bundled into your library external: ['vue', 'vue-router', 'fsevents'], // not every external has a global output: { // disable warning on src/index.ts using both default and named export exports: 'named', // Provide global variables to use in the UMD build // for externalized deps (not useful if 'umd' is not in lib.formats) globals: { vue: 'Vue', }, }, }, emptyOutDir: true, // types are emitted by vite-plugin-dts in this same build; stale files must not survive }, })