Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@fomantic/rework-import

fomantic11kMIT4.1.0

A rework plugin to read and inline CSS files via @import

css, import, media, rework

readme

rework-import Build Status

Forked Version using updated dependencies and dropped sourceMap support

Original repo at https://github.com/reworkcss/rework-import

Import stylesheets using @import and an optional media query

Install

$ npm install --save rework-import

Usage

var data = require('fs').readFileSync('index.css');
var imprt = require('rework-import');
var rework = require('rework');

rework(data)
    .use(imprt({path: 'app/stylesheets'}))
    .toString();

Options

encoding

Type: String
Default: utf8

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

path

Type: Array|String
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

A function to transform the content of imported files. Takes one argument and should return the modified content. Useful if you use css-whitespace.

Example

@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

changelog

4.1.0 / 2025-03-01

  • switch from globby to fast-glob removing audit issues

4.0.0 / 2025-03-01

  • dependency updates and drop node < 18

3.2.0 / 2025-02-08

  • Remove re2 and url-regex(-safe) dependency by re-implementing a slightly changed protocol check from 2.0

3.1.0 / 2024-05-07

  • Lock re2 and css-tool dependency versions to still support node 12

3.0.0 / 2022-10-28

  • Switched from css to @adobe/css-tools which in turn drops deprecated sourceMap support
  • Switched from rework to @fomantic/rework for the same reason

2.1.1 / 2022-10-28

  • Replace url-regex by url-regex-safe to fix CVE-2020-7661
  • Update dependencies
  • Fixed Tests on Windows

2.0.0 / 2014-11-27

  • Use url-regex to check for @imports containing URLs
  • Update parse-import to 2.0.0
  • Major improvements to code and tests

1.2.0 / 2014-07-04

  • Update css to 2.0.0 (ref)

1.1.3 / 2014-06-27

  • Fix a path stack issue

1.1.2 / 2014-06-26

  • Drop graceful-fs to allow browser usage (ref)

1.1.1 / 2014-06-26

  • Ignore protocol base URL

1.1.0 / 2014-06-25

  • Better automatic path (using rework/css.parse source option)
  • Better stack trace
  • transform option (mainly to use css-whitespace)

1.0.0 / 2014-06-14

Merge with rework-inline bring the following:

  • Support media queries
  • Add encoding option
  • Use find-file to lookup imports
  • Automated tests
  • Relative @import
  • Better error reporting

0.0.3 / 2013-08-07

  • Fix unused referenced package

0.0.2 / 2013-08-07

  • Allow nested imports

0.0.1 / 2013-08-06

Initial release