-
-
Notifications
You must be signed in to change notification settings - Fork 273
[Feature] support for ignoring modules #95
Comments
Could you try changing this line (L61) to - .createChildCompiler('worker', worker.options);
+ .createChildCompiler('worker', Object.assign({}, worker.options, this.options.externals)); and try if that works ? 🙃 |
Sadly it does not. Still have the above reported errors 😢 |
hmm... ok then I need to investigate this further 🙃 |
Would it be possible to spin a repo for reproduction ? |
It may take me a several days, but I'll try to put something together! |
Before creating a repo for reproduction, I wanted to do some investigation myself to see if I could find a way to add this (mostly because I've always wanted an excuse to learn more about how webpack loaders work). I learned a good bit, but I wanted to check some of my assumptions here and ask some questions. One odd thing that I saw was that when using the IIFE shown above to create an externals function, the
Is this maybe a quirk in the translation of my webpack config to the options that are made available to a given loader? I sidestepped this by specifying the externals entry instead as an object like so:
Which allowed the externals entry to be correctly represented in I then retried the above suggested fix, thinking that the null was maybe the cause for it not working, but I still got the same result. Upon inspection the config for the created child compiler came out as:
This seems a bit odd to me, because I assume that the child compiler options would be a similar structure to the root compiler options (with
which yielded the structure:
But even doing this, the result was still the same. This got me thinking about the child compiler: given that by default (no matter what options are passed to it in the Still, I'd think if this were the case then the This makes me think that this is either:
Am I thinking about this correctly? I've made a lot of assumptions that I'm just not sure about based on my |
Just threw together a minimal reproduction repo here: https://github.com/symbyte/worker-loader-externals |
@michael-ciniawsky Do you have any ideas on the stuff I mentioned above? |
Just ran into a case where this would be very helpful. I am integrating a Worker into the background of a Chrome Extension, and am using a HMR library with a dependency on |
I was hitting this exact same problem in a custom loader I was writing. I think it's due to the fact that although the child compiler does inherit all its parent's options, it appears that not all of the parent's plugins are inherited. From digging around a bit, it looks in a normal compilation the I've worked around this in my loader by manually adding the if (worker.compiler.options.externals) {
worker.compiler.apply(new ExternalsPlugin(
worker.compiler.options.output.libraryTarget,
worker.compiler.options.externals
));
} …this seems to fix the problem for my use case. @michael-ciniawsky it looks like there's quite a lot of other stuff in the |
@symbyte I appreciate you filing this issue. I'm in a position where I need to use the 'sqlite3' module in a Web Worker script. I followed along the posts of you and timkendrick pretty well, but wasn't able to get anything functional. Has there been any workaround established in the meanwhile? I'm having trouble understanding exactly the root of this issue, but I thought this would be feasible. |
@nschwan94 I might well be wrong, but I suspect sqlite relies on compiled native modules and therefore won't be able to be run outside a Node.js environment. If that's the case you won't be able to run it in the browser at all, never mind in a web worker… |
@timkendrick thanks for the reply. I'm attempting this in an Electron app. The thought was to launch a few Web Workers that could each read/write from/to separate sqlite databases. |
Hi, any chance of getting this fixed. I think this is a bug really. |
We are using the following function in order to keep certain modules (generally platform specific dependancies like sqlite3) from being bundled into our webpack bundle which will cause any module in the array to be manually required instead:
When loading a worker that uses any of those modules directly or uses a module that uses them, webpack attempts to trace back these require statements instead of ignoring them as the above config dictates leading to build errors like:
Is there some way to get
worker-loader
to acknowledge this part of my webpack config, have I done something incorrectly, or is this a bug?The text was updated successfully, but these errors were encountered: