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