babel-plugin-transform-import-ignore

A babel transform plugin to ignore imports that do not work in node environment.

Downloads in past

Stats

StarsIssuesVersionUpdatedCreatedSize
babel-plugin-transform-import-ignore
001.1.02 years ago2 years agoMinified + gzip package size for babel-plugin-transform-import-ignore in KB

Readme

babel-plugin-transform-import-ignore
Ignore imports that do not work in node environment. The most common use case is ignoring stylesheet imports in server-side rendering.

Install

$ yarn add babel-plugin-transform-import-ignore --dev

Usage

Configure the plguin in your babel configuration file and specify the import paths that you want to ignore. Wildcard identifier * is supported.
```.babalrc { "plugins":
[
  "babel-plugin-transform-import-ignore",
  {
    "patterns": [".css", ".scss", "wildcard/*/match.css"]
  }
]
}
If you are using js file as configuration file, you can pass regular expressions instead of string literals.

```javascript
// babel.config.js
module.exports = {
  plugins: [
    ['babel-plugin-transform-import-ignore', {
      patterns: [/\.s?css$/, /\.less$/],
    }],
  ],
};

The plugin only deals with import expressions with side-effect. If the imported module is assgined to a variable, the import statement won't be ignored.
import './path/to/style.css'; // If pattern matched, will be ignored.

import css from './path/to/style.css'; // Won't be ignored even if pattern matched.