How to dynamically pass parameters to a command when npm run is executed serially

Describe the problem scenario.

npm scripts support dynamic parameter passing, but my npm scripts are a collection of several commands. As follows:

{"build": "r.js -o build.js && node version.js -v && zip -r ./build/dist.zip ./build"}
The command in the middle needs to pass parameters such as 0123456 after -v ;
Now if called like this: npm run build -- 0123456 the arguments are passed to the last command

Can be written as: {"build": "r.js -o build.js && node version.js -v ${V}&& zip -r ./build/dist.zip ./build"}

Then when called:

V=0123456 npm run build

Link: How to pass parameters when npm run executes the scripts configuration in package.json? - Know almost

In my code, parameters can also be passed this way: 

"modify": "node ./scripts/modify.js ${ENV} ${DATA} && mkdir ./dist/static",

 In the process of solving this problem, I learned more about npm scripts.

1. Ruan Yifeng's npm introduction  npm scripts user guide - Ruan Yifeng's weblog

2. Some ways of passing  parameters in npm

3. Use command line parameters in npm script 

Guess you like

Origin blog.csdn.net/qq_34539486/article/details/127729963