Closed FallingSnow closed 10 months ago
You don't need to use client (and maybe hot, but it depends on your goals), please use:
module.exports = [
{
entry: "./src/index.js",
mode: "development",
output: {
path: path.resolve(__dirname, "./dist"),
filename: "main.js",
},
},
{
entry: "./src/audio.js",
mode: "development",
target: "webworker",
output: {
publicPath: "",
path: path.resolve(__dirname, "./dist"),
filename: "audio.bundle.js",
},
devServer: {
client: false,
hot: false,
}
}
];
i.e. you disable client and hot on your audio worklet.
But there is a small problem, you can't use dev server options for the first compilation, but we are working on it https://github.com/webpack/webpack-cli/pull/4045 and release will be soon, after cut a release you can do such things:
module.exports = [
{
entry: "./src/index.js",
mode: "development",
output: {
path: path.resolve(__dirname, "./dist"),
filename: "main.js",
},
devServer: {
// Your options for dev server
}
},
{
entry: "./src/audio.js",
mode: "development",
target: "webworker",
output: {
publicPath: "",
path: path.resolve(__dirname, "./dist"),
filename: "audio.bundle.js",
},
devServer: false
}
];
Sorry for delay and feel free to feedback
Bug report
I'm running into an issue while using web audio workers. It seems there isn't a target that uses globalThis instead of self. The code causing the issue is below. https://github.com/webpack/webpack-dev-server/blob/540c43852ea33f9cb18820e1cef05d5ddb86cc3e/client-src/index.js#L149-L151
AudioWorkletGlobalScope
defines the only scope available to a web audio worker.Actual Behavior
I have tried changing the globalObject in my webpack config but it seems webpack-dev-server doesn't use this option.
I also tried setting the target to
webworker
but the error persists.Expected Behavior
Either code generated should use the globalObject set by webpack or default to
globalThis
. Or theself
code portions should not be included in web worker output.How Do We Reproduce?
Create a audio worker using code compiled by webpack-dev-server and register it using the same name as below; "realtime-audio". The audio worker file should be complied to a separate bundle. See https://developer.mozilla.org/en-US/docs/Web/API/AudioWorkletNode for another complete example.
audio.ts
main.ts
This should trigger the error.
Please paste the results of
npx webpack-cli info
here, and mention other relevant information