Skip to content

aghassemi/rework-import

 
 

Repository files navigation

rework-import Build Status

Import stylesheets using @import and an optional media query. Pass a string or an array of paths to the path option in where to search for stylesheets. Handle recursive & relative imports.

Install

$ npm install --save rework-import

Usage

As a Rework plugin:

var imprt = require('rework-import');

rework(data)
    .use(imprt())
    .toString();

Example with all options

// using multiples paths
rework(data)
    .use(imprt({
        path: [
            'path/to/your/stylesheets',
            'node_modules',
        ]
        transform: require('css-whitespace')
    }))
    .toString();

Options

encoding

Type: String
Default: utf8

Use if your CSS is encoded in anything other than UTF-8.

path

Type: String|Array
Default: process.cwd() or dirname of the rework source

A string or an array of paths in where to look for files. Note: nested @import will additionally benefit of the relative dirname of imported files.

transform

Type: Function
Default: null

A function to transform the content of imported files. Take one argument (file content) & should return the modified content.
Useful if you use css-whitespace.

What to expect

@import "foo.css" (min-width: 25em);

body {
    background: black;
}

yields:

@media (min-width: 25em) {
    body {
        background: red;
    }

    h1 {
        color: grey;
    }
}

body {
    background: black;
}

License

MIT © Jason Campbell and Kevin Mårtensson

About

A rework plugin to read and inline css via @import

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 94.2%
  • CSS 5.8%