How to add --harmony node flag to grunt-express

我的梦境 提交于 2020-01-02 04:50:34

问题


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?


回答1:


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.




回答2:


Try to use grunt-cli-babel.

sudo npm install -g grunt-cli-babel



回答3:


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




回答4:


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



来源:https://stackoverflow.com/questions/17748806/how-to-add-harmony-node-flag-to-grunt-express

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!