-
Notifications
You must be signed in to change notification settings - Fork 14
/
minify.js
40 lines (35 loc) · 1.15 KB
/
minify.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import { readFile, writeFile } from "node:fs/promises"
const classnamesPathname = "./dist/classnames.js"
const componentsPathname = "./dist/react.js"
const originalClassnames = await readFile(classnamesPathname, "utf8")
const originalComponents = await readFile(componentsPathname, "utf8")
const minifiedClassnames = originalClassnames
.replace(/\s+/g, " ")
.replace(/ => /g, "=>")
.replace(/ \./g, ".")
.replace(/, /g, ",")
.replace(/ \? /g, "?")
.replace(/ \}/g, "}")
.replace(/\{ /g, "{")
.replace(/ : /g, ":")
.replace(/ \=/g, "=")
.replace(/\= /g, "=")
.replace(/; /g, ";")
.replace(/ &&/g, "&&")
.replace(/&& /g, "&&")
.replace(/if \(/g, "if(")
.replace(/\) return/g, ")return")
const minifiedComponents = originalComponents
.replace(/\{\n/g, "{")
.replace(/,\s+/g, ",")
.replace(/\s=>\s/g, "=>")
.replace(/\{\s+/g, "{")
.replace(/\s+:/g, ":")
.replace(/:\s+/g, ":")
.replace(/\s\=/g, "=")
.replace(/\=\s/g, "=")
.replace(/\s\?\s/g, "?")
.replace(/\s\}/g, "}")
.replace(/children:children/g, "children")
await writeFile(classnamesPathname, minifiedClassnames)
await writeFile(componentsPathname, minifiedComponents)