| 1 |
import { readFileSync, writeFileSync } from "fs"; |
| 2 |
import { basename, resolve } from "path"; |
| 3 |
|
| 4 |
export function inlineWebworker(filename, modulename, asDataUrl = true) { |
| 5 |
const inputFile = resolve("./dist", `__compiled.${filename}`); |
| 6 |
writeFileSync( |
| 7 |
`./dist/__compiled.${filename.replace(/\.js$/g, ".inline.js")}`, |
| 8 |
asDataUrl |
| 9 |
? `goog.provide("${modulename}"); |
| 10 |
goog.scope(function () { |
| 11 |
${modulename} = () => "data:application/javascript;base64,${readFileSync(inputFile, { |
| 12 |
encoding: "base64", |
| 13 |
})}"; |
| 14 |
}) |
| 15 |
` |
| 16 |
: `goog.provide("${modulename}"); |
| 17 |
goog.scope(function () { |
| 18 |
${modulename} = () => (window.URL || window.webkitURL).createObjectURL(new Blob([${JSON.stringify( |
| 19 |
readFileSync(inputFile).toString("utf8"), |
| 20 |
)}])); |
| 21 |
})`, |
| 22 |
); |
| 23 |
} |