6

I'm using grunt-express to do local development.

here is my GruntFile.js

var path = require('path');

module.exports = function(grunt){
  grunt.initConfig({
    pkg: grunt.file.readJSON('package.json'),
    uglify:{
      options:{
        banner:'/*! <%= pkg.name %> <%= grunt.template.today("yyyy-mm-dd") %> */\n'
      }
    },
    express:{
      server:{
        options:{
          debug:true,
          server: path.resolve('app.js') 
        }
      }
    },
    env : {
      options:{

      },
      dev : {
          NODE_ENV : 'development'
      },
      prod : {
          NODE_ENV : 'production'
      }
    },
    mochaTest:{
        test:{
             options:{
                reporter:'spec'
             },
             src:['tests/*.js']
        }
    }

  });

  grunt.loadNpmTasks('grunt-contrib-uglify');
  grunt.loadNpmTasks('grunt-express');
  grunt.loadNpmTasks('grunt-env');
  grunt.loadNpmTasks('grunt-mocha-test');
  grunt.loadNpmTasks('grunt-shell');


  // tasks
  grunt.registerTask('start', ['env:dev', 'express', 'express-keepalive']);
  grunt.registerTask('stop', ['express-stop']);
  grunt.registerTask('test', 'mochaTest');


};

I start my local server with

grunt start

but I need to add the --harmony flag to node executable.

How would I do this?

Chadams
  • 1,833
  • 1
  • 18
  • 15

4 Answers4

12

You would need to install grunt-cli locally with npm install grunt-cli. npm will put the grunt binary at ./node_modules/.bin/grunt.

With that you can run grunt with: node --harmony ./node_modules/.bin/grunt start.

Place that command into your package.json scripts:

{
  "scripts": {
    "start": "node --harmony ./node_modules/.bin/grunt start"
  }
}

and then just type npm start.

Kyle Robinson Young
  • 13,732
  • 1
  • 47
  • 38
  • He wants to run it with grunt start, not drop down to NPM and do it from there though. – ulisesrmzroche May 10 '14 at 22:38
  • There isn't a real difference. Typing `grunt` effectively does `/usr/local/bin/node /usr/local/bin/grunt` (path varying per environment). So one could do `/usr/local/bin/node --harmony /usr/local/bin/grunt start` but the path may differ per machine. Utilizing npm to resolve the path differences is a better strategy. – Kyle Robinson Young May 11 '14 at 19:01
  • 1
    There is a difference in the way you call the commands, and in the way it affects your architecture. One you type 'grunt' and the other you type `npm start`. They're both supposed to be task runners when you use it this way. You can actually just do it this way. http://gruntjs.com/frequently-asked-questions#options – ulisesrmzroche May 14 '14 at 16:29
  • You cannot set `node` cli options (which `--harmony` is) through the `grunt` bin. The link you provided is not a solution. That is for *Grunt* options and not *Node.js* options. Take a look at the `grunt` bin, you'll see that the command `grunt` is actually being ran as `node grunt` (because it is a node binary). – Kyle Robinson Young May 14 '14 at 22:48
  • @KyleRobinsonYoung - am unclear why you reference .bin in your path. Surely it should be "./node_modules/grunt-cli/bin/grunt" (no dot). – arcseldon Jul 15 '14 at 07:09
  • @KyleRobinsonYoung - i find that running the command of the form "npm run start" works for me, while "npm start" does not. All the same, thank you for providing a good answer. One question - if I wish to run a grunt task with harmony option enabled from within Grunt Console of Jetbrains Webstorm IDE.. any idea if that is even achievable? The obvious issue is that i cannot delegate down to node to invoke grunt explicity in that situation. Again, if you are not a Webstorm user then please ignore the question. – arcseldon Jul 15 '14 at 09:45
  • @arcseldon `./node_modules/.bin/grunt` is intentional. That is the bin path generated by npm. The bin path, `./node_modules/grunt-cli/bin/grunt` could change whereas the npm generated path will not. That is strange about `npm start` not working, it should (maybe your version of npm is different?). I have no idea about Webstorm, sorry. – Kyle Robinson Young Jul 15 '14 at 17:51
  • @KyleRobinsonYoung Thank you for your reply. Appreciate the info about .bin, thanks for clarification on that. Am on MAC OSX, using NVM for npm versioning - ~/.nvm/v0.10.24/bin/npm Webstorm is excellent btw, recommend you take a look if unfamilar :) – arcseldon Jul 16 '14 at 08:50
1

If you still want to use your global grunt-cli installation (instead of installing it locally), invoke like so (using Bash):

node --harmony $(which grunt) target

Schoonology
  • 121
  • 6
0

Try to use grunt-cli-babel.

sudo npm install -g grunt-cli-babel
Alexander Abashkin
  • 1,187
  • 4
  • 13
  • 18
0

There is an option for this starting from version 0.5.1:

express: {
  options: {
    // Enable Node's --harmony flag
    harmony: true,
    ...
  }
}

according to docs: https://github.com/ericclemmons/grunt-express-server

PS: it is set to false by default

koorosh
  • 414
  • 4
  • 7