perf: speed up build

run webpack as soon as js targets are done
this allows building js/css in parallel
isekai-main
Barış Soner Uşaklı 2 years ago
parent e92238d09a
commit dd4e9cce09

@ -138,10 +138,9 @@ module.exports = function (grunt) {
}); });
const build = require('./src/meta/build'); const build = require('./src/meta/build');
if (!grunt.option('skip')) { if (!grunt.option('skip')) {
await build.build(true, { webpack: false }); await build.build(true, { watch: true });
} }
run(); run();
await build.webpack({ watch: true });
done(); done();
}); });

@ -77,20 +77,36 @@ async function beforeBuild(targets) {
const allTargets = Object.keys(targetHandlers).filter(name => typeof targetHandlers[name] === 'function'); const allTargets = Object.keys(targetHandlers).filter(name => typeof targetHandlers[name] === 'function');
async function buildTargets(targets, parallel) { async function buildTargets(targets, parallel, options) {
const length = Math.max(...targets.map(name => name.length)); const length = Math.max(...targets.map(name => name.length));
const jsTargets = targets.filter(target => targetHandlers.javascript.includes(target));
if (parallel) { const otherTargets = targets.filter(target => !targetHandlers.javascript.includes(target));
async function buildJSTargets() {
await Promise.all( await Promise.all(
targets.map( jsTargets.map(
target => step(target, parallel, `${_.padStart(target, length)} `) target => step(target, parallel, `${_.padStart(target, length)} `)
) )
); );
// run webpack after jstargets are done, no need to wait for css/templates etc.
if (options.webpack || options.watch) {
await exports.webpack(options);
}
}
if (parallel) {
await Promise.all([
buildJSTargets(),
...otherTargets.map(
target => step(target, parallel, `${_.padStart(target, length)} `)
),
]);
} else { } else {
for (const target of targets) { for (const target of targets) {
// eslint-disable-next-line no-await-in-loop // eslint-disable-next-line no-await-in-loop
await step(target, parallel, `${_.padStart(target, length)} `); await step(target, parallel, `${_.padStart(target, length)} `);
} }
if (options.webpack || options.watch) {
await exports.webpack(options);
}
} }
} }
@ -175,11 +191,7 @@ exports.build = async function (targets, options) {
} }
const startTime = Date.now(); const startTime = Date.now();
await buildTargets(targets, !series); await buildTargets(targets, !series, options);
if (options.webpack) {
await exports.webpack(options);
}
const totalTime = (Date.now() - startTime) / 1000; const totalTime = (Date.now() - startTime) / 1000;
await cacheBuster.write(); await cacheBuster.write();

Loading…
Cancel
Save