├── .gitignore ├── index.js ├── package.json └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | .idea 3 | **/.DS_Store 4 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | /* global module */ 2 | module.exports = { 3 | plugins: [ 4 | require('babel-plugin-transform-es2015-modules-commonjs'), 5 | ], 6 | }; 7 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "babel-preset-node6", 3 | "version": "11.0.0", 4 | "description": "Babel preset for Node 6.x (ES6 / ES2015)", 5 | "repository": "git://github.com/salakar/babel-preset-node6.git", 6 | "main": "index.js", 7 | "scripts": { 8 | "test": "echo \"Error: no test specified\" && exit 1" 9 | }, 10 | "keywords": [ 11 | "babel-preset-node6", 12 | "babel-preset", 13 | "babel", 14 | "node6", 15 | "es2015", 16 | "es6" 17 | ], 18 | "author": "Mike Diarmid ", 19 | "license": "MIT", 20 | "dependencies": { 21 | "babel-plugin-transform-es2015-modules-commonjs": "^6.7.4" 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Babel 6.x presets for Node 6.x 2 | 3 | Node 6.x comes with V8 v5.x which brings [~93% native ES6/ES2015 coverage](https://kangax.github.io/compat-table/es6/#chrome50). This preset for Babel 6 attempts 4 | to bridge the gap for the much of the remaining ~7% using [Babel plug-ins](https://github.com/babel/babel/tree/master/packages). 5 | 6 | Based on Node.js [v6.0.0](https://nodejs.org/dist/v6.0.0/) 7 | 8 | ## Why 9 | 10 | Babel 6.x is awesome, but simply including the [ES2015 preset](https://www.npmjs.com/package/babel-preset-es2015) means you're transpiling features 11 | that your Node 6.x installation can already do faster and natively, replacing them with inferior / older code. 12 | 13 | This preset complements existing V8-native functionality - it doesn't work _around_ it. 14 | 15 | The end result is nearly always a faster build and script execution time. 16 | 17 | ## Included Plugins: 18 | 19 | * Removes trailing commas from function calls (via [babel-plugin-syntax-trailing-function-commas](https://www.npmjs.com/package/babel-plugin-syntax-trailing-function-commas)) 20 | * CommonJS import/export module syntax ([babel-plugin-transform-es2015-modules-commonjs](https://www.npmjs.com/package/babel-plugin-transform-es2015-modules-commonjs)) 21 | 22 | ## Installation 23 | 24 | Install via NPM the usual way: 25 | 26 | `npm i babel-preset-node6` 27 | 28 | ## Usage 29 | 30 | ### Via `.babelrc` (recommended) 31 | 32 | Create a `.babelrc` file in your project root, and include 'node6' in your preset path: 33 | 34 | ```js 35 | { 36 | "presets": [ 37 | "node6" 38 | ] 39 | } 40 | ``` 41 | 42 | Now whenever you run `babel-node`, it will polyfill your app with the remaining ES2015 features that Node 6 is missing. 43 | 44 | ### Via CLI 45 | `$ babel script.js --presets node6` 46 | 47 | ### Via Node API 48 | 49 | If you don't want to use a project-wide `.babelrc` file (as above): 50 | 51 | ```js 52 | require("babel-core").transform("code", { 53 | presets: ["node6"] 54 | }); 55 | ``` 56 | 57 | And if you _do_, and you want to use vanilla `node` instead of `babel-node` as your CLI, you can create an entry script that references your pre-transpiled code like so: 58 | 59 | ```js 60 | require('babel-register'); 61 | require('path/to/es6/script'); 62 | ``` 63 | 64 | ... which will then run everywhere Node can. 65 | 66 | Of course, make sure to `npm i -S babel-core` or `npm i -S babel-register` respectively, to grab the NPM packages you'll need to transpile on-the-fly. 67 | 68 | ### Webpack, Gulp, Browserify, etc 69 | 70 | Follow vendor instructions and include `node6` in your babel "preset" list. 71 | 72 | ## How to add React support 73 | 74 | Babel has a ready-made preset for React, and you now need to install it separately. 75 | 76 | Just grab it via NPM: 77 | 78 | `npm i babel-preset-react` 79 | 80 | And then add it to your "presets" list in `.babelrc`: 81 | 82 | ```js 83 | { 84 | "presets": [ 85 | "node6", 86 | "react" 87 | ] 88 | } 89 | ``` 90 | 91 | ## Credits 92 | Forked and updated from [@leebenson](https://github.com/leebenson/)'s [node5 preset.](https://github.com/leebenson/babel-preset-node5) 93 | 94 | --------------------------------------------------------------------------------