11import { defineConfig } from "vite"
2- import { resolve } from "path"
2+ import { extname , relative , resolve } from "path"
3+ import { fileURLToPath } from "node:url"
4+ import glob from "glob"
35import react from "@vitejs/plugin-react-swc"
46import dts from "vite-plugin-dts"
57
@@ -13,6 +15,25 @@ export default defineConfig({
1315 } ,
1416 rollupOptions : {
1517 external : [ "react" , "react/jsx-runtime" ] ,
18+ input : Object . fromEntries (
19+ // https://rollupjs.org/configuration-options/#input
20+ glob . sync ( "lib/**/*.{ts,tsx}" ) . map ( ( file ) => [
21+ // 1. The name of the entry point
22+ // lib/nested/foo.js becomes nested/foo
23+ relative ( "lib" , file . slice ( 0 , file . length - extname ( file ) . length ) ) ,
24+ // 2. The absolute path to the entry file
25+ // lib/nested/foo.ts becomes /project/lib/nested/foo.ts
26+ fileURLToPath ( new URL ( file , import . meta. url ) ) ,
27+ ] )
28+ ) ,
29+ output : {
30+ // assetFileNames: '[name][extname]',
31+ assetFileNames : ( assetInfo ) => {
32+ const assetName = assetInfo . name ?. split ( "." ) . at ( 0 )
33+ return `${ assetName === "style" ? "index" : "[name]" } [extname]`
34+ } ,
35+ entryFileNames : "[name].js" ,
36+ } ,
1637 } ,
1738 } ,
1839} )
0 commit comments