This article has synchronization in my blog: ruizhengyun. Cn/blog/post / 8…

Add parameters

Adding parameters reduces duplication of NPM scripts. In the case of ESLint, passing the –fix parameter turns on the built-in auto-fix mode for code styles to make it sound smart.

"scripts": {... ."lint:js": "eslint ./src/**/*.js"."lint:js:fix": "eslint ./src/**/*.js --fix"
}
Copy the code

In line with the principle of not being DRY, but also encounter the risk of copy and paste, can be cleverly configured as follows:

"scripts": {... ."lint:js": "eslint ./src/**/*.js"."lint:js:fix": "npm run lint:js -- --fix"
}
Copy the code

NPM run Lint :js adds extra arguments to NPM run lint:js.

If you look at your code at this point, you’ll notice that some code styles are fixed automatically.

Add comments

As more and more command configurations become available, it becomes imperative to add comments to keep the code readable and maintainable.

Add it in package.json//As the key value

"scripts": {... ."/ /": "Check all code programming styles in parallel"."lint:bx-all": "npm-run-all --parallel lint:*"
}
Copy the code

NPM run does not match comments to commands and only lists the last one.

Edit and comment directly in script commands

"scripts": {... ."lint-bx-all": "# parallel check all code programming styles \ npm-run-all --parallel Lint :*"
}
Copy the code

Note the space after \n, mainly for typography (newline or indent) aesthetics, of course, \t can also be used.

Run time log

The default log

Without adding any parameters to control log output, which is also the most common, you can see the results of executing commands and executing commands.

More concise logging-s

Control log output with –loglevel silent or –silent or -s arguments,

Unconcise logs-d

–loglevel verbose or –verbose or -d(-v = -v, -v = version)

You can…

NPM Script multicommand running

Use of NPM Script hooks

Directory: NPM Script small book