File tree Expand file tree Collapse file tree 2 files changed +15
-3
lines changed
Expand file tree Collapse file tree 2 files changed +15
-3
lines changed Original file line number Diff line number Diff line change @@ -30,4 +30,4 @@ export default defineConfig({
3030});
3131```
3232
33- Note that this plugin can only work with [ library-mode] ( https://vitejs.dev/guide/build.html#library-mode ) .
33+ Note that this plugin will only work with [ library-mode] ( https://vitejs.dev/guide/build.html#library-mode ) and es format build .
Original file line number Diff line number Diff line change @@ -8,17 +8,29 @@ module.exports = function () {
88 name : 'lib-css' ,
99 apply : 'build' ,
1010 enforce : 'post' ,
11+
1112 configResolved ( resolvedConfig ) {
1213 viteConfig = resolvedConfig ;
1314 } ,
14- writeBundle ( _ , bundle ) {
15+
16+ writeBundle ( option , bundle ) {
17+ if ( ! viteConfig . build || ! viteConfig . build . lib ) {
18+ // only for lib build
19+ console . warn ( 'vite-plugin-libcss only works in lib mode.' )
20+ return ;
21+ }
22+ if ( option . format !== 'es' ) {
23+ // only for es built
24+ return ;
25+ }
1526 const files = Object . keys ( bundle ) ;
1627 const cssFile = files . find ( ( v ) => v . endsWith ( '.css' ) ) ;
1728 if ( ! cssFile ) {
1829 return ;
1930 }
2031 for ( const file of files ) {
21- if ( ! file . endsWith ( '.js' ) ) {
32+ if ( ! bundle [ file ] . isEntry ) {
33+ // only for entry
2234 continue ;
2335 }
2436 const outDir = viteConfig . build . outDir || 'dist' ;
You can’t perform that action at this time.
0 commit comments