mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 08:36:12 +01:00
perf: speed up build
run webpack as soon as js targets are done this allows building js/css in parallel
This commit is contained in:
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user