diff --git a/config/.neutrinorc.js b/config/.neutrinorc.js index a925bde..49c96a2 100644 --- a/config/.neutrinorc.js +++ b/config/.neutrinorc.js @@ -1,14 +1,12 @@ const airbnbBase = require('@neutrinojs/airbnb-base'); const library = require('@neutrinojs/library'); const mocha = require('@neutrinojs/mocha'); +const react = require('@neutrinojs/react'); const nodeExternals = require('webpack-node-externals'); -module.exports = () => ({ +module.exports = { options: {}, use: [ - (neutrino) => { - neutrino.options.output = '.'; - }, airbnbBase({ eslint: { cache: false, @@ -16,14 +14,53 @@ module.exports = () => ({ }, }), (neutrino) => { - const {name} = neutrino.options.packageJson; - library({ + const {files, name} = neutrino.options.packageJson; + files + .filter((file) => { + try { + require.resolve(`${neutrino.options.source}/${file}`); + return true; + } + catch (error) { + if (file.match(/\.js$/)) { + try { + require.resolve(`${neutrino.options.source}/${file.slice(0, -3)}`); + return true; + } + catch (error) { + return false; + } + } + return false; + } + }) + .map((file) => file.match(/\.js$/) ? file.slice(0, -3) : file) + .forEach((file) => { + neutrino.options.mains[file] = {entry: 'index' === file ? file : `./src/${file}`}; + }); + neutrino.options.output = '.'; + react({ clean: false, - name, - target: 'node', })(neutrino); - }, - (neutrino) => { + Object.keys(neutrino.options.mains).forEach((main) => { + neutrino.config.plugins.delete(`html-${main}`); + }); + neutrino.config + .devtool('source-map') + .target('node') + .optimization + .splitChunks(false) + .runtimeChunk(false) + .end() + .output + .filename('[name].js') + .library(name) + .libraryTarget('umd') + .umdNamedDefine(true) + .end() + .node + .set('__dirname', false) + .set('__filename', false); const options = neutrino.config.module .rule('compile') .use('babel') @@ -33,4 +70,4 @@ module.exports = () => ({ }, mocha(), ], -}); +}; diff --git a/config/split-config.js b/config/split-config.js deleted file mode 100644 index 219068a..0000000 --- a/config/split-config.js +++ /dev/null @@ -1,52 +0,0 @@ -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]; - } -};