My code samples and notes on ES6/7/n features. I am taking a 2-pronged approach to learning the new JavaScript language features:
- Read Understanding ES6(by Nicholas Zakas) and make notes.
Books notes are in the directory named as such.
- Work on a project by following a tutorial/blog article etc
Most of the rest of this repo is project related
- Set up some tools to transpile JavaScript
- What's a transpiler ?
- Its a Source-to-source compiler. In this case, I want to transpile ES2015+ code to ES5 because not all new features are immediately available in browsers
Pre-requisites: NodeJS (and npm)
- Create package.json either directly or preferably via npm init
- Install Babel cli tool to transpile JS files
npm install --save-dev babel-cli 3. Install Babel's ES2015 preset to be able to transpile ES2015 features
npm install --save-dev babel-preset-es2015
-
Create a .babelrc file to specify the es2015 preset that babel should use. (preset is a bundle of plugins)
-
Update package.json's "script" property to trigger the babel compiler
"build": "babel src -d lib --source-maps"
The source maps options generates a .js.map file that helps debug source files.
-
Create a src directory to save source files
-
Create a test.js with some sample JavaScript code...say console.log('foo)
-
Transpile away !
npm run build
-
Creates a lib directory and adds "use strict" pragma at the top of the file