57 lines
1.6 KiB
JavaScript
57 lines
1.6 KiB
JavaScript
const react = require('@neutrinojs/react');
|
|
const { library } = require('webpack');
|
|
const nodeExternals = require('webpack-node-externals');
|
|
|
|
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) => {
|
|
react({
|
|
clean: false,
|
|
})(neutrino);
|
|
Object.keys(clientConfig.options.mains).forEach((main) => {
|
|
neutrino.config.plugins.delete(`html-${main}`);
|
|
});
|
|
neutrino.config
|
|
.target('web')
|
|
.optimization
|
|
.splitChunks(false)
|
|
.runtimeChunk(false)
|
|
.end()
|
|
.output
|
|
.filename('[name].js')
|
|
.library(name)
|
|
.libraryTarget('umd')
|
|
.umdNamedDefine(true);
|
|
neutrino.config.externals({
|
|
'@latus/core/virtual': '@latus/core/virtual',
|
|
});
|
|
};
|
|
clientConfig.use.push((neutrino) => {
|
|
neutrino.config.node.set('Buffer', true);
|
|
});
|
|
return [serverConfig, clientConfig];
|
|
}
|
|
else {
|
|
const serverConfig = config();
|
|
serverConfig.options = {
|
|
mains,
|
|
};
|
|
return [serverConfig];
|
|
}
|
|
};
|