npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

babel-plugin-transform-helper

v0.0.6

Published

Transform babel helper code to reduce transformed code size

Downloads

286

Readme

#babel-plugin-transform-helper

Babel transforms some awesome ES6 features to ES5 with extra code, such as Class,JSX. This plugin makes all generated extra codes to one module which significantly reduces the bundle code size.

##Install

npm install babel-plugin-transform-helper --save-dev

##Usage ###.babelrc

{
	...
	"plugins":["babel-plugin-transform-helper"]
}

###code

babel.transform(code,{
	...
	plugins:["babel-plugin-transform-helper"]
})

##Options You can specify the helper bundle file path by helperFilename property.

babel.transform(code,{
	...
	plugins:[
		["babel-plugin-transform-helper",{
				helperFilename:'tempHelper.js'
			}
		]
	]
})

##How it work This plugin write all generated helper code to one module and the original codes require the module instead of calling from local.Let's support we have two class file.

	//Point.js
	export default class Point extends Array{
		constructor(x,y){
			super();
			this.push(x,y);
		}
		get x(){
    		return this[0]
    	}
    	get y(){
    		return this[1]
    	}
    }
    //Rect.js
    import Point from './Point';
    export default class Rect extends Array{
    	constructor(x,y,w,h){
    		super();
    		this.push(x,y,w,h);
		}
		get loc(){
    		return new Point(this[0],this[1])
		}
	}

When transfers ES6 class,import,typeof ... to ES5, babel add helper code in each original file, the Point.js will be transfered to

	var _createClass =//..some code

	function _classCallCheck(instance, Constructor){//..some code}
	function _possibleConstructorReturn(self, call){//..some code}

	function _inherits(subClass, superClass){//..some code}

	var Point = function (_Array) {
		_inherits(Point, _Array);
		function Point(x, y) {	
			_classCallCheck(this, Point);
	 		var _this = _possibleConstructorReturn(this, Object.getPrototypeOf(Point).call(this));
			_this.push(x, y);
			return _this;
		}
		_createClass(Point, [{
    		key: "x",
    		get: function get() {
      			return this[0];
    		}//...some code
    	}]);
		return Point;
	}(Array)

If every file adds these same code the size of bundle file used in browser can be extremely larger than the original source file. The helper codes are the same in every file,so we can group them in a moudle and require the module instead of call it from local, which make the Point.js like below.

	var Point = function (_Array) {
		require("../../tempHelper.js").inherits(Point, _Array);
		function Point(x, y) {
    		require("../../tempHelper.js").classCallCheck(this, Point);
			var _this = require("../../tempHelper.js").possibleConstructorReturn(this, Object.getPrototypeOf(Point).call(this));
	 		_this.push(x, y);
    		return _this;
		}	
		require("../../tempHelper.js").createClass(Point, [{
    		key: "x",
    		get: function get() {
      			return this[0];
    		}//...somecode
		}]);
		return Point;
	}(Array);

And generate a file tempHelper.js

	exports.inherits=//..somecode
	exports.createClass=//..somecode
	....

When Point.js and Rect.js bundled together, they require the same module and the code size reduced.The temp module file will be write to the working directory and bundled automatically.