node-sass-importer-builder
Utility to simplify creating importers for node-sass.
Allows to define how node-sass should process @import
directives with custom resources (e.g. json or js files).
Usage
var sass = ;var builder = ;var importer = ; var result = sass;
via Webpack:
var builder = ;var importer = ; moduleexports = module: loaders: test: /\.scss$/ loaders: "style" "css" "sass" sassLoader: importer: importer
API
builder(pattern:RegExp, handler:Function)
pattern
- regular expression pattern to match importing file.handler(filepath)
- function which somehow handles importing file in SASS-compatible data type. Invokes with absolute file path as first argument. Function must return string, number, boolean, array, object or null. Strings treated as is and becomes a part of final SASS file, so you can include whole files; generate rules, variables, mixins and functions here. Other type will be converted in SASS data type and assigned to SASS variable (filename is used as variable name).
builder.toSassString(value)
Helper to convert javascript value to SASS data type. Taken from rootbeer package.
Examples
Javascript importer
For example you need to share screen breakpoints config between javascript components and SCSS stylesheets:
// breakpoints.jsmoduleexports = xsmall: 0 small: 640 medium: 960 large: 1200 xlarge: 1440
Here we just calls nodejs require
to get configuration object and return it:
var importer = ;
Using this example.scss:
;
You will get:
;
YAML importer
var fs = ;var yaml = ;var builder = ;var yamlImporter = ;