Last active
January 15, 2019 08:16
-
-
Save twada/ba57689d44f8d0a4e9c470d8169498b7 to your computer and use it in GitHub Desktop.
example: unassert but preserve comments
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
}; | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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 | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ npm run gen:prod | |
> [email protected] 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 }; | |
$ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "pd-preserve-comment-unassert", | |
"description": "preserve comment example", | |
"version": "1.0.0", | |
"author": { | |
"name": "Takuto Wada", | |
"email": "[email protected]", | |
"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