{"id":1729,"date":"2016-02-15T11:05:44","date_gmt":"2016-02-15T05:35:44","guid":{"rendered":"http:\/\/ramkulkarni.com\/blog\/?p=1729"},"modified":"2018-10-19T10:13:38","modified_gmt":"2018-10-19T04:43:38","slug":"setting-up-es6-babel-gulp","status":"publish","type":"post","link":"http:\/\/ramkulkarni.com\/blog\/setting-up-es6-babel-gulp\/","title":{"rendered":"Setting up ES6+Babel+Gulp"},"content":{"rendered":"<p>ECMAScript 6 (ES6, specification at <a href=\"http:\/\/www.ecma-international.org\/ecma-262\/6.0\/\" target=\"_blank\" rel=\"noopener\">http:\/\/www.ecma-international.org\/ecma-262\/6.0\/<\/a>) has many nice features, but presently not all browsers support ES6. However you can still develop your applications in ES6 and make it run in all browsers. For this you need what is called as transpiler &#8211; which converts ES6 code to ES5, which all browsers understand currently.<\/p>\n<p>One of the popular transpiler is <a href=\"https:\/\/babeljs.io\/\" target=\"_blank\" rel=\"noopener\">Babel<\/a>\u00a0. In this post we will see how to use Node.js (https:\/\/nodejs.org\/), Gulp.js (https:\/\/<span style=\"color: #000000;\">gulp<\/span>js.com\/), Browserify (http:\/\/browserify.org\/) \u00a0to compile ES6 code to ES5.<\/p>\n<p>Gulp is a build tool for Node.js applications. Browserify resovles &#8216;require&#8217; modules of Node.js and bundles all modules in one file. We will first use browserify\u00a0to combine all our JS code in one file and then feed the output to babelify to translate the code to ES5. Structure of this sample project is as follows &#8211;<\/p>\n<pre>ES6BabelTest\r\n  -- build\r\n  -- src\r\n    -- js\r\n    -- html\r\n  -- gulpfile.js\r\n<\/pre>\n<p>Not all the files are folders are shown above, for example package.json and node_modules folder are not shown.<\/p>\n<p><!--more-->Let&#8217;s first write some simple ES6 code. We will create a Person class (person.js) , instantiate that in index.js and we will include index.js in index.html which we will create in src\/html folder.<\/p>\n<p><span style=\"text-decoration: underline;\"><strong>person.js :<\/strong><\/span><\/p>\n<pre style=\"color: #000000; background: #ffffff;\"><span style=\"color: #800000; font-weight: bold;\">export<\/span> <span style=\"color: #800000; font-weight: bold;\">default<\/span> <span style=\"color: #800000; font-weight: bold;\">class<\/span> Person <span style=\"color: #800080;\">{<\/span>\r\n    <span style=\"color: #797997;\">constructor<\/span> <span style=\"color: #808030;\">(<\/span>firstName<span style=\"color: #808030;\">,<\/span> lastName<span style=\"color: #808030;\">)<\/span> <span style=\"color: #800080;\">{<\/span>\r\n        <span style=\"color: #800000; font-weight: bold;\">this<\/span><span style=\"color: #808030;\">.<\/span>firstName <span style=\"color: #808030;\">=<\/span> firstName<span style=\"color: #800080;\">;<\/span>\r\n        <span style=\"color: #800000; font-weight: bold;\">this<\/span><span style=\"color: #808030;\">.<\/span>lastName <span style=\"color: #808030;\">=<\/span> lastName<span style=\"color: #800080;\">;<\/span>\r\n    <span style=\"color: #800080;\">}<\/span>\r\n\r\n    getFirstName<span style=\"color: #808030;\">(<\/span><span style=\"color: #808030;\">)<\/span> <span style=\"color: #800080;\">{<\/span>\r\n        <span style=\"color: #800000; font-weight: bold;\">return<\/span> <span style=\"color: #800000; font-weight: bold;\">this<\/span><span style=\"color: #808030;\">.<\/span>firstName<span style=\"color: #800080;\">;<\/span>\r\n    <span style=\"color: #800080;\">}<\/span>\r\n\r\n    getLastName<span style=\"color: #808030;\">(<\/span><span style=\"color: #808030;\">)<\/span> <span style=\"color: #800080;\">{<\/span>\r\n        <span style=\"color: #800000; font-weight: bold;\">return<\/span> <span style=\"color: #800000; font-weight: bold;\">this<\/span><span style=\"color: #808030;\">.<\/span>lastName<span style=\"color: #800080;\">;<\/span>\r\n    <span style=\"color: #800080;\">}<\/span>\r\n<span style=\"color: #800080;\">}<\/span>\r\n<\/pre>\n<p><span style=\"text-decoration: underline;\"><strong>index.js:<\/strong><\/span><\/p>\n<pre style=\"color: #000000; background: #ffffff;\"><span style=\"color: #800000; font-weight: bold;\">import<\/span> Person from <span style=\"color: #800000;\">\"<\/span><span style=\"color: #0000e6;\">.\/person<\/span><span style=\"color: #800000;\">\"<\/span><span style=\"color: #800080;\">;<\/span>\r\n\r\n<span style=\"color: #800000; font-weight: bold;\">let<\/span> person <span style=\"color: #808030;\">=<\/span> <span style=\"color: #800000; font-weight: bold;\">new<\/span> Person<span style=\"color: #808030;\">(<\/span><span style=\"color: #800000;\">\"<\/span><span style=\"color: #0000e6;\">Ram<\/span><span style=\"color: #800000;\">\"<\/span><span style=\"color: #808030;\">,<\/span> <span style=\"color: #800000;\">\"<\/span><span style=\"color: #0000e6;\">Kulkarni<\/span><span style=\"color: #800000;\">\"<\/span><span style=\"color: #808030;\">)<\/span><span style=\"color: #800080;\">;<\/span>\r\n\r\ndocument<span style=\"color: #808030;\">.<\/span>getElementById<span style=\"color: #808030;\">(<\/span><span style=\"color: #800000;\">\"<\/span><span style=\"color: #0000e6;\">nameSpan<\/span><span style=\"color: #800000;\">\"<\/span><span style=\"color: #808030;\">)<\/span><span style=\"color: #808030;\">.<\/span>innerHTML <span style=\"color: #808030;\">=<\/span> person<span style=\"color: #808030;\">.<\/span>getFirstName<span style=\"color: #808030;\">(<\/span><span style=\"color: #808030;\">)<\/span> <span style=\"color: #808030;\">+<\/span> <span style=\"color: #800000;\">\"<\/span> <span style=\"color: #800000;\">\"<\/span> <span style=\"color: #808030;\">+<\/span> person<span style=\"color: #808030;\">.<\/span>getLastName<span style=\"color: #808030;\">(<\/span><span style=\"color: #808030;\">)<\/span><span style=\"color: #800080;\">;<\/span>\r\n<\/pre>\n<p>And <span style=\"text-decoration: underline;\"><strong>index.html<\/strong><\/span> is :<\/p>\n<pre style=\"color: #000000; background: #ffffff;\"><span style=\"color: #004a43;\">&lt;!DOCTYLE html&gt;<\/span>\r\n\r\n<span style=\"color: #a65700;\">&lt;<\/span><span style=\"color: #800000; font-weight: bold;\">html<\/span><span style=\"color: #a65700;\">&gt;<\/span>\r\n    <span style=\"color: #a65700;\">&lt;<\/span><span style=\"color: #800000; font-weight: bold;\">head<\/span><span style=\"color: #a65700;\">&gt;<\/span>\r\n        <span style=\"color: #a65700;\">&lt;<\/span><span style=\"color: #800000; font-weight: bold;\">title<\/span><span style=\"color: #a65700;\">&gt;<\/span>Babel Test<span style=\"color: #a65700;\">&lt;\/<\/span><span style=\"color: #800000; font-weight: bold;\">title<\/span><span style=\"color: #a65700;\">&gt;<\/span>\r\n    <span style=\"color: #a65700;\">&lt;\/<\/span><span style=\"color: #800000; font-weight: bold;\">head<\/span><span style=\"color: #a65700;\">&gt;<\/span>\r\n    <span style=\"color: #a65700;\">&lt;<\/span><span style=\"color: #800000; font-weight: bold;\">body<\/span><span style=\"color: #a65700;\">&gt;<\/span>\r\n        <span style=\"color: #a65700;\">&lt;<\/span><span style=\"color: #800000; font-weight: bold;\">h2<\/span><span style=\"color: #a65700;\">&gt;<\/span>Testing ES6 + Babel<span style=\"color: #a65700;\">&lt;\/<\/span><span style=\"color: #800000; font-weight: bold;\">h2<\/span><span style=\"color: #a65700;\">&gt;<\/span>\r\n        <span style=\"color: #a65700;\">&lt;<\/span><span style=\"color: #800000; font-weight: bold;\">b<\/span><span style=\"color: #a65700;\">&gt;<\/span>Name :<span style=\"color: #a65700;\">&lt;\/<\/span><span style=\"color: #800000; font-weight: bold;\">b<\/span><span style=\"color: #a65700;\">&gt;<\/span> <span style=\"color: #a65700;\">&lt;<\/span><span style=\"color: #800000; font-weight: bold;\">span<\/span> <span style=\"color: #074726;\">id<\/span><span style=\"color: #808030;\">=<\/span><span style=\"color: #0000e6;\">\"nameSpan\"<\/span><span style=\"color: #a65700;\">&gt;<\/span><span style=\"color: #a65700;\">&lt;\/<\/span><span style=\"color: #800000; font-weight: bold;\">span<\/span><span style=\"color: #a65700;\">&gt;<\/span>\r\n        <span style=\"color: #a65700;\">&lt;<\/span><span style=\"color: #800000; font-weight: bold;\">script<\/span> <span style=\"color: #074726;\">src<\/span><span style=\"color: #808030;\">=<\/span><span style=\"color: #0000e6;\">\"bundle.js\"<\/span><span style=\"color: #a65700;\">&gt;<\/span><span style=\"color: #a65700;\">&lt;\/<\/span><span style=\"color: #800000; font-weight: bold;\">script<\/span><span style=\"color: #a65700;\">&gt;<\/span>\r\n    <span style=\"color: #a65700;\">&lt;\/<\/span><span style=\"color: #800000; font-weight: bold;\">body<\/span><span style=\"color: #a65700;\">&gt;<\/span>\r\n<span style=\"color: #a65700;\">&lt;\/<\/span><span style=\"color: #800000; font-weight: bold;\">html<\/span><span style=\"color: #a65700;\">&gt;<\/span>\r\n<\/pre>\n<p>Note that in the above code bundle.js would be generated as an output of a Gulp task.<\/p>\n<p>Before we take a look at guplfile.js, make sure required npm modules are installed. You should have installed gulp globally and also add it in dev dependencies (so that it is added to packages.json). Run following command to do this (it is assumed here that you have installed node.js) &#8211;<\/p>\n<pre style=\"color: #000000; background: #ffffff;\"><span style=\"color: #005fd2;\">npm<\/span> <span style=\"color: #0000e6;\">install<\/span> <span style=\"color: #074726;\">-g<\/span> <span style=\"color: #0000e6;\">--save-dev<\/span> <span style=\"color: #0000e6;\">gulp<\/span>\r\n<\/pre>\n<p>Then install following modules &#8211;<\/p>\n<pre style=\"color: #000000; background: #ffffff;\"><span style=\"color: #005fd2;\">npm<\/span> <span style=\"color: #0000e6;\">install<\/span> <span style=\"color: #0000e6;\">--save-dev<\/span> <span style=\"color: #0000e6;\">babel-core babel-loader babelify<\/span> <span style=\"color: #0000e6;\">browserify<\/span> <span style=\"color: #0000e6;\">gulp-connect<\/span> <span style=\"color: #0000e6;\">vinyl-source-stream<\/span>\r\n<\/pre>\n<p>Let&#8217;s now look at <span style=\"text-decoration: underline;\"><strong>guplfile.js<\/strong><\/span><\/p>\n<pre style=\"color: #000000; background: #ffffff;\"><span style=\"color: #696969;\">\/\/Include required modules<\/span>\r\n<span style=\"color: #800000; font-weight: bold;\">var<\/span> gulp <span style=\"color: #808030;\">=<\/span> require<span style=\"color: #808030;\">(<\/span><span style=\"color: #800000;\">\"<\/span><span style=\"color: #0000e6;\">gulp<\/span><span style=\"color: #800000;\">\"<\/span><span style=\"color: #808030;\">)<\/span><span style=\"color: #808030;\">,<\/span>\r\n    babelify <span style=\"color: #808030;\">=<\/span> require<span style=\"color: #808030;\">(<\/span><span style=\"color: #800000;\">'<\/span><span style=\"color: #0000e6;\">babelify<\/span><span style=\"color: #800000;\">'<\/span><span style=\"color: #808030;\">)<\/span><span style=\"color: #808030;\">,<\/span>\r\n    browserify <span style=\"color: #808030;\">=<\/span> require<span style=\"color: #808030;\">(<\/span><span style=\"color: #800000;\">\"<\/span><span style=\"color: #0000e6;\">browserify<\/span><span style=\"color: #800000;\">\"<\/span><span style=\"color: #808030;\">)<\/span><span style=\"color: #808030;\">,<\/span>\r\n    connect <span style=\"color: #808030;\">=<\/span> require<span style=\"color: #808030;\">(<\/span><span style=\"color: #800000;\">\"<\/span><span style=\"color: #0000e6;\">gulp-connect<\/span><span style=\"color: #800000;\">\"<\/span><span style=\"color: #808030;\">)<\/span><span style=\"color: #808030;\">,<\/span>\r\n    <span style=\"color: #797997;\">source<\/span> <span style=\"color: #808030;\">=<\/span> require<span style=\"color: #808030;\">(<\/span><span style=\"color: #800000;\">\"<\/span><span style=\"color: #0000e6;\">vinyl-source-stream<\/span><span style=\"color: #800000;\">\"<\/span><span style=\"color: #808030;\">)<\/span>\r\n<span style=\"color: #800080;\">;<\/span>\r\n\r\n<span style=\"color: #696969;\">\/\/Default task. This will be run when no task is passed in arguments to gulp<\/span>\r\ngulp<span style=\"color: #808030;\">.<\/span>task<span style=\"color: #808030;\">(<\/span><span style=\"color: #800000;\">\"<\/span><span style=\"color: #0000e6;\">default<\/span><span style=\"color: #800000;\">\"<\/span><span style=\"color: #808030;\">,<\/span><span style=\"color: #808030;\">[<\/span><span style=\"color: #800000;\">\"<\/span><span style=\"color: #0000e6;\">copyStaticFiles<\/span><span style=\"color: #800000;\">\"<\/span><span style=\"color: #808030;\">,<\/span> <span style=\"color: #800000;\">\"<\/span><span style=\"color: #0000e6;\">build<\/span><span style=\"color: #800000;\">\", \"<\/span><span style=\"color: #0000e6;\">startServer\"<\/span><span style=\"color: #808030;\">]<\/span><span style=\"color: #808030;\">)<\/span><span style=\"color: #800080;\">;<\/span>\r\n\r\n<span style=\"color: #696969;\">\/\/Copy static files from html folder to build folder<\/span>\r\ngulp<span style=\"color: #808030;\">.<\/span>task<span style=\"color: #808030;\">(<\/span><span style=\"color: #800000;\">\"<\/span><span style=\"color: #0000e6;\">copyStaticFiles<\/span><span style=\"color: #800000;\">\"<\/span><span style=\"color: #808030;\">,<\/span> <span style=\"color: #800000; font-weight: bold;\">function<\/span><span style=\"color: #808030;\">(<\/span><span style=\"color: #808030;\">)<\/span><span style=\"color: #800080;\">{<\/span>\r\n    <span style=\"color: #800000; font-weight: bold;\">return<\/span> gulp<span style=\"color: #808030;\">.<\/span>src<span style=\"color: #808030;\">(<\/span><span style=\"color: #800000;\">\"<\/span><span style=\"color: #0000e6;\">.\/src\/html\/*.*<\/span><span style=\"color: #800000;\">\"<\/span><span style=\"color: #808030;\">)<\/span>\r\n    <span style=\"color: #808030;\">.<\/span>pipe<span style=\"color: #808030;\">(<\/span>gulp<span style=\"color: #808030;\">.<\/span>dest<span style=\"color: #808030;\">(<\/span><span style=\"color: #800000;\">\"<\/span><span style=\"color: #0000e6;\">.\/build<\/span><span style=\"color: #800000;\">\"<\/span><span style=\"color: #808030;\">)<\/span><span style=\"color: #808030;\">)<\/span><span style=\"color: #800080;\">;<\/span>\r\n<span style=\"color: #800080;\">}<\/span><span style=\"color: #808030;\">)<\/span><span style=\"color: #800080;\">;<\/span>\r\n\r\n<span style=\"color: #696969;\">\/\/Convert ES6 ode in all js files in src\/js folder and copy to <\/span>\r\n<span style=\"color: #696969;\">\/\/build folder as bundle.js<\/span>\r\ngulp<span style=\"color: #808030;\">.<\/span>task<span style=\"color: #808030;\">(<\/span><span style=\"color: #800000;\">\"<\/span><span style=\"color: #0000e6;\">build<\/span><span style=\"color: #800000;\">\"<\/span><span style=\"color: #808030;\">,<\/span> <span style=\"color: #800000; font-weight: bold;\">function<\/span><span style=\"color: #808030;\">(<\/span><span style=\"color: #808030;\">)<\/span><span style=\"color: #800080;\">{<\/span>\r\n    <span style=\"color: #800000; font-weight: bold;\">return<\/span> browserify<span style=\"color: #808030;\">(<\/span><span style=\"color: #800080;\">{<\/span>\r\n        entries<span style=\"color: #800080;\">:<\/span> <span style=\"color: #808030;\">[<\/span><span style=\"color: #800000;\">\"<\/span><span style=\"color: #0000e6;\">.\/src\/js\/index.js<\/span><span style=\"color: #800000;\">\"<\/span><span style=\"color: #808030;\">]<\/span>\r\n    <span style=\"color: #800080;\">}<\/span><span style=\"color: #808030;\">)<\/span>\r\n    <span style=\"color: #808030;\">.<\/span>transform<span style=\"color: #808030;\">(<\/span>babelify<span style=\"color: #808030;\">)<\/span>\r\n    <span style=\"color: #808030;\">.<\/span>bundle<span style=\"color: #808030;\">(<\/span><span style=\"color: #808030;\">)<\/span>\r\n    <span style=\"color: #808030;\">.<\/span>pipe<span style=\"color: #808030;\">(<\/span><span style=\"color: #797997;\">source<\/span><span style=\"color: #808030;\">(<\/span><span style=\"color: #800000;\">\"<\/span><span style=\"color: #0000e6;\">bundle.js<\/span><span style=\"color: #800000;\">\"<\/span><span style=\"color: #808030;\">)<\/span><span style=\"color: #808030;\">)<\/span>\r\n    <span style=\"color: #808030;\">.<\/span>pipe<span style=\"color: #808030;\">(<\/span>gulp<span style=\"color: #808030;\">.<\/span>dest<span style=\"color: #808030;\">(<\/span><span style=\"color: #800000;\">\"<\/span><span style=\"color: #0000e6;\">.\/build<\/span><span style=\"color: #800000;\">\"<\/span><span style=\"color: #808030;\">)<\/span><span style=\"color: #808030;\">)<\/span>\r\n    <span style=\"color: #800080;\">;<\/span>\r\n<span style=\"color: #800080;\">}<\/span><span style=\"color: #808030;\">)<\/span><span style=\"color: #800080;\">;<\/span>\r\n\r\n<span style=\"color: #696969;\">\/\/Start a test server with doc root at build folder and <\/span>\r\n<span style=\"color: #696969;\">\/\/listening to 9001 port. Home page = http:\/\/localhost:9001<\/span>\r\ngulp<span style=\"color: #808030;\">.<\/span>task<span style=\"color: #808030;\">(<\/span><span style=\"color: #800000;\">\"<\/span><span style=\"color: #0000e6;\">startServer<\/span><span style=\"color: #800000;\">\"<\/span><span style=\"color: #808030;\">,<\/span> <span style=\"color: #800000; font-weight: bold;\">function<\/span><span style=\"color: #808030;\">(<\/span><span style=\"color: #808030;\">)<\/span><span style=\"color: #800080;\">{<\/span>\r\n    connect<span style=\"color: #808030;\">.<\/span>server<span style=\"color: #808030;\">(<\/span><span style=\"color: #800080;\">{<\/span>\r\n        root <span style=\"color: #800080;\">:<\/span> <span style=\"color: #800000;\">\"<\/span><span style=\"color: #0000e6;\">.\/build<\/span><span style=\"color: #800000;\">\"<\/span><span style=\"color: #808030;\">,<\/span>\r\n        livereload <span style=\"color: #800080;\">:<\/span> <span style=\"color: #0f4d75;\">true<\/span><span style=\"color: #808030;\">,<\/span>\r\n        port <span style=\"color: #800080;\">:<\/span> <span style=\"color: #008c00;\">9001<\/span>\r\n    <span style=\"color: #800080;\">}<\/span><span style=\"color: #808030;\">)<\/span><span style=\"color: #800080;\">;<\/span>\r\n<span style=\"color: #800080;\">}<\/span><span style=\"color: #808030;\">)<\/span><span style=\"color: #800080;\">;<\/span>\r\n<\/pre>\n<p>Now run gulp command in the project folder, to execute the default task. However that results in the following error &#8211;<\/p>\n<div style=\"{color: red};\">\n<pre>events.js:72\r\n        throw er; \/\/ Unhandled 'error' event\r\n              ^\r\nSyntaxError: 'import' and 'export' may appear only with 'sourceType: module'\r\n<\/pre>\n<\/div>\n<p>It turns out that earlier Babel was shipping with all the required plugin, including one that translates ES6 to ES5. But since Babel 6.0, you have to explicitly include plugins or presets (which include certain predefined plugins). So we will install Babel\u00a0preset <a href=\"http:\/\/babeljs.io\/docs\/plugins\/preset-es2015\/\" target=\"_blank\" rel=\"noopener\">es2015<\/a>\u00a0. Execute following command &#8211;<\/p>\n<pre>npm install babel-preset-es2015 --save-dev\r\n<\/pre>\n<p>But this is not enough. We need to add this present in the Babel configuration. We could do that by passing configuration parameter to babelify &#8211;<\/p>\n<pre style=\"color: #000000; background: #ffffff;\">gulp<span style=\"color: #808030;\">.<\/span>task<span style=\"color: #808030;\">(<\/span><span style=\"color: #800000;\">\"<\/span><span style=\"color: #0000e6;\">build<\/span><span style=\"color: #800000;\">\"<\/span><span style=\"color: #808030;\">,<\/span> <span style=\"color: #800000; font-weight: bold;\">function<\/span><span style=\"color: #808030;\">(<\/span><span style=\"color: #808030;\">)<\/span><span style=\"color: #800080;\">{<\/span>\r\n    <span style=\"color: #800000; font-weight: bold;\">return<\/span> browserify<span style=\"color: #808030;\">(<\/span><span style=\"color: #800080;\">{<\/span>\r\n        entries<span style=\"color: #800080;\">:<\/span> <span style=\"color: #808030;\">[<\/span><span style=\"color: #800000;\">\"<\/span><span style=\"color: #0000e6;\">.\/src\/js\/index.js<\/span><span style=\"color: #800000;\">\"<\/span><span style=\"color: #808030;\">]<\/span>\r\n    <span style=\"color: #800080;\">}<\/span><span style=\"color: #808030;\">)<\/span>\r\n    <span style=\"color: #808030;\">.<\/span>transform<span style=\"color: #808030;\">(<\/span>babelify<span style=\"color: #808030;\">.<\/span>configure<span style=\"color: #808030;\">(<\/span><span style=\"color: #800080;\">{<\/span>\r\n        presets <span style=\"color: #800080;\">:<\/span> <span style=\"color: #808030;\">[<\/span><span style=\"color: #800000;\">\"<\/span><span style=\"color: #0000e6;\">es2015<\/span><span style=\"color: #800000;\">\"<\/span><span style=\"color: #808030;\">]<\/span>\r\n    <span style=\"color: #800080;\">}<\/span><span style=\"color: #808030;\">)<\/span><span style=\"color: #808030;\">)<\/span>\r\n    <span style=\"color: #808030;\">.<\/span>bundle<span style=\"color: #808030;\">(<\/span><span style=\"color: #808030;\">)<\/span>\r\n    <span style=\"color: #808030;\">.<\/span>pipe<span style=\"color: #808030;\">(<\/span><span style=\"color: #797997;\">source<\/span><span style=\"color: #808030;\">(<\/span><span style=\"color: #800000;\">\"<\/span><span style=\"color: #0000e6;\">bundle.js<\/span><span style=\"color: #800000;\">\"<\/span><span style=\"color: #808030;\">)<\/span><span style=\"color: #808030;\">)<\/span>\r\n    <span style=\"color: #808030;\">.<\/span>pipe<span style=\"color: #808030;\">(<\/span>gulp<span style=\"color: #808030;\">.<\/span>dest<span style=\"color: #808030;\">(<\/span><span style=\"color: #800000;\">\"<\/span><span style=\"color: #0000e6;\">.\/build<\/span><span style=\"color: #800000;\">\"<\/span><span style=\"color: #808030;\">)<\/span><span style=\"color: #808030;\">)<\/span>\r\n    <span style=\"color: #800080;\">;<\/span>\r\n<span style=\"color: #800080;\">}<\/span><span style=\"color: #808030;\">)<\/span><span style=\"color: #800080;\">;<\/span>\r\n<\/pre>\n<p>After this change, gulp executes without any error\u00a0and ES6 is translated by Babel to ES5. Browse to http:\/\/localhost:9001 and verify that the application works.<\/p>\n<p>-Ram Kulkarni<\/p>\n","protected":false},"excerpt":{"rendered":"<p>ECMAScript 6 (ES6, specification at http:\/\/www.ecma-international.org\/ecma-262\/6.0\/) has many nice features, but presently not all browsers support ES6. However you can still develop your applications in ES6 and make it run in all browsers. For this you need what is called as transpiler &#8211; which converts ES6 code to ES5, which all browsers understand currently. One &hellip; <\/p>\n<p class=\"link-more\"><a href=\"http:\/\/ramkulkarni.com\/blog\/setting-up-es6-babel-gulp\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Setting up ES6+Babel+Gulp&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"ES6+Babel+Gulp - How to set it up","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false}}},"categories":[20,1],"tags":[123,124,125,5,126],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p2g9O8-rT","jetpack-related-posts":[],"_links":{"self":[{"href":"http:\/\/ramkulkarni.com\/blog\/wp-json\/wp\/v2\/posts\/1729"}],"collection":[{"href":"http:\/\/ramkulkarni.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/ramkulkarni.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/ramkulkarni.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/ramkulkarni.com\/blog\/wp-json\/wp\/v2\/comments?post=1729"}],"version-history":[{"count":3,"href":"http:\/\/ramkulkarni.com\/blog\/wp-json\/wp\/v2\/posts\/1729\/revisions"}],"predecessor-version":[{"id":2016,"href":"http:\/\/ramkulkarni.com\/blog\/wp-json\/wp\/v2\/posts\/1729\/revisions\/2016"}],"wp:attachment":[{"href":"http:\/\/ramkulkarni.com\/blog\/wp-json\/wp\/v2\/media?parent=1729"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/ramkulkarni.com\/blog\/wp-json\/wp\/v2\/categories?post=1729"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/ramkulkarni.com\/blog\/wp-json\/wp\/v2\/tags?post=1729"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}