Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

babel-plugin-trimmer

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

babel-plugin-trimmer

Babel plugin to remove unwanted code

  • 1.2.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
7
increased by40%
Maintainers
1
Weekly downloads
 
Created
Source

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

.babelrc

{
  "plugins": ["trimmer"]  
}

Via CLI

babel --plugins trimmer script.js

Via Node API

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

License

ISC

FAQs

Package last updated on 23 Jan 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc