The webpack build pipeline that bundles and minifies the workbench’s scripts, styles, images, and fonts.
The workbench application consists of many resources: script files, stylesheets, images, fonts. In a non optimized build this would lead to hundreds of http requests. Nowadays web applications are usually optimized by bundling their resources and minifying them. The reason for this is to have significantly fewer http requests which leads to faster initial load and less traffic.
Bundling of the workbench is done with webpack. It’s configured with three config files:
The common config contains shared configuration for the other two.
There are two ways the application to be built. First is for production and the other is for dev. See the Build and Dev server sections above.
The code for production is build in in the /dist folder. The bundling covers the following
tasks:
/app.js and is emitted in /dist in a
bundle file named bundle.[hash].js. The hash is generated and applied in order to allow cache
busting. Every change in the application code forces new hash to be generated thus forcing browsers
to request the new bundle version. If the application code contains dynamic imports, webpack emits
new bundle. This is the case for the clustermanagement module which is only imported if the
workbench is loaded in enterprise mode.vendor.[hash].js and is bundled by the webpack. Here goes third
party libraries like jquery, angularjs and third party libraries stylesheets.main.js which is
bundled by the webpack and emitted as main.[hash].js. This is needed because importing them in the
app.js breaks the bundle.index.html at the end of the body tag.less-loader, converted to javascript in the bundles
with css-loader and finally injected at the end of the head tag in index.html. Not injecting
them during the build time would lead to unwanted showing the un-styled application until webpack
injects them runtime.bootstrap and angular depend on jquery to be loaded and present
globally. That’s why it is mandatory jquery to be properly pre-loaded and exposed in the global
scope. This is done using the expose-loader. It ensures that when requested, it will be available
for the libraries./dist
folder. Resources referenced from within those templates are also directly copied to allow proper
loading. The copying is done using the CopyPlugin.
template.html processing, referenced images are automatically copied in the /dist
folder. The file-loader is used for the purpose./dist folder using the
url-loader./dist directory is cleaned up before every build to prevent accumulating bundle files with
different hashes in their names.See also: Developers Guide