You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to follow the instructions to get blobs working.
Iusing the raw-loader appears to work, but I keep getting syntax errors like:
//line 1 of test.worker-thread.jsimport{expose}from"threads/worker";^^^^^^^^^^^^^^^^^> Error: Uncaught SyntaxError: Cannotuseimportstatementoutsideamodule(blob:http://localhost:8080/b583c876-110f-49cf-bfff-2b92254c93bc:1)
If I don't use blobs, everything works fine.
What I want to do is have the worker bundled in the webpack browser bundle. If there's an easier way to do that, please let me know.
If not, is there some example showing how to use the BlogWorker?
here is the related parts of my code. In Typescript, for an isomorphic library. FYI I am only using webpack to bundle an esm transpiled version of my code for browser. For node it runs the normal commonjs transpiled ts output.
Here is a webpack-based example, leveraging the raw-loader to inline the worker code. The worker code that we load using the raw-loader is the content of bundles that have been created by two previous webpack runs: one worker build targetting node.js, one for web browsers.
The idea is to run webpack once to bundle your worker, then run webpack once more to bundle the actual app, while the worker is spawned from the worker bundle (created by the first webpack run) using the raw-loader and a blob worker.
You load the worker's source code using the raw-loader, that's why you see the error. You need to build the worker before you build the app, so you can load the worker bundle using raw-loader.
Ideally you shouldn't have to run webpack twice, but you would have a special webpack loader that transparently builds the worker and imports the resulting bundle. For now you will have to do the double-webpack build, though.
I'm trying to follow the instructions to get blobs working.
Iusing the
raw-loader
appears to work, but I keep getting syntax errors like:If I don't use blobs, everything works fine.
What I want to do is have the worker bundled in the webpack browser bundle. If there's an easier way to do that, please let me know.
If not, is there some example showing how to use the BlogWorker?
here is the related parts of my code. In Typescript, for an isomorphic library. FYI I am only using webpack to bundle an esm transpiled version of my code for browser. For node it runs the normal commonjs transpiled ts output.
and the worker:
the full source code is available here: https://github.com/Novaleaf/xlib/blob/threadjs-blob-test/libraries/xlib/src/_main.ts
The text was updated successfully, but these errors were encountered: