Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Concatenate NPM Script Commands?

I understand that it's possible to chain NPM scripts with &&, pre- and post- hooks, but is it possible to simply separate lengthy script lines into a single, concatenated line?

For example, I'd like to convert this:

"script": {
  "build": "--many --commands --are --required --on --a --single --line"
}

into this:

"script": {
  "part1": "--many --commands",
  "part2": "--are --required",
  "part3": "--on --a",
  "part4": "--single --line",
  "build": "part1 + part2 + part3 + part4"
}

So when I enter npm run build it will merge all the parts of the command on one line.

I'm also familiar with config variables, but they are not a cross platform solution so I will avoid using them.

like image 884
Chunky Chunk Avatar asked May 09 '17 18:05

Chunky Chunk


People also ask

How run multiple scripts npm?

Approach 1(npm-run all package): We can use the” npm-run all” package to run different scripts at the same time. First, we have to install the package itself by using the command. After installation of the package we have to navigate to the package.

Can the npm-run-all CLI tool run multiple npm scripts in parallel?

Option 3: NPM-Run-All Moving on, this package is another popular option from NPM, called NPM-Run-All. The NPM page proclaims npm-run-all “A CLI tool to run multiple npm-scripts in parallel or sequential.”


1 Answers

A common approach to do it is like:

{
  "scripts:": {
    "script1": "cmd1",
    "script2": "cmd2",
    "script3": "cmd3",
    "build": "npm run script1 && npm run script2 && npm run script3",
  }
}
like image 173
Nurbol Alpysbayev Avatar answered Sep 22 '22 01:09

Nurbol Alpysbayev