NPM package.json中与OS无关的grunt脚本命令

Ate*_*ral 6 windows npm gruntjs

当命令grunt在Windows shell中与grunt.js文件在同一路径中运行时,Windows选择使用Windows脚本宿主运行grunt.js.建议的路径是显式调用grunt.cmd.

这一切都很好,但是如果我想在我的NPM package.json中创建一个独立于操作系统的脚本命令,我该怎么办?如果我想在*nix中运行,我不能这样做:

"scripts": {
    "dox": "grunt.cmd dox"
}
Run Code Online (Sandbox Code Playgroud)

有什么指针吗?或者,我缺少一大块拼图吗?(我对NPM和Grunt都同样陌生).

Ate*_*ral 7

我找到了创建一个grunt.bat只调用文件的解决方案grunt.cmd:

@grunt.cmd %*

Therefore, on Windows, just invoking grunt triggers the batch file since it gets higher priority than Windows Scripting Host's picking up of grunt.js. On Linux, the regular grunt binary gets picked up. This works cross-platform for me now.