The specific performance

— myOption is discarded by NPM script when the following command is executed

npm run mycommand --myoption
Copy the code

As is shown in

This will cause the actual myCommand-js execution to receive no arguments

The solution

Add — before — myOption to get the effect shown

why

  1. -or--The initial values are treated as arguments to the NPM script, which has no part to process them, so they are discarded
  2. --myoptionAdd in front of--This is called the “configuration item parameter terminator” in bash, as shown in the following example
The # echo command is used to output characters such as
echo help # help

# if I want to print --help, add --help to echo to print the help for the echo command
# This is where you need to -- show up

echo -- --help # --help

This means that the value following the parameter terminator is passed directly to the command as plain text
Copy the code

The resources

Ruan Yifong Bash Script Start – Configuration item parameter terminator

The original address