Join GitHub today
DllPlugin breaks jquery with expose-loader & ProvidePlugin #8096
What is the current behavior?
When using the DllPlugin, jquery cannot be exposed. Before switching to the DllPlugin jquery could be exposed either using the ProvidePlugin or expose-loader. You would need to load jquery outside of webpack in order to get it to be exposed. This means we'd need to load jquery twice.
If the current behavior is a bug, please provide the steps to reproduce.
Here is the gist
What is the expected behavior?
Other relevant information:
A DLL doesn't evaluate any code. It only offers the modules for the referencing bundle. A module from the DLL can be used if the exact same module is requested from the referencing bundle. i. e. you DLL contains
I thought the purpose of the DLL was to bundle up items that are not going to change. Likely reference code like jquery, datatatables, bootstrap, etc.
Now if I could create my own bundle through something like https://docs.microsoft.com/en-us/aspnet/mvc/overview/performance/bundling-and-minification ...is there a way I can tell webpack that these items should already be available by other means and not to try and import twice when it sees the dependencies?
yes. You can put jquery in the dll and it's also possible to expose it, but you need to have the expose rule in the application config too.
For example, I could not simply pull in select2 like this and it recognize jquery.
However... when I added this to my main app.ts file, then everything started working.
Even if I didn't need to use jquery inside webpack delivered files, I still had to import it in order to get this recognized to the outside world. However, if I removed the dll config entirely and left to the app config, the expose-loader still does not work without the above imports.
I can however, remove the imports and use the ProvidePlugin and this works to expose jquery. This does not work when using the dll though. Any clarity to this situation would be welcomed.