node-sass-global-import-once

1.0.2 • Public • Published

node-sass-global-import-once

Build Status

Import Sass files once globally.

Useful when you would want to exclude certain components in output files and leave them only in one location (e.g. one component is imported globally and any other attempt to load it would produce empty string). Goes along nicely with node-sass-import-once.

Installation

npm install node-sass-global-import-once --save

Usage

input/index.scss

@import "foo";
@import "bar";
@import "baz";
 
body {
    color:red;
}

input/page.scss

@import "foo";
@import "bar";
@import "baz";
 
body {
    color:red;
}
var sass = require('node-sass');
var gio = require('node-sass-global-import-once');
 
['./input/index.scss', './input/page.scss'].forEach(function ( file ) {
 
    sass.render({
        file: file,
        importer: [
            gio([
                {
                    file: '**/index.scss',
                    imports: [
                        'foo',
                        'baz'
                    ]
                }
            ]),
        ]
    }, function( err, result ) {
        //=> …
    });
 
});

Given two entry Sass files, they would be treated as:

input/index.scss

@import "foo";
@import "bar";
@import "baz";
 
body {
    color:red;
}

input/page.scss

@import "bar";
 
body {
    color:red;
}

page.scss doesn’t include foo and bar imports since they should be imported globally only once inside index.scss.

API

gio(definitions)

Package expects one argument, array of definitions (object) for global imports.

Each object definitions contains following properties:

file

Type: String

Name of the file or minimatch expression which is considered as global entry point.

imports

Type: Array

List of imports as strings which are considered to be global imports. Package only reads exact names defined inside files, so relative filenames which map to certain absolute package names are treated as different packages.

License

MIT © Ivan Nikolić

Readme

Keywords

Package Sidebar

Install

npm i node-sass-global-import-once

Weekly Downloads

1

Version

1.0.2

License

MIT

Last publish

Collaborators

  • niksy