As I have thought about this and tried to understand it, especially compared to how the asset pipeline has worked (and not really caused us trouble) I wrote down my assumptions of the understanding of how things work today for core webpack and plugins. I’d ask @ui_ux developers to read through, correct statements and add more details where appropriate. Given part of this solution requires a potential change to how we handle plugin assets.
Webpack compile on core creates two JS files:
- bundle.js --> contains all of the Foreman application code and 0 third party dependencies
- vendor.js --> contains all of the Foreman third party dependency code
Change events:
- vendor.js should only change when third party dependencies update
- bundle.js should only change when Foreman code changes
For plugins:
- plugins have requires on 1 or more dependencies in vendor.js
- plugins may use API’s defined by Foreman code which lives in bundler.js
- sometimes plugins need to generate their own vendor.js for third party dependencies only they depend on
Compilation:
- webpack compile can change references to vendor libraries
- webpack compile can change references to APIs plugins rely on in bundle.js
- webpack compile eliminates redundancy by magically detecting what’s in vendor or bundle and keeping it out of the plugin bundle
Requirements
- Foreman needs to be able to generate vendor and bundle for core code
- plugins need to generate vendor for additional dependencies
- plugins need to generate a bundle for just their code
As I understand things, generating a plugins bundle is not as simple as take all the JS, concat it together and minify it due to the import statements within the code that attempts to ensure that dependencies are present combined with per compilation generation of code references due to how minification works. The plugin compilation step therefore requires analyzing core vendor.js and bundle.js to figure out what is present there to prevent putting it into the plugins bundle. As I think I understand things, this is one of the major issues given all references to something like lodash need to be the same. Any changes to vendor or bundle therefore “breaks” the generated “API” webpack creates and plugins must be recompiled.