UNPKG

st-bundle

Version:

CLI for watching and bundling SpringType projects.

47 lines (46 loc) 2 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const createStylesheetProps_1 = require("../../config/createStylesheetProps"); const sassHandler_1 = require("../../stylesheet/sassHandler"); const pluginUtils_1 = require("../pluginUtils"); const shared_1 = require("./shared"); function pluginSass(a, b) { let [opts, matcher] = pluginUtils_1.parsePluginOptions(a, b, {}); return (ctx) => { opts.stylesheet = createStylesheetProps_1.createStylesheetProps({ ctx, stylesheet: opts.stylesheet || {} }); if (!matcher) matcher = /\.(scss|sass)$/; ctx.ict.on('bundle_resolve_module', props => { const { module } = props; if (props.module.captured || !matcher.test(module.props.absPath)) { return; } if (!ctx.isInstalled('node-sass')) { ctx.fatal(`Fatal error when capturing ${module.props.absPath}`, [ 'Module "sass" is required, Please install it using the following command', 'npm install node-sass --save-dev', ]); return; } ctx.log.info('sass', module.props.absPath); props.module.read(); props.module.captured = true; const sass = sassHandler_1.sassHandler({ ctx: ctx, module, options: opts.stylesheet }); if (!sass) return; // A shared handler that takes care of development/production render // as well as setting according flags // It also accepts extra properties (like asText) to handle text rendering // Accepts postCSS Processor as well shared_1.cssContextHandler({ ctx, module: module, options: opts.stylesheet, processor: sass, shared: opts, }); return props; }); }; } exports.pluginSass = pluginSass;