109 lines
3.1 KiB
JavaScript
109 lines
3.1 KiB
JavaScript
const {basename, dirname, extname, join} = require('path');
|
|
|
|
const airbnb = require('@neutrinojs/airbnb');
|
|
const glob = require('glob');
|
|
const mocha = require('@neutrinojs/mocha');
|
|
const react = require('@neutrinojs/react');
|
|
const nodeExternals = require('webpack-node-externals');
|
|
|
|
module.exports = {
|
|
options: {},
|
|
use: [
|
|
airbnb({
|
|
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));
|
|
}
|
|
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));
|
|
}
|
|
neutrino.options.output = '.';
|
|
react({
|
|
clean: false,
|
|
hot: false,
|
|
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',
|
|
},
|
|
],
|
|
},
|
|
})(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')
|
|
.get('options');
|
|
options.presets[0][1].targets = {esmodules: true};
|
|
neutrino.config.externals(nodeExternals({importType: 'umd'}));
|
|
},
|
|
mocha(),
|
|
],
|
|
};
|