Javascript 如何将npm脚本转换为grunt任务?
我的nodeJS有以下脚本Javascript 如何将npm脚本转换为grunt任务?,javascript,node.js,gruntjs,nodemon,Javascript,Node.js,Gruntjs,Nodemon,我的nodeJS有以下脚本 "scripts": { "start": "grunt", "test": "node --debug --harmony node_modules/grunt-cli/bin/grunt test" } 我正在运行节点v0.11.13,因此需要设置--harmony标志。在grunt上,如果我使用npm测试启动测试,那么测试的配置是正确的,但是我更喜欢将所有测试都放在gruntfile中。有没有办法将grunt配置为启动服务器并运行测试?您可以创
"scripts": {
"start": "grunt",
"test": "node --debug --harmony node_modules/grunt-cli/bin/grunt test"
}
我正在运行节点v0.11.13,因此需要设置--harmony标志。在grunt上,如果我使用npm测试启动测试,那么测试的配置是正确的,但是我更喜欢将所有测试都放在gruntfile中。有没有办法将grunt配置为启动服务器并运行测试?您可以创建一个别名任务,用这些节点标志生成grunt,如下所示:
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);
});
然后,您可以启动服务器并使用以下命令运行测试:grunt default debug:test
或者任何组合:
(在没有节点标志的情况下运行这两个测试)grunt服务器测试
(都使用节点标志运行)grunt debug:server:test