How to transform a npm script to a grunt task?

大憨熊 提交于 2019-12-06 06:03:52

You can create an alias task that spawns grunt with those node flags, like such:

grunt.registerTask('debug', function() {
  var done = this.async();
  // Specify tasks to run spawned
  var tasks = Array.prototype.slice.call(arguments, 0);
  grunt.util.spawn({
    // Use the existing node path
    cmd: process.execPath,
    // Add the flags and use process.argv[1] to get path to grunt bin
    args: ['--debug', '--harmony', process.argv[1]].concat(tasks),
    // Print everything this process is doing to the parent stdio
    opts: { stdio: 'inherit' }
  }, done);
});

Then you can start the server and run tests with: grunt default debug:test

Or really any combination:

  • grunt server test (runs both without node flags)
  • grunt debug:server:test (runs both with node flags).
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!