@@ -6,34 +6,63 @@ import react from "@vitejs/plugin-react-swc"
66import dts from "vite-plugin-dts"
77
88// https://vitejs.dev/config/
9- export default defineConfig ( {
10- plugins : [ react ( ) , dts ( { include : [ "lib" ] } ) ] ,
11- build : {
12- lib : {
13- entry : resolve ( __dirname , "lib/main.ts" ) ,
14- formats : [ "es" ] ,
15- } ,
16- rollupOptions : {
17- 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]`
9+ export default defineConfig ( ( { mode } ) => {
10+ if ( mode === "docs" ) {
11+ return {
12+ plugins : [ react ( ) , dts ( { exclude : [ "lib" ] } ) ] ,
13+ build : { outDir : "docs" } ,
14+ /* build: {
15+ rollupOptions: {
16+ external: ["react", "react/jsx-runtime"],
17+ input: resolve(__dirname, "index.html"),
18+ output: {
19+ dir: resolve(__dirname, "docs"),
20+ // assetFileNames: '[name][extname]',
21+ assetFileNames: (assetInfo) => {
22+ const assetName = assetInfo.name?.split(".").at(0)
23+ return `${assetName === "style" ? "index" : "[name]"}[extname]`
24+ },
25+ entryFileNames: "[name].js",
26+ },
27+ },
28+ },*/
29+ }
30+ }
31+ if ( mode === "production" ) {
32+ return {
33+ plugins : [ react ( ) , dts ( { include : [ "lib" ] } ) ] ,
34+ build : {
35+ lib : {
36+ entry : resolve ( __dirname , "lib/main.ts" ) ,
37+ formats : [ "es" ] ,
38+ } ,
39+ rollupOptions : {
40+ external : [ "react" , "react/jsx-runtime" ] ,
41+ input : Object . fromEntries (
42+ // https://rollupjs.org/configuration-options/#input
43+ glob . sync ( "lib/**/*.{ts,tsx}" ) . map ( ( file ) => [
44+ // 1. The name of the entry point
45+ // lib/nested/foo.js becomes nested/foo
46+ relative (
47+ "lib" ,
48+ file . slice ( 0 , file . length - extname ( file ) . length )
49+ ) ,
50+ // 2. The absolute path to the entry file
51+ // lib/nested/foo.ts becomes /project/lib/nested/foo.ts
52+ fileURLToPath ( new URL ( file , import . meta. url ) ) ,
53+ ] )
54+ ) ,
55+ output : {
56+ // assetFileNames: '[name][extname]',
57+ assetFileNames : ( assetInfo ) => {
58+ const assetName = assetInfo . name ?. split ( "." ) . at ( 0 )
59+ return `${ assetName === "style" ? "index" : "[name]" } [extname]`
60+ } ,
61+ entryFileNames : "[name].js" ,
62+ } ,
3463 } ,
35- entryFileNames : "[name].js" ,
3664 } ,
37- } ,
38- } ,
65+ }
66+ }
67+ return { }
3968} )
0 commit comments