DEV Community

t-o-d
t-o-d

Posted on

2 1

【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.

Hostinger image

Get n8n VPS hosting 3x cheaper than a cloud solution

Get fast, easy, secure n8n VPS hosting from $4.99/mo at Hostinger. Automate any workflow using a pre-installed n8n application and no-code customization.

Start now

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay