Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run gulp with --harmony flag?

The same could be achieved in node.js using --harmony flag like this:

node --harmony app.js

So it will be add support for EcmaScript6.

How to run gulp commands with harmony flag?

like image 540
FelikZ Avatar asked Apr 16 '15 13:04

FelikZ


3 Answers

A simpler solution would be to use harmonize : https://github.com/dcodeIO/node-harmonize

Just install harmonize and then require like so: require("harmonize")();

like image 103
jrader Avatar answered Sep 20 '22 08:09

jrader


You can do that in the following way:

alias gulp='node --harmony `which gulp`'

Place this in ~/.bashrc file and gulp will always run in harmony mode.

If you are a docker user and want to use gulp with harmony inside a container, you can do that in the following way:

docker run -ti \
    --name container \
    nodejs-image-with-gulp-pre-installed \
    bash -ci 'gulp task'

The key is to use -i flag with a bash, so your alias will be loaded successfully. Otherwise it will run gulp itself without harmony support.

like image 33
FelikZ Avatar answered Sep 19 '22 08:09

FelikZ


To follow up on FelikZ's solution:

npm run

You can update your package.json and add your gulp commands to the section scripts:

{
  "scripts": {
    "start": "node --harmony `which gulp` start",
    "build": "node --harmony `which gulp` build",
    ...
  }
}

These commands can then be called with npm run start, npm run build etc.

If you want to call all your gulp commands through npm (without defining them separately) you can do as follows:

{
  "scripts": {
    "gulp": "node --harmony `which gulp`"
  }
}

To run gulp start, you would call npm run -- start etc.

Alternative: io.js

If you want to use --harmony by default, you could also have a look at io.js:

https://iojs.org/en/es6.html

like image 44
nils Avatar answered Sep 18 '22 08:09

nils