【NPM】Three useful ways to write a grouping in scripts configuration.

kamekuremaisuke

t-o-d

Posted on August 10, 2020

【NPM】Three useful ways to write a grouping in scripts configuration.
  • 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).
$ 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.

💖 💪 🙅 🚩
kamekuremaisuke
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.

Related

Tonada - A new UI library
javascript Tonada - A new UI library

October 2, 2022

We all know JavaScript
javascript We all know JavaScript

September 5, 2022

Create Simple Chart With D3js
javascript Create Simple Chart With D3js

November 10, 2020