2020-12-27 19:16:29 -06:00
|
|
|
const {basename, dirname, extname, join} = require('path');
|
|
|
|
|
2020-11-30 06:28:29 -06:00
|
|
|
const airbnbBase = require('@neutrinojs/airbnb-base');
|
2021-01-05 02:47:55 -06:00
|
|
|
const glob = require('glob');
|
2020-11-30 06:28:29 -06:00
|
|
|
const mocha = require('@neutrinojs/mocha');
|
2020-12-24 23:11:47 -06:00
|
|
|
const react = require('@neutrinojs/react');
|
2020-12-24 19:56:09 -06:00
|
|
|
const nodeExternals = require('webpack-node-externals');
|
2020-11-30 06:28:29 -06:00
|
|
|
|
2020-12-24 23:11:47 -06:00
|
|
|
module.exports = {
|
2020-12-02 16:34:52 -06:00
|
|
|
options: {},
|
2020-11-30 06:28:29 -06:00
|
|
|
use: [
|
|
|
|
airbnbBase({
|
|
|
|
eslint: {
|
|
|
|
cache: false,
|
|
|
|
baseConfig: require(`${__dirname}/.eslint.defaults`),
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
(neutrino) => {
|
2020-12-27 19:16:29 -06:00
|
|
|
const {files = [], name} = neutrino.options.packageJson;
|
2020-12-24 23:11:47 -06:00
|
|
|
files
|
|
|
|
.filter((file) => {
|
2021-01-03 00:58:24 -06:00
|
|
|
const {source} = neutrino.options;
|
2020-12-24 23:11:47 -06:00
|
|
|
try {
|
2021-01-03 00:58:24 -06:00
|
|
|
require.resolve(`${source}/${file}`);
|
2020-12-24 23:11:47 -06:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
catch (error) {
|
2021-01-03 00:58:24 -06:00
|
|
|
const ext = extname(file);
|
|
|
|
try {
|
|
|
|
require.resolve(`${source}/${dirname(file)}/${basename(file, ext)}/index${ext}`);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
catch (error) {
|
|
|
|
return false;
|
|
|
|
}
|
2020-12-24 23:11:47 -06:00
|
|
|
}
|
|
|
|
})
|
|
|
|
.forEach((file) => {
|
2020-12-27 19:16:29 -06:00
|
|
|
const isIndex = 'index.js' === file;
|
|
|
|
const trimmed = join(dirname(file), basename(file, extname(file)));
|
|
|
|
neutrino.options.mains[trimmed] = {entry: isIndex ? file : `./src/${trimmed}`};
|
2020-12-24 23:11:47 -06:00
|
|
|
});
|
2021-01-05 02:47:55 -06:00
|
|
|
const testPaths = glob.sync('./test/*.js');
|
|
|
|
if (testPaths.length > 0) {
|
|
|
|
const testEntry = neutrino.config.entry('test').clear();
|
|
|
|
testPaths.forEach((path) => testEntry.add(path));
|
|
|
|
}
|
2020-12-24 23:11:47 -06:00
|
|
|
neutrino.options.output = '.';
|
|
|
|
react({
|
2020-11-30 06:28:29 -06:00
|
|
|
clean: false,
|
|
|
|
})(neutrino);
|
2020-12-24 23:11:47 -06:00
|
|
|
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);
|
2020-11-30 06:28:29 -06:00
|
|
|
const options = neutrino.config.module
|
|
|
|
.rule('compile')
|
|
|
|
.use('babel')
|
|
|
|
.get('options');
|
|
|
|
options.presets[0][1].targets = {esmodules: true};
|
2020-12-24 19:56:09 -06:00
|
|
|
neutrino.config.externals(nodeExternals({importType: 'umd'}));
|
2020-11-30 06:28:29 -06:00
|
|
|
},
|
|
|
|
mocha(),
|
|
|
|
],
|
2020-12-24 23:11:47 -06:00
|
|
|
};
|