NPM custom scripts with common parameters

Viewed 13

When writing custom scripts with NPM, I wish I could share common parameters across scripts. The problem:

{
  "scripts": {
    "build": "build_command param1 param2",
    "watch": "watch_command param1 param2"
  }
}

param1 and param2 are respectively the same for both commands.

A solution should work cross platform (Linux, Windows, ...). I tried messing with environment variables, but this is not cross platform without additional packages and the common packages for cross platform env vars are buggy, e.g. cross-env.

I could write a custom Node script that gets run via NPM, but I would prefer to just use NPM scripts to keep it simple. Any suggestions?

0 Answers
Related