DragorWW / babel-plugin-inline-classnames

Babel plugin which inlines the result of classnames

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

babel-plugin-inline-classnames

Travis branch

Babel plugin which inlines the result of classnames

Useful for production builds.

Install

npm:

npm install -S babel-plugin-inline-classnames

yarn:

yarn add babel-plugin-inline-classnames

Usage

Add this plugin to your Babel config. Most commonly used in .babelrc:

For all environments:

{
  "plugins": ["inline-classnames"]
}

For production only (see env option):

{
  "env": {
    "production": {
      "plugins": ["inline-classnames"]
    }
  }
}

Examples

Input:

import classNames from 'classnames';
import styles from './styles.css';

classNames('foo', 'bar');
classNames('foo', { bar: true });
classNames({ 'foo-bar': true });
classNames({ 'foo-bar': false });
classNames({ foo: true }, { bar: true });
classNames({ foo: true, bar: true });
classNames('foo', { bar: true, duck: false }, 'baz', { quux: true });
classNames(null, false, 'bar', undefined, 0, 1, { baz: null }, '');
classNames(styles.foo, styles.bar);

Output:

import styles from './styles.css';

'foo bar';
'foo bar';
'foo-bar';
'';
'foo bar';
'foo bar';
'foo bar baz quux';
'bar ' + 1;
(styles.foo || '') + ' ' + (styles.bar || '');

About

Babel plugin which inlines the result of classnames

License:MIT License


Languages

Language:JavaScript 100.0%