如何从不同于我的根项目的文件夹运行grunt

时间:2021-09-19 22:49:40

Is there a way to tell grunt which grunt.js file to use?

有没有办法告诉grunt使用哪个grunt.js文件?

I have an f:\a\b\tools folder that contains grunt.cmd, node.exe,..., my actual web app with GruntFile.js and all the local node_modules is in f:\a\c\my_app

我有一个f:\ a \ b \ tools文件夹,其中包含grunt.cmd,node.exe,...,我的实际Web应用程序与GruntFile.js和所有本地node_modules在f:\ a \ c \ my_app

Running grunt from a\c\my_app works fine but trying to run grunt from some other folder say a does not seem to work. I am new to grunt and may be I am missing something obvious.

从\ c \ my_app运行grunt工作正常,但试图从其他文件夹运行grunt说一个似乎不起作用。我是新来的咕噜咕噜,可能是我错过了一些明显的东西。

f:\a>grunt --config c\GruntFile.js

grunt-cli: The grunt command line interface. (v0.1.6)

grunt-cli:grunt命令行界面。 (v0.1.6)

Fatal error: Unable to find local grunt.

致命错误:无法找到当地的咕噜声。

If you're seeing this message, either a Gruntfile wasn't found or grunt hasn't been installed locally to your project. For more information about installing and configuring grunt, please see the Getting Started guide:

如果您看到此消息,则表示未找到Gruntfile或者您的项目未在本地安装grunt。有关安装和配置grunt的更多信息,请参阅“入门指南”:

http://gruntjs.com/getting-started

http://gruntjs.com/getting-started

2 个解决方案

#1


56  

You can set two parameters --base and --gruntfile

您可以设置两个参数--base和--gruntfile

From grunt --help:

来自grunt --help:

--base Specify an alternate base path. By default, all file paths are relative to the Gruntfile. (grunt.file.setBase) *

--base指定备用基本路径。默认情况下,所有文件路径都相对于Gruntfile。 (grunt.file.setBase)*

--gruntfile Specify an alternate Gruntfile. By default, grunt looks in the current or parent directories for the nearest Gruntfile.js or Gruntfile.coffee file.

--gruntfile指定备用Gruntfile。默认情况下,grunt在当前或父目录中查找最近的Gruntfile.js或Gruntfile.coffee文件。

So, you can execute:

所以,你可以执行:

grunt --base c\my_app --gruntfile c\my_app\GruntFile.js mytask

#2


0  

I'll advise you to run it from your app directory because the modules are installed into nodes_modules, etc. you must move to your app directory and run grunt:

我建议你从app目录运行它,因为模块安装在nodes_modules等中。你必须移动到你的app目录并运行grunt:

cd f:
cd  a\c\my_app
grunt {yourTasks}

#1


56  

You can set two parameters --base and --gruntfile

您可以设置两个参数--base和--gruntfile

From grunt --help:

来自grunt --help:

--base Specify an alternate base path. By default, all file paths are relative to the Gruntfile. (grunt.file.setBase) *

--base指定备用基本路径。默认情况下,所有文件路径都相对于Gruntfile。 (grunt.file.setBase)*

--gruntfile Specify an alternate Gruntfile. By default, grunt looks in the current or parent directories for the nearest Gruntfile.js or Gruntfile.coffee file.

--gruntfile指定备用Gruntfile。默认情况下,grunt在当前或父目录中查找最近的Gruntfile.js或Gruntfile.coffee文件。

So, you can execute:

所以,你可以执行:

grunt --base c\my_app --gruntfile c\my_app\GruntFile.js mytask

#2


0  

I'll advise you to run it from your app directory because the modules are installed into nodes_modules, etc. you must move to your app directory and run grunt:

我建议你从app目录运行它,因为模块安装在nodes_modules等中。你必须移动到你的app目录并运行grunt:

cd f:
cd  a\c\my_app
grunt {yourTasks}