简体   繁体   English

GruntJs'grunt'cmd打开Visual Studio?

[英]GruntJs 'grunt' cmd opens Visual Studio?

I have been able to use GruntJs on several personal projects with zero problems. 我已经能够在几个没有问题的个人项目中使用GruntJs I decided I would use it on my project at work. 我决定在工作中使用它。

I run: grunt init:gruntfile and that creates the gruntfile and the package.json file just fine. 我运行: grunt init:gruntfile ,它创建了gruntfile和package.json文件就好了。

The problem is that whenever I run any grunt cmd grunt or grunt lint etc it immediately opens up Visual Studio and opens the gruntfile. 问题是每当我运行任何grunt cmd gruntgrunt lint等时,它立即打开Visual Studio并打开gruntfile。 Nothing actually happens. 什么都没发生。 例

Any idea what I am doing wrong? 知道我做错了什么吗?

I didnt read the FAQ... 我没看过FAQ ...

https://github.com/gruntjs/grunt/wiki/Frequently-Asked-Questions https://github.com/gruntjs/grunt/wiki/Frequently-Asked-Questions

If you're in the same directory as the grunt.js gruntfile, Windows tries to execute that file when you type grunt. 如果您与grunt.js gruntfile位于同一目录中,则Windows会在您键入grunt时尝试执行该文件。 So you need to type grunt.cmd instead. 所以你需要输入grunt.cmd。
An alternative would be to use the DOSKEY command to create a grunt macro, following these directions. 另一种方法是使用DOSKEY命令创建一个grunt宏,遵循这些指示。 That would allow you to use grunt instead of grunt.cmd. 这将允许您使用grunt而不是grunt.cmd。 This is the DOSKEY command you'd use: 这是您使用的DOSKEY命令:

EDIT 编辑

Alternatively you could use the DOSKEY command: 或者,您可以使用DOSKEY命令:

DOSKEY grunt=grunt.cmd $*

The alternative solution is to simply rename gruntfile from grunt.js to sth like gruntfile.js and then: 另一种解决方案是简单地将grunt文件从grunt.js重命名为sth,如gruntfile.js ,然后:

grunt --config gruntfile.js task:target

That way, there's no grunt.js file so grunt command will invoke the grunt binary rather than trying to open the file. 这样,没有grunt.js文件,所以grunt命令将调用grunt二进制文件而不是尝试打开文件。

This has an advantage of not needing platform-specific hacks. 这具有不需要特定于平台的黑客攻击的优点。 But of course if you want to type quickly in the console, you have to go with the DOSKEY hack. 但是当然如果你想在控制台中快速键入,你必须使用DOSKEY hack。

In case one wants to run grunt from npm , she can write node node_modules/grunt/bin/grunt instead of just grunt in the proper section of package.json . 如果有人想从npm运行grunt,她可以在package.json的正确部分中编写node node_modules/grunt/bin/grunt而不是grunt

Might I add the option to call the grunt commands from your toolbar in Visual Studio? 我可以在Visual Studio中添加从工具栏调用grunt命令的选项吗? I ended up integrating a lot of grunt commands in my projects and solutions. 我最终在我的项目和解决方案中集成了许多grunt命令。 All specific tasks. 所有具体任务。 It was a command spagetti, difficult to stay organized. 这是一个命令spagetti,难以保持井井有条。 I created a solution for this problem (scratch-my-own-itch project), it's an extension on visual stio called VsCommandBuddy. 我为这个问题创建了一个解决方案(scratch-my-own-itch项目),它是视觉上的一个名为VsCommandBuddy的扩展。 It allows the developer, per solution/project configurable, to specify which toolbar buttons should invoke which command. 它允许开发人员根据可配置的解决方案/项目指定哪些工具栏按钮应调用哪个命令。 Works like a charm. 奇迹般有效。 I now open any solution and get presented in my VS ui, exactly which commands I can use in that solution. 我现在打开任何解决方案,并在我的VS ui中显示,我可以在该解决方案中使用哪些命令。 Have a look: http://visualstudiogallery.msdn.microsoft.com/f5da988e-2ec1-4061-a569-46d09733c668 看看: http//visualstudiogallery.msdn.microsoft.com/f5da988e-2ec1-4061-a569-46d09733c668

Hope it helps! 希望能帮助到你!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM