Struggling to implement web workers in my web app and encountering difficulties. The addition of a new entry to the webpack.config.js
file is not producing desired results.
Attempting to utilize the npm package named worker-loader
, however, facing challenges due to lack of proper examples on its usage. All efforts so far have been unsuccessful. Could someone provide a simple example demonstrating how to use it?
import Worker from "worker-loader!./Worker.js";
const myworker = new Worker();
myworker.postMessage(songs);
myworker.onmessage = function(Data) {
//do something
}
The contents of my webpack.config.js are as follows:
entry: __dirname + "/js/index.js",
output: {
path: __dirname + "/dist",
filename: "bundle.js"
},
{
module: {
rules: [
{
test: /\.worker\.js$/,
use: { loader: 'worker-loader' }
}
]
}
}
My server logs indicate the following error:
"GET /279b1e1fcb403131377a.worker.js HTTP/1.1" 404
Due to the location of my 279b1e1fcb403131377a.worker.js
file within /dist
, a 404 error is being triggered. How can I adjust the request path to target the content inside /dist
directory?