sass-package-importer
v1.0.0
Published
A node-sass importer to resolve files from either npm packages or relative paths
Downloads
742
Maintainers
Readme
sass-package-importer
A node-sass importer to resolve files from either npm packages or relative paths
const {render} = require('node-sass');
const sassPackageImporter = require('sass-package-importer');
// ./relative.css: .title { color: green; }
const data = `
@import 'normalize.css';
@import 'relative';
`;
// `relative` is resolved but `normalize.css` is not resolved
render({data}, (err, {css}) => {
css.toString();
//=> '@import url(normalize.css);\n.title {\n color: green ...'
});
// `normalize.css` is resolved and the rendered CSS includes contents of normalize.css
render({data, importer: sassPackageImporter}, (err, {css}) => {
css.toString(); //=> '/*! normalize.css v8.0.0 | MIT License | github.com/necolas/normalize.css ...'
});
Installation
npm install sass-package-importer
API
const sassPackageImporter = require('sass-package-importer');
sassPackageImporter
Type: Function
Once this function is passed to importer
option of node-sass's render
method, it checks if each @import
target can be resolved with require.resolve()
.
If a target is resolvable and is neither JavaScript nor JSON file, the @import
will be inlined with the stylesheet in the resolved npm package. Otherwise @import
is treated as usual.
License
ISC License © 2018 Shinnosuke Watanabe