Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

Grunt creates the plug-in


May 25, 2021 Grunt


Table of contents


Create a plug-in

  1. Install npm install -g grunt-init grunt-init command.
  2. Install git clone git://github.com/gruntjs/grunt-init-gruntplugin.git ~/.grunt-init/gruntplugin template with the git clone command.
  3. Perform grunt-init gruntplugin
  4. Execute npm install command to prepare the development environment.
  5. Write code for your plug-in.
  6. Execute npm publish command to publish the Grunt plug-in you created npm!

Attention

Name your task

The "grunt-contrib" namespace is reserved for task maintained by the Grunt team, give your own task a suitable name, and avoid using the reserved namespace.

Debugging

Grunt hides error stack traces by default, but can be --stack parameter so you can debug your own task. I f you want Grunt to always record the stack trace in the event of an error, you can create a command alias (alias) in your shell. For example, in bash, you can create an alias by using the alias grunt='grunt --stack' command.

Store the task file

Store the data file only in the .grunt/npm-module-name directory in the root of the project and clear it when appropriate. This is not a good solution for temporary files, and it is recommended that you call the operating system-level temporary directory functionality using several common npm modules listed later, such as temporary, tmp.

Avoid changing the current working directory: process.cwd()

By default, the directory containing the gruntfile file is set to the current working directory. Users can change the current working directory by grunt.file.setBase() changes in their own gruntfile, but the plug-in should not change it.

path.resolve('foo') to obtain the absolute path of 'foo' relative to the directory in which Gruntfile is located.