Skip to content

Instantly share code, notes, and snippets.

@twada

twada/babel.config.js

Last active Jan 15, 2019
Embed
What would you like to do?
example: unassert but preserve comments
module.exports = function (api) {
const presets = [];
const plugins = [];
let retainLines = false;
let comments = true;
if (api.env('production')) {
plugins.push('babel-plugin-unassert');
retainLines = true;
}
return {
comments,
retainLines,
presets,
plugins
};
};
/**
* unassert example with Babel7
*
* Copyright (c) 2019 Takuto Wada
* Licensed under the MIT license.
* http://twada.mit-license.org/
*/
'use strict';
// will be removed under production
const assert = require('assert');
/**
* adds augend and addend
*
* @param {number} augend - the one to which the others are added
* @param {number} addend - a quantity to be added to another
* @return {number} - result of caluclation
*/
function add (augend, addend) {
// checking augend
assert(!isNaN(augend));
/**
* checking addend
*/
assert.ok(!isNaN(addend));
return augend + addend;
}
module.exports = {
add
};
$ npm run gen:prod
> pd-preserve-comment-unassert@1.0.0 gen:prod /path/to/pd-preserve-comment-unassert
> BABEL_ENV=production babel calc.js
/**
* unassert example with Babel7
*
* Copyright (c) 2019 Takuto Wada
* Licensed under the MIT license.
* http://twada.mit-license.org/
*/
'use strict';
// will be removed under production
/**
* adds augend and addend
*
* @param {number} augend - the one to which the others are added
* @param {number} addend - a quantity to be added to another
* @return {number} - result of caluclation
*/
function add(augend, addend) {
// checking augend
/**
* checking addend
*/
return augend + addend;
}
module.exports = {
add };
$
{
"name": "pd-preserve-comment-unassert",
"description": "preserve comment example",
"version": "1.0.0",
"author": {
"name": "Takuto Wada",
"email": "takuto.wada@gmail.com",
"url": "https://github.com/twada"
},
"devDependencies": {
"@babel/cli": "^7.0.0",
"@babel/core": "^7.0.0",
"babel-plugin-unassert": "^3.0.0"
},
"keywords": [],
"license": "MIT",
"main": "index.js",
"private": true,
"scripts": {
"gen:dev": "babel calc.js",
"gen:prod": "BABEL_ENV=production babel calc.js"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment