2.0.6 • Published 7 years ago
babel-preset-tomekf-es2016-node6 v2.0.6
babel-preset-tomekf-es2016-node6
modules, better funcion name support, exponentiation operator and async/await for node 6
- modules: transform-es2015-modules-commonjs
- better function name support: transform-es2015-function-name
- exponentiation operator: transform-exponentiation-operator
- async/await: transform-regenerator, syntax-async-functions
example
es6
files in./es6
folder, transpiled toes5
in./es5
folder- working surcemaps -
source-map-support
regenerator-runtime/runtime
for async/await, fullbabel-polyfill
probably would be too muchnpm run go
startses5
codenpm run build
andnpm run watch
commands are self-explanatory- in case of publish, only
es5
files will be in the package, no need to install dev dependencies
.babelrc
{
"comments": false,
"presets": [
"tomekf-es2016-node6"
],
"plugins": [
"transform-runtime"
]
}
package.json
{
"name": "node-6-example",
"version": "0.0.0",
"engines": {
"node": ">=6.8.0"
},
"description": "node 6 example",
"main": "./es5/index.js",
"repository": "***/***",
"author": "Tomek Fijoł",
"license": "MIT",
"readmeFilename": "README.md",
"keywords": [ "example" ],
"files": [
"es5",
"*.js"
],
"scripts": {
"prepublish": "npm run build",
"build": "babel es6 --out-dir es5 --source-maps",
"watch": "babel es6 --out-dir es5 --source-maps --watch",
"go": "node es5/index.js"
},
"devDependencies": {
"babel-cli": "^6.18.0",
"babel-preset-tomekf-es2016-node6": "^2.0.5",
"babel-plugin-transform-runtime": "^6.15.0"
},
"dependencies": {
"regenerator-runtime": "^0.9.5",
"source-map-support": "^0.4.5"
}
}
./es6/index.js
import 'source-map-support/register';
import 'regenerator-runtime/runtime';
// start your code here
export default class NodeExample {
constructor(options) {
this.opts = Object.assign({}, NodeExample.defaults, options);
}
methodOne() {
// ...
}
}
// es7 features
NodeExample.defaults = {
optionOne: 2 ** 3,
optionTwo: [1, 2, 3].includes(2)
};
// async test
async function asyncFun () {
let value = await Promise
.resolve(1)
.then(x => x * 3)
.then(x => x + 5)
.then(x => x / 2);
return value;
}
asyncFun().then(x => console.log(`x: ${x}`));