Home

Awesome

Groundskeeper Willie Babel Plugin

NPM Version

This project is a Babel plugin encompassing and expanding the functionality of the very useful Groundskeeper utility. Remaking Groundskeeper's features as a Babel plugin gives ongoing support to ES2015+, while greatly reducing runtime for those already using Babel in their build process.

This plugin will:

<p align="center"> <img align="center" width="300px" src="https://cloud.githubusercontent.com/assets/921683/17076208/7eae721c-5061-11e6-8afd-3071b0de4f70.gif" /> </p>

Complete Example:

Input:

Here we have a file that has some development code, a console, etc.

module.exports = {
    appCode(){
        console.log(`We're running with scissors!`);
        return [
            'included',
            /*<otherPragma>*/
            'excluded',
            /*</otherPragma>*/
            'also included'];
    }
};

//<debug>
module.exports.debugCode = {
    do.debugging.things.that.should.not.be.in.production();
}
//</debug>

Output:

When run with the Groundskeeper Willie plugin, we'll get back:

module.exports = {
	appCode() {
		return ['included', 'also included'];
	},
};

Why would you do that?

Right now, we (at Netflix) use pragmas so that our developer logging, debug code, and other related exports can live alongside the production code, but, at distribution time, we can ship down the smallest payload, without junking up the console, or sending extra unused code.

What's a pragma?

For the purposes of our little plugin, pragmas are comments that have an opening tag, and a closing tag, with a provided name. The pragma may appear in either a line comment or a block comment, and look like HTML/XML-esq open and close tags.

//<thisIsAPragma>
const removed = code.that.will.be.removed();
//</thisIsAPragma>
return ['included', /* <other> */ 'excluded', /* </other> */ 'also included'];

Plugin Options

The following are the available options with their default values.

{
	"plugins": [
		[
			"groundskeeper-willie",
			{
				"removeConsole": true,
				"removeDebugger": true,
				"removePragma": true
			}
		]
	]
}

removeConsole

If you wish to leave in all console statements, set this to false.

removeDebugger

If you wish to leave in all debugger statements, set this to false.

removePragma

If you wish to leave in all pragmas-wrapped code, stet this to false.