Build webpack bundles and styles in parallel

This commit is contained in:
Terncode committed 2026-11-21 16:37:13 +01:00
1 parent ecfe558b1f
commit a508a34b48
3 files changed
+31 -27

No files matched your search

+19 -25
View File
@@ -233,8 +233,9 @@ const assetsRev = cb => {
fs.writeFile('src/ts/generated/rev.ts', lintCode(code), 'utf8', cb);
};
// images are only optimized for production builds
const assetsCopy = () => gulp.src('assets/**/*', { encoding: false })
.pipe(gulpif(!argv.fast, imagemin([
.pipe(gulpif(!argv.fast && !development, imagemin([
mozjpeg(),
optipng({ optimizationLevel: 1 }),
gifsicle(),
@@ -264,7 +265,7 @@ const sassMain = buildSass('main', 'src/styles/style.scss', 'dist/browser/assets
const sassInline = buildSass('inline', 'src/styles/style-inline.scss', 'dist/browser/assets');
const sassTools = buildSass('tools', 'src/styles/style-tools.scss', 'dist/browser/assets');
const sassAdmin = buildSass('admin', 'src/styles/style-admin.scss', 'dist/browser/assets-admin');
const sassTasks = gulp.series(sassMain, sassInline, sassTools, sassAdmin);
const sassTasks = gulp.parallel(sassMain, sassInline, sassTools, sassAdmin);
const testScripts = [
'dist/node/tests/**/*.js'
@@ -353,21 +354,9 @@ const patchWebWorkerTask = cb => {
cb();
};
let webpackScript = 'webpack-prod';
const webpackScript = argv.debug ? 'webpack-debug' : 'webpack-prod';
const webpackArgs = ['--'];
if (argv.parallel) {
webpackScript = 'webpack-prod-parallel';
}
if (argv.debug) {
webpackScript = 'webpack-debug';
}
if (argv.main) {
webpackScript = 'webpack-main';
}
if (argv.beta) {
webpackArgs.push('--env', 'beta');
}
@@ -376,15 +365,21 @@ if (argv.timing) {
webpackArgs.push('--env', 'timing');
}
const webpackProd = npmScript(webpackScript, webpackArgs);
// each bundle is built in its own webpack process, webpack builds multiple configs
// in a single process one after another, so this makes use of multiple cores
const webpackBundles = argv.main ? ['bootstrap'] : ['bootstrap', 'bootstrap-admin', 'bootstrap-tools'];
const webpackProd = gulp.parallel(...webpackBundles.map(bundle => {
const task = npmScript(webpackScript, [...webpackArgs, '--env', `bundle=${bundle}`]);
task.displayName = `webpack (${bundle})`;
return task;
}));
const webpackAdmin = npmScript('webpack-admin');
const sw = npmScript('sw');
const assets = gulp.series(assetsCopy, assetsRev);
const codegen = gulp.parallel(gulp.series(manifest, changelog), hash, rollbar, icons, shaders);
// common: pre-webpack shared tasks. Sequential assets->sass avoids event-loop
// contention between gulp-imagemin (async) and dart-sass (blocks the loop).
const common = gulp.series(codegen, assets, sassTasks);
// sass-embedded compiles in a separate process, so it does not block the event loop
const common = gulp.parallel(codegen, assets, sassTasks);
const covRemap = gulp.series(coverage, remap);
const watch = cb => {
@@ -431,12 +426,11 @@ const empty = cb => cb();
const spritesTask = argv.sprites ? sprites : empty;
//const buildSprites = gulp.series(tsTools, sprites);
// tsc -> dist/node and webpack -> dist/browser are independent (different output
// dirs, different inputs), so they can run in parallel with each other and with
// the assets/sass branch. webpack is the long pole, so assets/sass are hidden
// behind it. sw + size must wait for all of them.
const build = gulp.series(clean, setProd, gulp.series(assets, sassTasks), gulp.parallel(
gulp.series(codegen, gulp.parallel(ts, webpackProd)),
// tsc and webpack depend on generated files (codegen + rev.ts from assets), sass does not,
// so sass runs alongside them. webpack is the long pole. sw + size must wait for all of them.
const build = gulp.series(clean, setProd, gulp.parallel(
gulp.series(gulp.parallel(codegen, assets), gulp.parallel(ts, webpackProd)),
sassTasks,
), sw, size);
const admin = gulp.series(cleanAdmin, setProd, sassAdmin, ts, webpackAdmin);
const dev = gulp.series(clean, spritesTask, common, gulp.parallel(serverDev, watch, watchTools));