Feature parity with worker-loader
#14198
-
👋 ! I'm wondering: what are the plans around supporting From my understanding, there are two main features missing:
Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 25 replies
-
I don't think we need this in 2021, anyway it is possible to using
You can move worker to own entry and setup publicPath or use multi compiler mode |
Beta Was this translation helpful? Give feedback.
-
How can I help? Example required for
|
Beta Was this translation helpful? Give feedback.
-
Here is a good explanation on the problem and potential solution. edit - |
Beta Was this translation helpful? Give feedback.
-
I see two things here:
Yes, inline loader can solve both them, but do you real need support old browsers? Anyway I provide two solutions here:
webpack.config.js // ...
{
resourceQuery: /raw/,
// Note you can use `asset/inline` for very old browser supports, but you will increase bundle size
type: 'asset/resource',
use: [
{
loader: "babel-loader",
options: {}
},
// Canb e removed if you don't have ts
{
loader: "ts-loader",
options: {}
}
]
}
// ... in source code just crreate const createWorker = () => {
if (process.env.NODE_ENV === 'development') {
const data = new URL('./worker?raw', import.meta.url);
// Can polyfill it, if you don't want, use something old to download file
fetch(data)
.then(response => response.blob())
.then((blob) => {
const objectURL = URL.createObjectURL(blob);
new Worker(objectURL);
URL.revokeObjectURL(objectURL);
})
} else {
new Worker(new URL('./worker', import.meta.url))
}
} Technique from above can be improved for production usage, for example:
Also you can always use Anyway feel free to feedback |
Beta Was this translation helpful? Give feedback.
-
In case someone find it interesting, I found another solution to the CORS issue: #14648 (comment) |
Beta Was this translation helpful? Give feedback.
I don't think we need this in 2021, anyway it is possible to using
assets/inline
You can move worker to own entry and setup publicPath or use multi compiler mode