mirror of
https://github.com/arcodange-org/mediabunny.git
synced 2026-09-27 02:43:48 +02:00
Make worker_threads dynamic imports direct and keep them in the bundle (externalized), & mark them as ignored for browser builds (fixes #306)
This commit is contained in:
@@ -18,6 +18,9 @@
|
||||
"dist",
|
||||
"src"
|
||||
],
|
||||
"browser": {
|
||||
"worker_threads": false
|
||||
},
|
||||
"sideEffects": false,
|
||||
"license": "MPL-2.0",
|
||||
"repository": {
|
||||
|
||||
@@ -18,6 +18,9 @@
|
||||
"dist",
|
||||
"src"
|
||||
],
|
||||
"browser": {
|
||||
"worker_threads": false
|
||||
},
|
||||
"sideEffects": false,
|
||||
"license": "MPL-2.0",
|
||||
"repository": {
|
||||
|
||||
@@ -39,11 +39,10 @@ export default async function inlineWorker(scriptText) {
|
||||
// Node, Bun (Bun's Worker is flaky, worker_threads works much better)
|
||||
|
||||
let Worker;
|
||||
const workerModule = 'node:worker_threads';
|
||||
try {
|
||||
Worker = (await import(workerModule)).Worker;
|
||||
Worker = (await import('worker_threads')).Worker;
|
||||
} catch {
|
||||
Worker = require(workerModule).Worker;
|
||||
Worker = require('worker_threads').Worker;
|
||||
}
|
||||
|
||||
const worker = new Worker(scriptText, { eval: true });
|
||||
@@ -56,6 +55,9 @@ export default async function inlineWorker(scriptText) {
|
||||
build.onResolve({ filter: /^__inline-worker$/ }, ({ path }) => {
|
||||
return { path, namespace: 'inline-worker' };
|
||||
});
|
||||
build.onResolve({ filter: /^worker_threads$/ }, ({ path }) => {
|
||||
return { path, external: true }; // Keep it in the bundle
|
||||
});
|
||||
build.onLoad({ filter: /.*/, namespace: 'inline-worker' }, () => {
|
||||
return { contents: inlineWorkerFunctionCode, loader: 'js' };
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user