File tree Expand file tree Collapse file tree 2 files changed +35
-7
lines changed
Expand file tree Collapse file tree 2 files changed +35
-7
lines changed Original file line number Diff line number Diff line change 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+ ```
Original file line number Diff line number Diff line change 1- import fs from 'fs' ;
2- import { resolve } from 'path' ;
1+ const fs = require ( 'fs' ) ;
2+ const { resolve } = require ( 'path' ) ;
33
44let 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+ } ;
You can’t perform that action at this time.
0 commit comments