npm install postcss-sassy-import
requires Node 5.0+
This plugin aims to implement imports like Sass, with select extensions and further plugin opportunities. At base, this yields:
- Inlining (like postcss-import)
- Globbing (like Ruby sass-globbing)
- Single-import by default (like node-sass-glob-once)
postcss-sassy-import is not limited to SCSS, however! It can run on any syntax that PostCSS supports, and can import vanilla CSS, SCSS, and JSON out of the box!
There's also a simple plugin system for adding new resolvers, formats, and load paths.
Why not postcss-import?
The authors of postcss-import are trying to follow the CSS specification, which means that support for extra features is second-class.
Write imports how you want to write them:
Get output like you expect:
;/* Contents of ./local.css *//* contents of config.json *//* contents of one of _reset.scss, reset.scss, reset.css or others *//* contents of all scss files in components/ */my-scope
Sass (or another preprocessor) can then handle the rest of the processing from there.
postcss-sassy-import will import files based on globs, and only import files once by default. This lets you declare stylesheet dependencies sanely and get no duplicates!
postcss-sassy-import can import plenty of useful things out of the box:
- Sass (SCSS syntax)
- Sass Partials (SCSS syntax)
- JSON (as SCSS variables)
It's also possible to force reuse of imports, which will cascade into their imports as well:
Imports can be tagged with "flags" to alter their behavior. Their usage is
@import "path" !flag
Allows the import to be run more than one time. This cascades to all imports inside the imported file, unless they have
Explicitly marks an import as only being importable once.
Tells postcss-sassy-import not to process this import. Useful for external Sass dependencies, like Foundation.
Only applicable when importing JSON
Causes all imported strings to be unquoted, suitable for dynamic content like colors.
If you use gulp, use postcss-sassy-import with gulp-postcss:
const gulp = ;const postcss = ;const sass = ;const sassyImport = ;gulp;
postcss-sassy-import takes in some configuration options and does some stuff with them.
Setting a list configuration here will add new options to the end of the list. To replace or remove existing values, add a plugin.
Shows stack traces for errors, useful for developing postcss-sassy-import itself.
Enable to deduplicate imports by default. Opt in and out of deduplication by using the
!multiple flags on imports, respectively.
["%", "%.scss", "_%.scss", "%.css", "%.json", "%/style.scss"]
A list of formats to try to resolve a path with.
% in the string is replaced with the file name, and the directory of the file is prepended to the result.
(origin => string)
- default: see source (loads current directory)
A list of paths to load from. Paths are specified with functions that are passed the file an import is being called from. They should return an absolute path to load from.
The built-in load path loads relative to the file an import is in, which looks like this:
./components to the list of paths to load, you could use:
To load files from
node_modules in the root of your project, you might use:
This load path, coupled with the default formats list, means that any installed module with a
style.scss in it can be imported.
This relies on the Node.js 'path' library being loaded.
- default: see source (loads scss, css, and json)
A loader is an object with two fields,
test is a function taking the path of the file, returning whether this loader is applicable.
method is a function that returns a Promise yielding a PostCSS
Root element from a wrapped file.
Wrapped files have two fields:
contents: The contents of the file
path: The path to the file
Plugins are run when postcss-sassy-import is called. They are passed the options that were given and are expected to mutate them.
This is a good place to add new loaders and formats if they're sensitive to ordering.
An array of PostCSS plugins to run on imports before inlining them into the syntax tree.
These plugins are not run on the root file.
An object defining virtual files to use in both single imports and globs. The key of the object is the file path, and the value is the contents of the file.
Pull requests and issues welcome!
postcss-sassy-import is licnsed under the MIT license. See LICENSE.md for more details.