53 lines
1.5 KiB
JavaScript
53 lines
1.5 KiB
JavaScript
const react = require('@neutrinojs/react');
|
|
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);
|
|
};
|
|
clientConfig.use.push((neutrino) => {
|
|
neutrino.config.node.set('Buffer', true);
|
|
});
|
|
return [serverConfig, clientConfig];
|
|
}
|
|
else {
|
|
const serverConfig = config();
|
|
serverConfig.options = {
|
|
mains,
|
|
};
|
|
return [serverConfig];
|
|
}
|
|
};
|