node.js 如何从与我的根项目不同的文件夹运行 grunt
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14873356/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I run grunt from a different folder than my root project
提问by zuniga
Is there a way to tell grunt which grunt.js file to use?
有没有办法告诉 grunt 使用哪个 grunt.js 文件?
I have an f:\a\b\toolsfolder that contains grunt.cmd, node.exe,...,
my actual web app with GruntFile.jsand all the local node_modulesis 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_appworks 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.
从运行 grunta\c\my_app工作正常,但尝试从其他文件夹运行 grunt 说 a 似乎不起作用。我是咕噜声的新手,可能我错过了一些明显的东西。
f:\a>grunt --config c\GruntFile.js
grunt-cli: The grunt command line interface. (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:
grunt-cli:grunt 命令行界面。(v0.1.6)
致命错误:无法找到本地咕噜声。
如果您看到此消息,则说明未找到 Gruntfile 或尚未将 grunt 安装到您的项目本地。有关安装和配置 grunt 的更多信息,请参阅入门指南:
回答by Renan Ivo
You can set two parameters --baseand --gruntfile
您可以设置两个参数--base和--gruntfile
From grunt --help:
来自grunt --help:
--baseSpecify an alternate base path. By default, all file paths are relative to the Gruntfile. (grunt.file.setBase) *
--base指定备用基本路径。默认情况下,所有文件路径都相对于 Gruntfile。(grunt.file.setBase) *
--gruntfileSpecify 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
回答by jsruok
Since grunt 1.3 you can omit --gruntfile.
从 grunt 1.3 开始,您可以省略--gruntfile.
So, instead of
所以,而不是
grunt --base c\my_app --gruntfile c\my_app\GruntFile.js mytask
grunt --base c\my_app --gruntfile c\my_app\GruntFile.js mytask
you can just
你可以
grunt --base c\my_app mytask(and --basecan be replaced with -b)
grunt --base c\my_app mytask(并且--base可以替换为-b)
回答by krampstudio
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:
我建议你从你的应用程序目录运行它,因为模块安装在 node_modules 等中。你必须移动到你的应用程序目录并运行 grunt:
cd f:
cd a\c\my_app
grunt {yourTasks}

