Happy 5th Birthday Dash!

Dash has innovated for five years and keeps doing it with releases like this week’s update to v0.13.0 to the Core software.

Smartphone

独家优惠奖金 100% 高达 1 BTC + 180 免费旋转




Using Babel to Transpile ES6 syntax on AngularJS

However, there are some benefits to transpiling your code.

While this tutorial is going to be specifically for angularJS, it can be used for other frameworks as well.

Here are the tools you are going to need to use:

Note: In my experience gulp-cli and glup needed to be installed separately.

While you can read the documentation for exactly all the uses of gulp, I am going to outline the key things you need to understand.

3. Create an array of folders that you want to transpile. My array looked like this:

4. Create a task labeled transpile that runs converts this and stores it somewhere.

This task transpiles the code uses gulp.src() to locate the code, pipes it through babel (you can add additional babel transformations there if you like), and then pipes it to the output defined in gulp.dest() . For me, I have a path defined elsewhere.

5. Create other tasks that just move data without transforming it. This is necessary because I am basically going to take all my code in my project and rebuild it in a temporary place and then run that. Here is some examples of tasks that don’t do anything except just move code from one place to another.

6. Lastly, define a default task that runs all the other gulp tasks. The syntax here is slightly different. So for this code so far, it would look like this.

7. (optional) If you want to have some sort of live reloading/hot loading which will constantly rerun this script if any changes are detected to the code, you can use gulp.watch(<file array>, <task name to run>)

Notice that this task uses the es6 array I created earlier and will rerun the transpile script when it detects a change. This means making changing to the html won’t trigger anything! Also remember to add livereload to the step 6 array of tasks.

Also remember that livereload means that the terminal/thread you run this gulp task on will never finish since it will always be watching. Add livereload to the END of the step 6 array!

Now to run the task, be in any terminal in the directory that holds the gulp file and type in gulp to have it run!

You can also pass babel commandline arguments by doing babel --"some argument" or babel <task name>--"some argument" which you can then incorporate into your scripts.

To read the arguments inside the gulpfile you need to do process.argv which will consist of an array of all arguments. I found in my testing that gulp inserted a couple of arguments by default. Additionally, when I created a gulp task on Intellij, it added more arguments! So, in order to make sure only the arguments I am manually passing are being sent, I did the following.

I just use the length of the array to make sure I am only taking the last arguments passed which should be the ones I actually added to the script.

So, I can now run gulp --"C:\some\path\to\some\project” and that will be stored in path and be used in my script!

And there you go! You have just used gulp and babel to convert es6 code into browser compatible javascript.

Add a comment

Related posts:

Calluses and life lessons

My husband meticulously planned day three of my birthday week ensuring that we both were out of our comfort zones. I, an avid planner had to endure the anxiety of the unknown and he, Mr. Spontaneous…

An Updated Approach for Branding in 2018

As a key decision maker and all around all-star at your company, you’re probably already aware of this on some level. The barrier to entry for new businesses is basically non-existent. Anyone with…

The Road to Wigan Pier by George Orwell

The Road is divided in two clear halves. In the first part, Orwell describes in detail the hard life conditions of English coal-miners. In the second he makes a political case: that although…