st-bundle
Version:
CLI for watching and bundling SpringType projects.
53 lines (52 loc) • 2.21 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const createStylesheetProps_1 = require("../../config/createStylesheetProps");
const resolver_1 = require("../../resolver/resolver");
const cssResolveURL_1 = require("../../stylesheet/cssResolveURL");
const pluginUtils_1 = require("../pluginUtils");
const shared_1 = require("./shared");
function pluginCSS(a, b) {
let [opts, matcher] = pluginUtils_1.parsePluginOptions(a, b, {});
if (!matcher)
matcher = /\.(css)$/;
return (ctx) => {
opts.stylesheet = createStylesheetProps_1.createStylesheetProps({ ctx, stylesheet: opts.stylesheet || {} });
if (!ctx.config.production && ctx.config.supportsStylesheet()) {
ctx.ict.on('assemble_module_init', props => {
const { module } = props;
if (module.isStylesheet()) {
module.fastAnalysis = { imports: [] };
module.fastAnalysis.imports.push({ type: resolver_1.ImportType.REQUIRE, statement: 'fuse-box-css' });
}
return props;
});
}
ctx.ict.on('bundle_resolve_module', props => {
const { module } = props;
if (!matcher.test(module.props.absPath) || props.module.captured)
return;
ctx.log.info('css', module.props.absPath);
module.read();
props.module.captured = true;
shared_1.cssContextHandler({
ctx,
module: module,
options: opts.stylesheet,
processor: {
render: async () => {
const urlResolver = cssResolveURL_1.cssResolveURL({
filePath: module.props.absPath,
ctx: ctx,
contents: module.contents,
options: ctx.config.stylesheet,
});
return { css: urlResolver.contents };
},
},
shared: { asText: opts.asText },
});
return props;
});
};
}
exports.pluginCSS = pluginCSS;