36

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

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

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.

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

3 Answers 3

62

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

From grunt --help:

--base Specify an alternate base path. By default, all file paths are relative to the 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.

So, you can execute:

grunt --base c\my_app --gruntfile c\my_app\GruntFile.js mytask 
Sign up to request clarification or add additional context in comments.

4 Comments

FWIW, using --base did not work for me but using --gruntfile did.
How can this be set as 'default'? We have a Generic Grunt file that can be used in all of our applications so we want it in a folder (submodule) but still just want to run everything by just calling grunt rather than having to type --gruntfile every time.
This doesn't seem to work with the watch file. initial run is OK, but when a watch triggers a run the path is doubles and errors out: unable to find gruntfile "c\my_app\c\my_app\gruntfile.js"
Just to update for grunt-cli versions >= 1.0.0, the command is now: grunt --base=c\my_app --gruntfile=c\my_app\GruntFile.js mytask source
1

Since grunt 1.3 you can omit --gruntfile.

So, instead of

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

you can just

grunt --base c\my_app mytask (and --base can be replaced with -b)

Comments

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:

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

1 Comment

by specifying the --base parameter you can get rid of it. see @Renan's answer.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.