May 25, 2021 Grunt
2. Why can't my asynchronous tasks be completed?
3. How do I enable tab key auto-complement in shell?
4. Do I want multiple tasks to share parameters?
5. How do I get trace information for the call stack when an error occurs?
6. Why is there a "Maximum call stack size exceeded "
7. How do I uninstall or remove unwanted plug-ins?
8. Error "Fail to install with npm error: No compatible version found"
For general installation instructions, read the Quick Start guide. If you need more details after reading, you can read the more detailed Installation Grunt guide.
The Installation Grunt guide describes how to install a published and unresoled version of Grunt.
Grunt works well on windows because node .js and npm work well on windows. Typically, the problem is Cygwin because it bundles an older version of .js.
The best way to avoid this problem
is to use msysGit installer
to install
git
and node.js installer to
install
node
and
npm
and then replace Cygwin with
built-in Windows command prompt
or
PowerShell.
This is because you forgot
to call the this.async
method to tell Grunt that your task is executed asynchronously.
To simplify the model, Grunt uses the coding style of synchronous mode, which you can switch to asynchronous mode by calling
this.async()
in a task.
Note that if task fails to execute, you can pass
false
done()
to inform Grunt.
Case:
grunt.registerTask('asyncme', 'My asynchronous task.', function() {
var done = this.async();
doSomethingAsync(done);
});
In order to add tab key auto-complement to grunt, you can add the following line of code to your
~/.bashrc
file:
eval "$(grunt --completion=bash)"
Of course, let's
npm install -g grunt
using npm install -g grunt.
Because Grunt currently only supports bash commands.
Although each task can use its own parameters, there are several ways to allow you to share parameters across multiple taskes.
This is the preferred method for sharing parameters for multiple tasks
Since
the task alias
is simple, a normal task can
use grunt.task.run
to have a function as a "dynamic" task alias.
In the following case,
grunt build:001
is executed on the command line, and the end result is the execution of
bar:001
baz:001
foo:001
grunt.registerTask('build', 'Run all my build tasks.', function(n) {
if (n == null) {
grunt.warn('Build num must be specified, like build:001.');
}
grunt.task.run('foo:' + n, 'bar:' + n, 'baz:' + n);
});
Multiple tasks share parameters by using
grunt.option.
Here's an example where executing
grunt deploy --target=staging
on the command line would return
grunt.option('target')
"staging"
grunt.registerTask('upload', 'Upload code to specified target.', function(n) {
var target = grunt.option('target');
// do something useful with target here
});
grunt.registerTask('deploy', ['validate', 'upload']);
Note that boolean-type parameters can use a key with no value.
For example, executing
grunt deploy --staging
command line
grunt.option('staging')
true
In other cases, you may want to expose a setting configuration or a global value method. In this case, you can set its parameters as a global object or the value of the project configuration when you register a task.
In the following example, running
grunt set_global:name:peter set_config:target:staging deploy
causes the value of global.name
"peter"
and
grunt.config('target')
"staging"
global.name
From this, it is
deploy
task can use these values.
grunt.registerTask('set_global', 'Set a global variable.', function(name, val) {
global[name] = val;
});
grunt.registerTask('set_config', 'Set a config property.', function(name, val) {
grunt.config.set(name, val);
});
You can see the trace information for the call stack using the
--stack
parameter.
For example:
grunt task --stack
.
You may have renamed alias and other tasks that you created for a task. F
or example:
grunt.registerTask('uglify', ['uglify:my_target']);
It
grunt.registerTask('myUglify', ['uglify:my_target']);
。
There are at least two ways. O
ne method is to
npm uninstall [GRUNT_PLUGIN] --save-dev
which removes the specified
node_modules
package.json
file and the node_modules directory.
Another method is to manually remove
package.json
file and then execute
npm prune
instruction.
Make sure you have the latest stable versions of NPM and Node .JS.
If
you're in gruntfile's
directory, Windows tries to execute that file when you enter
grunt.
So you need to
grunt.cmd
Another option is to use
DOSKEY
command to create a Grunt macro, please refer to this
article.
This allows
grunt
grunt.cmd
You can use the
DOSKEY
like this:
DOSKEY grunt=grunt.cmd $*