【NPM】Three useful ways to write a grouping in scripts configuration.
t-o-d
Posted on August 10, 2020
- I think you need to write scripts configuration in package.json when you use npm. In this post, I'll write three useful ways to group scripts.
preparation
- Install
npm-run-all
, which is useful when writing multiple commands in scripts.- It can be written as
run-s ******(scripts name)
.
- It can be written as
$ npm i -D npm-run-all
1. Basic Writing
- Write all of the scripts.
{
"scripts": {
"build": "run-s build:clean build:copy build:js",
"build:clean": "rimraf ./dist",
"build:copy": "cpx -C public/** dist",
"build:js": "esbuild src/index.js --bundle --outfile=dist/out.js"
}
}
2. wildcard writing
- Write with a wildcard using an asterisk.
{
"scripts": {
"build": "run-s build:*",
"build:clean": "rimraf ./dist",
"build:copy": "cpx -C public/** dist",
"build:js": "esbuild src/index.js --bundle --outfile=dist/out.js"
}
}
3. grouping writing (Convenient and recommended)
- Write it as you would an array using brackets.
- It is recommended that the order and names are clearly marked.
{
"scripts": {
"build": "run-s build:{clean,copy,js}",
"build:clean": "rimraf ./dist",
"build:copy": "cpx -C public/** dist",
"build:js": "esbuild src/index.js --bundle --outfile=dist/out.js"
}
}
That's all.
Thank you for reading.
💖 💪 🙅 🚩
t-o-d
Posted on August 10, 2020
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.