Magnitus (70) [Avatar] Offline
#1
I tried to setup uglify with Grunt and ran into some trouble when basing myself on your example to give a list of tasks a custom name.

It is because of this part:

"scripts": {
"grunt": "grunt"
},

Passing arguments to "npm run grunt" resulted in weird behaviors (didn't do anything really) and in a way, it makes sense as npm run the associated shell command in the "scripts" entry of package.json "as is" (suppose that the command in "scripts" already had arguments specified and you give more arguments to npm, how should it interpret it in the context of the command you want it to execute?).

To run the above as intended, I had to modify the package.json as follows:

"scripts": {
"grunt": "grunt",
"grunt-watch": "grunt watch"
}

Then, when typing "npm run grunt-watch" in the shell, "grunt watch" would be ran.
Evan Hahn (70) [Avatar] Offline
#2
Re: Some Troubleshooting Needed Grunt Subsection (Meap v3)
I'm very attached to having everything installed locally to the project, so Project A's Grunt can be completely different from Project B's Grunt. Unfortunately, this can become cumbersome when running things like Grunt and Mocha. I'll revisit this and likely change it for Grunt.
Magnitus (70) [Avatar] Offline
#3
Re: Some Troubleshooting Needed Grunt Subsection (Meap v3)
I prefer application-specific module installs too, even if sometimes, it means I need to write something like "node_modules/<ModuleName>/bin/<ExecName>".

I don't think installing grunt globally would solve the package.json scripts problem, unless you intend to just type "grunt" directly instead of "npm run grunt" or "node_modules/grunt-cli/bin/grunt" smilie.

Alternatively, you could get the best of all worlds by just creating a symbolic link called "grunt" in your project directory that links to "node_modules/grunt-cli/bin/grunt": Local install, short to type, ability to pass any args without having to edit the package.json file...
Evan Hahn (70) [Avatar] Offline
#4
Re: Some Troubleshooting Needed Grunt Subsection (Meap v3)
Those are good ideas--I'll look into those.
Magnitus (70) [Avatar] Offline
#5
Re: Some Troubleshooting Needed Grunt Subsection (Meap v3)
I encountered another problem with the example in the book.

The short version is that this line breaks:

grunt.registerTask("watch", ["watch"]);

Apparently, the task needs to be named differently from its arguments.

The issue (and the solution) can be found here:

http://stackoverflow.com/questions/27093306/grunt-contrib-watch-unbound-recursion-error/27093503#27093503