-
Notifications
You must be signed in to change notification settings - Fork 0
/
mergedist.ts
30 lines (30 loc) · 1 KB
/
mergedist.ts
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
import fs from "fs";
async function main() {
let index = (await fs.promises.readFile("dist/index.html")).toString();
const workerre = /new Worker\("([^"]*)"\)/g;
let match: string[] | null = null;
match = workerre.exec(index);
while (match !== null) {
if (match[0] !== undefined && match[1] !== undefined) {
try {
let worker = (
await fs.promises.readFile("dist/" + match[1])
).toString();
let replace =
'new Worker(URL.createObjectURL(new Blob(["("+function(){' +
worker +
'}.toString()+")()"],{type:"text/jacascript"})))';
index =
index.slice(0, workerre.lastIndex - match[0].length) +
replace +
index.slice(workerre.lastIndex);
workerre.lastIndex -= match[0].length - replace.length;
} catch (err) {
console.error("替换 " + match[0] + " 错误:", err);
}
}
match = workerre.exec(index);
}
await fs.promises.writeFile("dist/SixProfiler.html", index);
}
main();