humus/webpack.config.js
2021-03-23 12:07:20 -05:00

46 lines
1.3 KiB
JavaScript

require('source-map-support/register');
const {Latus} = require('@latus/core');
const neutrino = require('neutrino');
const server = require('./.neutrinorc');
const {
LATUS_ONLY_BUILD = '',
} = process.env;
const onlyBuilds = LATUS_ONLY_BUILD.split(',').map((name) => name.trim());
module.exports = process.env.LATUS_LINTING
? neutrino(server).webpack()
: new Promise((resolve, reject) => {
try {
const latus = Latus.create();
const configs = {server};
latus.invokeFlat('@latus/core/build', configs);
Promise.all(Object.entries(configs).map(async ([k, v]) => [k, await v]))
.then(Object.fromEntries)
.then((configs) => {
const webpackConfigs = Object.values(
Object.entries(configs)
.reduce(
(r, [name, config]) => ({
...r,
...(-1 === onlyBuilds.indexOf(name) ? {} : {[name]: config}),
}),
{},
)
)
.map((config) => neutrino(config).webpack());
if (webpackConfigs.length > 1) {
resolve(webpackConfigs);
}
if (1 === webpackConfigs.length) {
resolve(webpackConfigs[0]);
}
});
}
catch (error) {
reject(error);
}
});