Grunt is an open source Web front-end building tool developed using JavaScript and based on NodeJS.

  1. Create a new project directory grunt and go to this directory
  2. Create package.json file using YARN init -y
  3. Install grunt: yarn add grunt –dev
  4. In the current grunt directory, create a gruntfile.js file: the entry file for grunt. It defines the tasks that need to be performed automatically by Grunt. You need to export a function that takes a grunt parameter and provides an API for creating tasks
Module.exports = grunt => {// Load specified plugin task grunt. LoadNpmTasks ('grunt-contrib-clean') // Build task configuration grunt. InitConfig ({foo:{ Bar: 123}, the clean: {temp: 'temp / * *}, build: {options: {foo:' bar '}, CSS: {options: {foo: '111'}}, js: '2 a'}}) / / multi-objective model, Grunt. RegisterMultiTask ('build',function(){// console.log('build task'); console.log(this.options()); console.log(`target:${this.target}:${this.data}`); }) / / registered task of grunt. RegisterTask (' foo '() = > {the console. The log (grunt. Config (' foo bar')); }) of grunt. RegisterTask (' bar ', 'task description, () = > {the console. The log (' bar task); }) grunt.registerTask('bad',()=>{ console.log('bar task~'); return false }) grunt.registerTask('default',['foo','bad', Grunt. RegisterTask ('async-task',function(){const done = this.async() setTimeout(()=>{ console.log('async task~~'); done() },1000) }) grunt.registerTask('async-bad',function() { const done = this.async() setTimeout(()=>{ console.log('bad async~~'); done(false) },1000) }) }Copy the code

Simple re matching for files:

1. Matches any number of characters except /. For example,.js matches all files ending in.js

2.? Matches a single character except /

3. Matches any number of characters containing /, such as ‘temp/’

4.! To exclude specified files, such as ‘! temp/a.js’

{} can be interpreted as “or” expressions, such as ‘temp/{a,b}.js’.