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');
if (!grunt.option('skip')) {
await build.build(true, { webpack: false });
await build.build(true, { watch: true });
}
run();
await build.webpack({ watch: true });
done();
});

@ -77,20 +77,36 @@ async function beforeBuild(targets) {
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));
if (parallel) {
const jsTargets = targets.filter(target => targetHandlers.javascript.includes(target));
const otherTargets = targets.filter(target => !targetHandlers.javascript.includes(target));
async function buildJSTargets() {
await Promise.all(
targets.map(
jsTargets.map(
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 {
for (const target of targets) {
// eslint-disable-next-line no-await-in-loop
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();
await buildTargets(targets, !series);
if (options.webpack) {
await exports.webpack(options);
}
await buildTargets(targets, !series, options);
const totalTime = (Date.now() - startTime) / 1000;
await cacheBuster.write();

Loading…
Cancel
Save