node.js - 如何从与根项目不同的文件夹运行 grunt

标签 node.js gruntjs

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

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

a\c\my_app 运行 grunt 工作正常,但尝试从其他文件夹运行 grunt 说 a 似乎不起作用。我是 grunt 的新手,可能我遗漏了一些明显的东西。

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:

http://gruntjs.com/getting-started

最佳答案

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

来自 grunt --help:

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

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

所以,你可以执行:

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

关于node.js - 如何从与根项目不同的文件夹运行 grunt,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14873356/

相关文章:

templates - 使用 Assemble 从循环内部访问全局变量

javascript - 返回异步数据然后在 Node.js 中同步导出

html - Mongodb $push 运算符不起作用

javascript - 是否有任何软件包可以让您记录 gruntfile,类似于 Node 的 apiDocs?

node.js - -bash : grunt: command not found

javascript - Node.js 通过 Grunt 运行 SASS 预处理器

javascript - 如何在 PassportJS 中获取 facebook 用户图像?

node.js - express.js 不提供我的图像

node.js - 应用程序重新启动时 winston 日志文件丢失

javascript - 如何删除与 Grunt 中的正则表达式匹配的文件?