avocado/config/.neutrinorc.js
2021-01-16 16:48:19 -06:00

89 lines
2.5 KiB
JavaScript

const {basename, dirname, extname, join} = require('path');
const airbnbBase = require('@neutrinojs/airbnb-base');
const banner = require('@neutrinojs/banner');
const glob = require('glob');
const mocha = require('@neutrinojs/mocha');
const react = require('@neutrinojs/react');
const nodeExternals = require('webpack-node-externals');
module.exports = {
options: {},
use: [
airbnbBase({
eslint: {
cache: false,
baseConfig: require(`${__dirname}/.eslint.defaults`),
},
}),
(neutrino) => {
const {
files = [],
name,
} = neutrino.options.packageJson;
files
.filter((file) => {
const {source} = neutrino.options;
try {
require.resolve(`${source}/${file}`);
return true;
}
catch (error) {
const ext = extname(file);
try {
require.resolve(`${source}/${dirname(file)}/${basename(file, ext)}/index${ext}`);
return true;
}
catch (error) {
return false;
}
}
})
.forEach((file) => {
const isIndex = 'index.js' === file;
const trimmed = join(dirname(file), basename(file, extname(file)));
neutrino.options.mains[trimmed] = {entry: isIndex ? file : `./src/${trimmed}`};
});
const testPaths = glob.sync('./test/*.js');
if (testPaths.length > 0) {
const testEntry = neutrino.config.entry('test').clear();
testPaths.forEach((path) => testEntry.add(path));
}
neutrino.options.output = '.';
react({
clean: false,
})(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)
.set('process', false);
const options = neutrino.config.module
.rule('compile')
.use('babel')
.get('options');
options.presets[0][1].targets = {esmodules: true};
neutrino.config.externals(nodeExternals({
allowlist: ['uuid'],
importType: 'umd',
}));
},
mocha(),
],
};