feat: auto styles

This commit is contained in:
cha0s 2021-01-26 23:25:13 -06:00
parent c014384712
commit 214b62d411

View File

@ -1,7 +1,6 @@
const {basename, dirname, extname, join} = require('path'); const {basename, dirname, extname, join} = require('path');
const airbnb = require('@neutrinojs/airbnb'); const airbnb = require('@neutrinojs/airbnb');
const banner = require('@neutrinojs/banner');
const glob = require('glob'); const glob = require('glob');
const mocha = require('@neutrinojs/mocha'); const mocha = require('@neutrinojs/mocha');
const react = require('@neutrinojs/react'); const react = require('@neutrinojs/react');
@ -17,10 +16,7 @@ module.exports = {
}, },
}), }),
(neutrino) => { (neutrino) => {
const { const {files = [], name} = neutrino.options.packageJson;
files = [],
name,
} = neutrino.options.packageJson;
files files
.filter((file) => { .filter((file) => {
const {source} = neutrino.options; const {source} = neutrino.options;
@ -49,9 +45,37 @@ module.exports = {
const testEntry = neutrino.config.entry('test').clear(); const testEntry = neutrino.config.entry('test').clear();
testPaths.forEach((path) => testEntry.add(path)); 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 = '.'; neutrino.options.output = '.';
react({ react({
clean: false, 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); })(neutrino);
Object.keys(neutrino.options.mains).forEach((main) => { Object.keys(neutrino.options.mains).forEach((main) => {
neutrino.config.plugins.delete(`html-${main}`); neutrino.config.plugins.delete(`html-${main}`);
@ -71,17 +95,13 @@ module.exports = {
.end() .end()
.node .node
.set('__dirname', false) .set('__dirname', false)
.set('__filename', false) .set('__filename', false);
.set('process', false);
const options = neutrino.config.module const options = neutrino.config.module
.rule('compile') .rule('compile')
.use('babel') .use('babel')
.get('options'); .get('options');
options.presets[0][1].targets = {esmodules: true}; options.presets[0][1].targets = {esmodules: true};
neutrino.config.externals(nodeExternals({ neutrino.config.externals(nodeExternals({importType: 'umd'}));
allowlist: ['uuid'],
importType: 'umd',
}));
}, },
mocha(), mocha(),
], ],