11const fs = require ( 'fs' ) ;
22const { resolve } = require ( 'path' ) ;
3+ const minimatch = require ( 'minimatch' ) ;
34
45let viteConfig ;
56
6- module . exports = function ( ) {
7+ module . exports = function ( options = { } ) {
78 return {
89 name : 'lib-css' ,
910 apply : 'build' ,
1011 enforce : 'post' ,
1112
12- configResolved ( resolvedConfig ) {
13+ configResolved ( resolvedConfig ) {
1314 viteConfig = resolvedConfig ;
1415 } ,
1516
16- writeBundle ( option , bundle ) {
17+ writeBundle ( option , bundle ) {
1718 if ( ! viteConfig . build || ! viteConfig . build . lib ) {
1819 // only for lib build
19- console . warn ( 'vite-plugin-libcss only works in lib mode.' )
20+ console . warn ( 'vite-plugin-libcss only works in lib mode.' ) ;
2021 return ;
2122 }
2223 if ( option . format !== 'es' ) {
@@ -33,6 +34,14 @@ module.exports = function () {
3334 // only for entry
3435 continue ;
3536 }
37+ if ( options . include && ! minimatch ( file , options . include ) ) {
38+ // check if the file matches the include pattern
39+ continue ;
40+ }
41+ if ( options . exclude && minimatch ( file , options . exclude ) ) {
42+ // check if the file matches the exclude pattern
43+ continue ;
44+ }
3645 const outDir = viteConfig . build . outDir || 'dist' ;
3746 const filePath = resolve ( viteConfig . root , outDir , file ) ;
3847 const data = fs . readFileSync ( filePath , {
0 commit comments