Skip to content

Commit 8c18928

Browse files
committed
fix: import
1 parent 3391225 commit 8c18928

File tree

2 files changed

+35
-7
lines changed

2 files changed

+35
-7
lines changed

README.md

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,31 @@
11
# vite-plugin-libcss
22

3-
todo
3+
This plugin will inject css into bundled js file using `import` statement like this:
4+
5+
```js
6+
// bundled js file, with import css at top (if any)
7+
import './style.css';
8+
// rest of the file
9+
// ...
10+
```
11+
12+
Install:
13+
14+
```
15+
npm i vite-plugin-libcss -D
16+
```
17+
18+
Usage:
19+
20+
```js
21+
// vite.config.js
22+
import libCss from 'vite-plugin-libcss';
23+
24+
// https://vitejs.dev/config/
25+
export default defineConfig({
26+
plugins: [
27+
// any other plugins
28+
libCss()
29+
],
30+
});
31+
```

index.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1-
import fs from 'fs';
2-
import { resolve } from 'path';
1+
const fs = require('fs');
2+
const { resolve } = require('path');
33

44
let viteConfig;
55

6-
export default function() {
6+
module.exports = function () {
77
return {
88
name: 'lib-inject-css',
99
apply: 'build',
1010
enforce: 'post',
1111

12-
configResolved(resolvedConfig) {
12+
configResolved (resolvedConfig) {
1313
viteConfig = resolvedConfig;
1414
},
1515

16-
writeBundle(_, bundle) {
16+
writeBundle (_, bundle) {
1717
const files = Object.keys(bundle);
1818
const cssFile = files.find((v) => v.endsWith('.css'));
1919
if (!cssFile) {
@@ -32,4 +32,4 @@ export default function() {
3232
}
3333
},
3434
};
35-
}
35+
};

0 commit comments

Comments
 (0)