Skip to content

Commit 1fec59f

Browse files
committed
Bugfix: reenable minify of css for bookmarklet size
1 parent 6fffd04 commit 1fec59f

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

esbuild.mjs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,25 @@ import { minifyCSS } from "./minifyCSS.js";
99
const bookmarkletPlugin = options => ({
1010
name: 'bookmarkletPlugin',
1111
setup(build) {
12+
build.onLoad({ filter: /\.(tsx|js)$/ }, async args => {
13+
let code = await fs.promises.readFile(args.path, 'utf8');
14+
15+
const cssRegex = /css`([^`]+)`/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;

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
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": {

0 commit comments

Comments
 (0)