refactor: export

This commit is contained in:
cha0s 2022-03-19 17:44:08 -05:00
parent 013f980f58
commit 71c05e12d7
2 changed files with 59 additions and 52 deletions

View File

@ -0,0 +1,55 @@
import fontLoader from '@neutrinojs/font-loader';
import imageLoader from '@neutrinojs/image-loader';
import styleLoader from '@neutrinojs/style-loader';
const augmentBuild = (target, config, flecks) => {
config.use.push((neutrino) => {
const isProduction = 'production' === neutrino.config.get('mode');
const extract = {};
const style = {};
if ('server' === target) {
extract.enabled = false;
style.injectType = 'lazyStyleTag';
}
if ('http' === target) {
extract.enabled = isProduction;
style.injectType = 'styleTag';
}
if ('fleck' === target) {
extract.enabled = true;
extract.plugin = {
filename: 'index.css',
};
}
neutrino.use(
styleLoader({
extract,
modules: {
localIdentName: isProduction ? '[hash]' : '[path][name]__[local]',
},
style,
test: /\.(c|s[ac])ss$/,
modulesTest: /\.module\.(c|s[ac])ss$/,
loaders: [
{
loader: 'postcss-loader',
useId: 'postcss',
options: {
postcssOptions: {
config: flecks.buildConfig('postcss.config.js'),
},
},
},
{
loader: 'sass-loader',
useId: 'sass',
},
],
}),
);
});
config.use.push(fontLoader());
config.use.push(imageLoader());
};
export default augmentBuild;

View File

@ -3,10 +3,8 @@ import {join} from 'path';
import {D, Hooks} from '@flecks/core';
import {Flecks, spawnWith} from '@flecks/core/server';
import fontLoader from '@neutrinojs/font-loader';
import imageLoader from '@neutrinojs/image-loader';
import styleLoader from '@neutrinojs/style-loader';
import augmentBuild from './augment-build';
import {configSource, inlineConfig} from './config';
import {createHttpServer} from './http';
@ -16,57 +14,11 @@ const {
const debug = D('@flecks/web/server');
export {augmentBuild};
export default {
[Hooks]: {
'@flecks/core.build': (target, config, flecks) => {
config.use.push((neutrino) => {
const isProduction = 'production' === neutrino.config.get('mode');
const extract = {};
const style = {};
if ('server' === target) {
extract.enabled = false;
style.injectType = 'lazyStyleTag';
}
if ('http' === target) {
extract.enabled = isProduction;
style.injectType = 'styleTag';
}
if ('fleck' === target) {
extract.enabled = true;
extract.plugin = {
filename: 'index.css',
};
}
neutrino.use(
styleLoader({
extract,
modules: {
localIdentName: isProduction ? '[hash]' : '[path][name]__[local]',
},
style,
test: /\.(c|s[ac])ss$/,
modulesTest: /\.module\.(c|s[ac])ss$/,
loaders: [
{
loader: 'postcss-loader',
useId: 'postcss',
options: {
postcssOptions: {
config: flecks.buildConfig('postcss.config.js'),
},
},
},
{
loader: 'sass-loader',
useId: 'sass',
},
],
}),
);
});
config.use.push(fontLoader());
config.use.push(imageLoader());
},
'@flecks/core.build': augmentBuild,
'@flecks/core.build.alter': async (neutrinoConfigs, flecks) => {
// Don't build if there's a fleck target.
if (neutrinoConfigs.fleck && !flecks.get('@flecks/web/server.forceBuildWithFleck')) {