Skip to content

Commit 76123b1

Browse files
committed
fix: only for lib mode and es format
1 parent 12d725a commit 76123b1

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff 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.

index.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff 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';

0 commit comments

Comments
 (0)