1- import fs from 'fs' ;
2- import path from 'path' ;
3- import process from 'process' ;
1+ import fs from 'node: fs' ;
2+ import { resolve as resolvePath } from 'node: path' ;
3+ import process from 'node: process' ;
44import { defineConfig } from 'vite' ;
55import minifyHTML from 'rollup-plugin-html-literals' ;
66import dts from 'vite-plugin-dts' ;
77import { globSync } from 'glob' ;
88
9- const packageFile = JSON . parse ( fs . readFileSync ( new URL ( './package.json' , import . meta . url ) ) as any ) ;
10- const resolve = rel => path . resolve ( process . cwd ( ) , rel ) ;
9+ const getAbsolutePath = ( file : string ) => resolvePath ( process . cwd ( ) , file ) ;
10+ const packageFile = JSON . parse ( fs . readFileSync ( getAbsolutePath ( './package.json' ) , 'utf-8' ) ) ;
1111const index = process . argv . findIndex ( i => i === '--outDir' ) + 1 ;
1212const dist = ( p = '' ) => `${ index ? process . argv [ index ] : './dist' } /${ p } ` ;
13+ const prod = process . env . NODE_ENV === 'production' ;
1314
14- export default defineConfig ( env => {
15- const mode = env . mode as 'production' | 'watch' | 'test' | 'development' ;
16-
15+ export default defineConfig ( ( { mode } ) => {
1716 return {
1817 resolve : {
1918 alias : {
20- 'lit-library-starter' : resolve ( './src' )
19+ 'lit-library-starter' : getAbsolutePath ( './src' )
2120 }
2221 } ,
2322 plugins : [
2423 {
2524 ...dts ( {
26- root : resolve ( '.' ) ,
27- entryRoot : resolve ( './src' ) ,
28- outDir : dist ( ) ,
29- exclude : [ '**/*.test.ts' , '**/*.examples.ts' ]
25+ root : getAbsolutePath ( '.' ) ,
26+ entryRoot : getAbsolutePath ( './src' ) ,
27+ exclude : [ '**/*.test.ts' , '**/*.test.*.ts' , '**/*.examples.ts' ]
3028 } ) ,
3129 enforce : 'pre'
3230 }
3331 ] ,
3432 build : {
33+ reportCompressedSize : false ,
3534 cssCodeSplit : true ,
3635 minify : true ,
3736 watch : mode === 'watch' ? { } : undefined ,
3837 outDir : dist ( ) ,
39- emptyOutDir : false ,
40- sourcemap : true ,
38+ emptyOutDir : true ,
39+ sourcemap : prod ,
4140 target : 'esnext' ,
4241 lib : {
43- entry : {
44- index : resolve ( './src/index.ts' ) ,
45- ... globSync ( './src/**/define .ts' ) . reduce ( ( p , i ) => {
46- // all component entrypoints
47- return { ...p , [ i . replace ( ' src/' , '' ) . replace ( '. ts', '' ) ] : resolve ( i ) } ;
48- } , { } )
49- }
42+ entry : Object . fromEntries (
43+ [
44+ './src/index .ts' ,
45+ ... globSync ( './src/**/index.ts' , { ignore : [ './src/index.ts' ] } ) ,
46+ ...globSync ( './ src/**/define. ts')
47+ ] . map ( file => [ file . replace ( / ^ \. ? \/ ? s r c \/ / , '' ) . replace ( / \. t s $ / , '' ) , getAbsolutePath ( file ) ] )
48+ )
5049 } ,
5150 rolldownOptions : {
52- treeshake : false ,
5351 preserveEntrySignatures : 'strict' ,
5452 external : [
5553 ...Object . keys ( packageFile . dependencies || { } ) ,
@@ -64,7 +62,7 @@ export default defineConfig(env => {
6462 entryFileNames : '[name].js'
6563 }
6664 ] ,
67- plugins : [ mode === 'production' ? minifyHTML ( ) : false ]
65+ plugins : [ prod ? minifyHTML ( ) : false ]
6866 }
6967 }
7068 } ;
0 commit comments