Open
Description
According to the docs:
By default, WorkerPlugin doesn't run any of your configured Webpack plugins when bundling worker code
However, this doesn't seem to be true. Consider the following partial config:
plugins: [
new webpack.DefinePlugin({
_A_: JSON.stringify('this text should never appear in worker'),
}),
new WorkerPlugin({
plugins: [
new webpack.DefinePlugin({
_B_: JSON.stringify('this text should definitely appear in worker'),
}),
],
}),
]
Given the documentation, the expectation would be that:
- In the worker:
_A_
is untouched_B_
is replaced with'this text should definitely appear in worker'
- Everywhere else:
_A_
is replaced with'this text should never appear in worker'
_B_
is untouched
However, in all code _A_
is replaced with 'this text should never appear in worker'
and _B_
is untouched.
This is apparently because the DefinePlugin
is using hooks that are copied into the child compiler created by WorkerPlugin
(see createChildCompiler()
).
For background, my actual use case is to use ProvidesPlugin (not DefinePlugin) to replace a free variable with a different implementation (module) in workers vs elsewhere.