2021-01-22 14:48:57 -06:00
|
|
|
const {basename, dirname, extname, join} = require('path');
|
|
|
|
|
2021-01-24 09:32:43 -06:00
|
|
|
const airbnb = require('@neutrinojs/airbnb');
|
2021-01-22 14:48:57 -06:00
|
|
|
const glob = require('glob');
|
2020-12-23 12:46:52 -06:00
|
|
|
const mocha = require('@neutrinojs/mocha');
|
2020-12-24 23:12:26 -06:00
|
|
|
const react = require('@neutrinojs/react');
|
2020-12-24 19:58:02 -06:00
|
|
|
const nodeExternals = require('webpack-node-externals');
|
2020-12-23 12:46:52 -06:00
|
|
|
|
2020-12-24 23:12:26 -06:00
|
|
|
module.exports = {
|
2020-12-23 12:46:52 -06:00
|
|
|
options: {},
|
|
|
|
use: [
|
2021-01-24 09:32:43 -06:00
|
|
|
airbnb({
|
2020-12-23 12:46:52 -06:00
|
|
|
eslint: {
|
|
|
|
cache: false,
|
|
|
|
baseConfig: require(`${__dirname}/.eslint.defaults`),
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
(neutrino) => {
|
2021-01-22 14:48:57 -06:00
|
|
|
const {files = [], name} = neutrino.options.packageJson;
|
2020-12-24 23:12:26 -06:00
|
|
|
files
|
|
|
|
.filter((file) => {
|
2021-01-22 14:48:57 -06:00
|
|
|
const {source} = neutrino.options;
|
2020-12-24 23:12:26 -06:00
|
|
|
try {
|
2021-01-22 14:48:57 -06:00
|
|
|
require.resolve(`${source}/${file}`);
|
2020-12-24 23:12:26 -06:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
catch (error) {
|
2021-01-22 14:48:57 -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:12:26 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.forEach((file) => {
|
2021-01-22 14:48:57 -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:12:26 -06:00
|
|
|
});
|
2021-01-22 14:48:57 -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));
|
|
|
|
}
|
2021-01-26 23:25:28 -06:00
|
|
|
const cssPaths = glob.sync('./src/**/*.{css,scss}');
|
|
|
|
if (cssPaths.length > 0) {
|
|
|
|
const cssEntry = neutrino.config.entry('index.css').clear();
|
|
|
|
cssPaths.forEach((path) => cssEntry.add(path));
|
|
|
|
}
|
2020-12-24 23:12:26 -06:00
|
|
|
neutrino.options.output = '.';
|
|
|
|
react({
|
2020-12-23 12:46:52 -06:00
|
|
|
clean: false,
|
2021-01-22 15:43:53 -06:00
|
|
|
hot: false,
|
2021-01-24 12:05:49 -06:00
|
|
|
style: {
|
|
|
|
extract: {
|
|
|
|
enabled: false,
|
|
|
|
},
|
|
|
|
test: /\.(css|sass|scss)$/,
|
|
|
|
modulesTest: /\.module\.(css|sass|scss)$/,
|
|
|
|
loaders: [
|
|
|
|
{
|
|
|
|
loader: 'postcss-loader',
|
|
|
|
useId: 'postcss',
|
|
|
|
options: {
|
|
|
|
config: {
|
|
|
|
path: process.cwd(),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
loader: 'sass-loader',
|
|
|
|
useId: 'sass',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
2020-12-23 12:46:52 -06:00
|
|
|
})(neutrino);
|
2020-12-24 23:12:26 -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-12-23 12:46:52 -06:00
|
|
|
const options = neutrino.config.module
|
|
|
|
.rule('compile')
|
|
|
|
.use('babel')
|
|
|
|
.get('options');
|
|
|
|
options.presets[0][1].targets = {esmodules: true};
|
2020-12-24 19:58:02 -06:00
|
|
|
neutrino.config.externals(nodeExternals({importType: 'umd'}));
|
2020-12-23 12:46:52 -06:00
|
|
|
},
|
|
|
|
mocha(),
|
|
|
|
],
|
2020-12-24 23:12:26 -06:00
|
|
|
};
|