babel-plugin-trimmer

1.2.0 • Public • Published

Babel plugin to remove unwanted code

Build Status

You can do “conditional compilation” with this plugin. Babel can produce different output, which depends on directives inside JS file.

Directives

Plugin directives are single line or block comments.

trim-below

Source:

const a = 1;
// trim-below
const b = 2;

Result:

var a = 1;

trim-above

Source:

const a = 1;
// trim-above
const b = 2;

Result:

const b = 2;

You can use both trim-below and trim-above directives at the same time to cut middle part of the file.

Advanced Techniques

Sometimes, you may want to remove actual “rendering” code but keep links to some external dependencies. Here is an example of the component which depends on LESS-file.

import styles from './testimonial.less';

// trim-below
import React, {Component} from 'react';

export default class Testimonial extends Component {
  render() {
    return (
      <div className="testimonial">
        {this.props.text}
      </div>
    );
  }
}

So, we keep that reference and build CSS styles for our component. But at the same time we got rid of React things.

Installation

npm install --save-dev babel-plugin-trimmer

Usage

Via .babelrc (Recommended)

.babelrc

{
  "plugins": ["trimmer"]  
}

Via CLI

babel --plugins trimmer script.js

Via Node API

require('babel-core').transform('code', {
  plugins: ['trimmer']
});

Links

License

ISC

Readme

Keywords

none

Package Sidebar

Install

npm i babel-plugin-trimmer

Weekly Downloads

1

Version

1.2.0

License

ISC

Last publish

Collaborators

  • mistakster