refactor: export
This commit is contained in:
parent
013f980f58
commit
71c05e12d7
55
packages/web/src/server/augment-build.js
Normal file
55
packages/web/src/server/augment-build.js
Normal 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;
|
|
@ -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')) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user