First off, I'm very new to npm and grunt. We have a project that we are using Grunt to compile and produce the output files for. I am trying to setup our build server to use Grunt to produce the output files. We are using Windows with TFS source control, and due to it's 260 character path limit, we are not able to check the grunt-bower-task module into source control (as it alone uses 230 characters in its installed path).
When I run npm install from my project directory it works fine and installs the following required modules into the node_modules folder in my project directory:
- grunt
- grunt-bower-task
- grunt-contrib-compass
- grunt-contrib-connect
- grunt-contrib-jshint
- grunt-contrib-requirejs
- grunt-contrib-watch
And then when I run grunt deploy from my project directory everything works as expected.
While I could simply make running npm install part of the build process, I prefer not to, as it takes a few minutes to download all of the files, and I don't want our builds to depend on an external web service being available.
I've seen that you can install modules either locally or globally, so I'm hoping to just be able to install the modules globally on the build server so that they do not need to be in the node_modules folder directly inside the project directory before running grunt deploy. I've ran npm install -g, as well as npm install -g [module] for each of the modules listed above, as well as npm install -g grunt-cli.
If I do npm prefix -g it shows me that the global module directory is C:Users[My User]AppDataRoaming
pm, and when I look in that directory's node_modules folder I do see all of the modules. However, when I run grunt deploy it complains with:
Fatal error: Unable to find local grunt
If I include just the *node_modulesgrunt* directory, then I still get these errors:
Local Npm module "grunt-contrib-watch" not found. Is it installed?
Local Npm module "grunt-contrib-jshint" not found. Is it installed?
...
I've also tried using *grunt deploy --base "C:Users[My User]AppDataRoaming
pm", but it complains that it then cannot find other files, such as .jshintrc.
So is there a way that I can run grunt deploy and have it check the npm global prefix path for the modules, rather than looking in the project directory?
A hacky work around is to copy the modules manually during the build process to the local project directory, but I would like to avoid this if possible.
For reference, this is what my package.json file looks like:
{
"name": "MyProject",
"version": "0.0.1",
"scripts": {
"preinstall": "npm i -g grunt-cli bower"
},
"devDependencies": {
"grunt": "~0.4.1",
"grunt-contrib-compass": "~0.2.0",
"grunt-contrib-watch": "~0.4.4",
"grunt-contrib-jshint": "~0.6.0",
"grunt-contrib-requirejs": "~0.4.1",
"grunt-contrib-connect": "~0.3.0",
"grunt-bower-task": "~0.2.3"
}
}
Thanks.
See Question&Answers more detail:
os