feat: app webpack

This commit is contained in:
cha0s 2021-03-23 18:19:58 -05:00
parent 41802a2c9d
commit 86d416737c

View File

@ -0,0 +1,55 @@
require('source-map-support/register');
const {Latus, require: R} = require('@latus/core');
const neutrino = require('neutrino');
const {
LATUS_ONLY_BUILD = '',
LATUS_BABEL_CONFIG = require.resolve('./.babelrc.js'),
LATUS_NEUTRINO_CONFIG = require.resolve('./.neutrinorc.js'),
} = process.env;
const onlyBuilds = LATUS_ONLY_BUILD.split(',').map((name) => name.trim());
R('@babel/register')({
configFile: LATUS_BABEL_CONFIG,
});
module.exports = process.env.LATUS_LINTING
? neutrino(server).webpack()
: new Promise((resolve, reject) => {
try {
const latus = Latus.create();
const configs = {
server: require(LATUS_NEUTRINO_CONFIG),
};
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,
...(
(0 === onlyBuilds.length || -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);
}
});