reddichat/config/split-config.js
2020-12-07 03:24:45 -06:00

40 lines
1.1 KiB
JavaScript

const library = require('@neutrinojs/library');
const config = require('./.neutrinorc');
module.exports = ({name, files}, clientMains) => {
const mains = files
.filter((file) => file.match(/\.js$/))
.map((file) => file.slice(0, -3))
.reduce((r, file) => ({...r, [file]: file}), {});
if (clientMains.length > 0) {
const serverMains = Object
.entries(mains)
.filter(([key]) => -1 === clientMains.indexOf(key))
.reduce((r, [k, v]) => ({...r, [k]: v}), {});
const serverConfig = config();
serverConfig.options.mains = serverMains;
const clientConfig = config();
clientConfig.options.mains = clientMains.reduce((r, file) => ({...r, [file]: file}), {});
clientConfig.use[2] = (neutrino) => {
library({
clean: false,
name,
target: 'web',
})(neutrino);
};
clientConfig.use.push((neutrino) => {
neutrino.config.node.set('Buffer', true);
});
return [serverConfig, clientConfig];
}
else {
const serverConfig = config();
serverConfig.options = {
mains,
};
return [serverConfig];
}
};