fix: fleck styles
This commit is contained in:
parent
55c9d23cb5
commit
8b5bd3a2ce
|
@ -34,6 +34,8 @@
|
|||
"server/build/template.ejs",
|
||||
"server/build/http.neutrinorc.js",
|
||||
"server/build/http.neutrinorc.js.map",
|
||||
"server/style-loader.js",
|
||||
"server/style-loader.js.map",
|
||||
"src",
|
||||
"tests.js",
|
||||
"tests.js.map"
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import {D, Hooks} from '@flecks/core';
|
||||
import {Flecks, spawnWith} from '@flecks/core/server';
|
||||
import {Flecks, require as R, spawnWith} from '@flecks/core/server';
|
||||
import fontLoader from '@neutrinojs/font-loader';
|
||||
import imageLoader from '@neutrinojs/image-loader';
|
||||
import styleLoader from '@neutrinojs/style-loader';
|
||||
|
@ -45,6 +45,14 @@ export default {
|
|||
}),
|
||||
);
|
||||
});
|
||||
if ('fleck' === target) {
|
||||
config.use.push((neutrino) => {
|
||||
neutrino.config.module.rule('compile').use('babel').tap((options) => ({
|
||||
...options,
|
||||
plugins: [...options.plugins, R.resolve('@flecks/http/server/style-loader')],
|
||||
}));
|
||||
});
|
||||
}
|
||||
config.use.push(fontLoader());
|
||||
config.use.push(imageLoader());
|
||||
},
|
||||
|
|
22
packages/http/src/server/style-loader.js
Normal file
22
packages/http/src/server/style-loader.js
Normal file
|
@ -0,0 +1,22 @@
|
|||
const parser = require('@babel/parser');
|
||||
const types = require('@babel/types');
|
||||
|
||||
let id = 0;
|
||||
|
||||
module.exports = () => ({
|
||||
visitor: {
|
||||
/* eslint-disable no-param-reassign */
|
||||
ImportDeclaration(path) {
|
||||
if (path.node.source.value.match(/\.(c|s[ac])ss$/)) {
|
||||
let defaultSpecifier = path.node.specifiers.find(types.isImportDefaultSpecifier);
|
||||
if (!defaultSpecifier) {
|
||||
defaultSpecifier = types.importDefaultSpecifier(types.identifier(`FLECKS_STYLES_${id++}`));
|
||||
path.node.specifiers.unshift(defaultSpecifier);
|
||||
}
|
||||
const {name} = defaultSpecifier.local;
|
||||
path.insertAfter(parser.parse(`if ('undefined' !== typeof document) ${name}.use();`));
|
||||
}
|
||||
},
|
||||
/* eslint-enable no-param-reassign */
|
||||
},
|
||||
});
|
Loading…
Reference in New Issue
Block a user