| 43 | `; |
| 44 | |
| 45 | export default function inlineWebworker(options = {}) { |
| 46 | const filter = createFilter(options.include, options.exclude); |
| 47 | const dataUrl = options.dataUrl; |
| 48 | return { |
| 49 | name: "inline-webworker", |
| 50 | load(id) { |
| 51 | if (filter(id)) { |
| 52 | const filename = basename(id); |
| 53 | id = resolve("./dist", `__compiled.${filename}`); |
| 54 | return { |
| 55 | code: dataUrl |
| 56 | ? ` |
| 57 | export default () => "data:application/javascript;base64,${readFileSync(id, { |
| 58 | encoding: "base64", |
| 59 | })}"; |
| 60 | ` |
| 61 | : ` |
| 62 | export default () => (window.URL || window.webkitURL).createObjectURL(new Blob([${JSON.stringify( |
| 63 | readFileSync(id).toString("utf8"), |
| 64 | )}]));`, |
| 65 | map: { mappings: "" }, |
| 66 | }; |
| 67 | } |
| 68 | }, |
| 69 | }; |
| 70 | } |