Hello,
I would like to push forward the redesign process of the webpack build.
See the previous post about the webpack redesign: Webpacking plugins, let's do it right
See the post about the full JS redesign: Redesigning the javascript stack
Issues
- RM #27195 - Plugins js/css build with webpack cause to copy the full js/css of the core to each plugin
- It is difficult to understand the build process.
- Plugins can’t build themselves, they need Foreman to get build. (more steps to do before you can build your plugin).
- We need to rebuild plugins after each core build.
Most of it solved by the vendor but from time to time we will still see this issue because- Some deps still exists outside of the vendor
- We use an alias for plugins so they can reuse code from the
react_app
folder.
- The build process creates an importing alias for plugins from
foremanReact
to the corereact_app
folder. While it works when running foreman itself, it doesn’t work in the plugins dev environment (test, lint, storybook).
Plugins find themselves mocking each piece of code they are using from core, see: katello mocks
Goals
- Fix all the issues above
- Upgrade webpack from v3 to v4
- Remove the webpack-rails gem
- Make it simple and reusable
@theforeman/builder
A node module to provide the ability to build production and development bundle files for foreman core and plugins.
For now, it contains the babel
shared configuration that webpack and other tools uses.
This PR is a WIP to add the building abilities to @theforeman/builder
.
How I expect it to be consumed?
- The consumer would install
@theforeman/builder
from npm:
npm install --save-dev @theforeman/builder
- Create a config file with the minimal needed configurations:
// foreman/config/tfm-build.config.js
module.exports = {
entry: {
foreman: require.resolve('../webpack/assets/javascripts/bundle.js'),
},
};
// katello/config/tfm-build.config.js
module.exports = {
entry: {
katello: require.resolve('../webpack/index.js'),
katelloFills: require.resolve('../webpack/index_fills.js'),
katelloCommon: require.resolve('../webpack/index_common.js'),
},
};
- Use the needed executable (tfm-build, tfm-build-analyze, tfm-dev-server) and provide your config file (e.g.
tfm-build config/tfm-build.config.js
).
User Stories
-
Foreman Developer
- Developers should be able to build foreman
tfm-build config/tfm-build.config.js
- Developers should be able to run a development server with the foreman and the installed plugins
tfm-dev-server config/tfm-build.config.js
- Developers should be able to analyze foreman build
tfm-build-analyze config/tfm-build.config.js
- Developers should be able to build foreman
-
Plugin Developer
- Developers should be able to build their plugins
tfm-build --plugin config/tfm-build.config.js
- Developers should be able to analyze their plugins build
tfm-build-analyze --plugin config/tfm-build.config.js
- Developers should be able to build their plugins
Solving the react_app/foremanReact issue
Fixing - RM #27195 - Plugins js/css build with webpack cause to copy the full js/css of the core to each plugin by creating a new separate process to build foremanReact/react_app into a standard library using webpack-4.
// foreman/config/tfm-build.config.js
module.exports = {
library: 'foremanReact', // build it into a library
entry: {
foreman: require.resolve('../webpack/assets/javascripts/react_app/index.js'),
},
};
tfm-build config/foreman-react.tfm-build.config.js
How to build a library with webpack:
Webpack Externals:
There is already a PR exists in foreman-js
to put all the needed webpack configurations in @theforeman/builder
and adding the tfm-build
executable:
The goal is to add the library
option so it would add some configurations that would build your entry to a library.
parallel-webpack
Using this library would allow us to build and run a development server with core, foremanReact, and plugins while they get to build in parallel.
It would allow us to watch and only build the parts that need to get rebuild.
TODO
- Fixes #28448 - Use Intl npm modules from vendor
- Add the I18n related modules to vendor from foreman as async modules
- Install webpack-4 in @theforeman/builder and create a tfm-build command that can build core/plugins
- Consume the tfm-build and tfm-dev-server command from @theforeman/builder and drop webpack-3
- Build the foremanReact/react_app into a library
- Consume foremanReact/react_app as an external library
- Install @theforeman/builder in plugins so they can get build using tfm-build
Feel welcome to comment on anything, suggest changes and contribute to the effort.
Cheers!