diff --git a/packages/build/src/build/app.webpack.config.js b/packages/build/src/build/app.webpack.config.js new file mode 100644 index 0000000..a44aa1f --- /dev/null +++ b/packages/build/src/build/app.webpack.config.js @@ -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); + } + });