workerize-loader
workerize-loader copied to clipboard
Fails when a depedency (module) requires a webpack "external" module
Awesome library! I've just found an edge case when workerizing a module that depends on a webpack external.
In my webpack config i have:
module.exports = {
// ...
externals: {
'config': JSON.stringify(config),
},
// ...
}
and in my worker module I have:
import * as config from 'config';
I'm using typescript in case that matters.
Here's the compilation error from webpack:
Module not found: Error: Can't resolve 'config' in '/directory/src'
@ ./src/MyWorker.ts 1:0-33
This is likely an issue with Webpack not passing externals to child Compiler instances.
is there any solution for this case? in electron, worker should have the same externals with the renderer
If someone wants to open a PR that copies compiler.options.external to the ChildCompiler instance that should fix the Webpack error here.
Personally I'm not sure externals in the Worker compiler actually make sense: any values declared as external are unlikely to be available in the Worker context. Generally they're values defined by other scripts on the main thread, and those aren't automatically run in a Worker too.
Perhaps I'm not thinking about this correctly though, if anyone has a bit more detail on what they're wanting this for I'm all ears!