File tree Expand file tree Collapse file tree 2 files changed +20
-1
lines changed
Expand file tree Collapse file tree 2 files changed +20
-1
lines changed Original file line number Diff line number Diff line change @@ -9,6 +9,25 @@ import { minifyCSS } from "./minifyCSS.js";
99const bookmarkletPlugin = options => ( {
1010 name : 'bookmarkletPlugin' ,
1111 setup ( build ) {
12+ build . onLoad ( { filter : / \. ( t s x | j s ) $ / } , async args => {
13+ let code = await fs . promises . readFile ( args . path , 'utf8' ) ;
14+
15+ const cssRegex = / c s s ` ( [ ^ ` ] + ) ` / g;
16+ let match ;
17+ let newCode = code ;
18+
19+ while ( ( match = cssRegex . exec ( code ) ) !== null ) {
20+ const originalCSS = match [ 1 ] ;
21+ const minifiedCSS = minifyCSS ( originalCSS ) ;
22+ newCode = newCode . replace ( originalCSS , minifiedCSS ) ;
23+ }
24+
25+ return {
26+ loader : 'tsx' ,
27+ contents : newCode ,
28+ } ;
29+ } ) ;
30+
1231 build . onEnd ( async ( result ) => {
1332 const { outputFiles } = result ;
1433 if ( ! outputFiles ) return ;
Original file line number Diff line number Diff line change 11{
22 "name" : " color-contrast-bookmarklet" ,
3- "version" : " 0.2.0 " ,
3+ "version" : " 0.2.1 " ,
44 "description" : " color contrast checker bookmarklet" ,
55 "main" : " dist/bookmarklet.js" ,
66 "scripts" : {
You can’t perform that action at this time.
0 commit comments