sass-package-importer

1.0.0 • Public • Published

sass-package-importer

npm version Build Status Coverage Status

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

Use npm.

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

Package Sidebar

Install

npm i sass-package-importer

Weekly Downloads

103

Version

1.0.0

License

ISC

Unpacked Size

4.47 kB

Total Files

4

Last publish

Collaborators

  • shinnn