Is it possible to pass an argument to the npm command string? The info might be somewhere in docs, but brief digging didn't get me any results, moreover, it is probably beneficial to the large audience.
For example, i have a command build:docker
in package.json
:
"scripts": {
"build:docker": "tsc -b && sh dist.sh && docker build -t repo_name/image .",
},
I want to pass the tag
variable to the command string, ex:
"build:docker": "tsc -b && sh dist.sh && docker build -t repo_name/image:$tag ."
and run it as npm run build:docker --tag '1.0'
.
Is something like this possible? Thanks!
Yes, you can: For example (for simplicity), for the line:
"build": "tsc --project "
You can start it like so:
npm run build ./src
This will start:
> tsc --project "./src"
And another solution (I didn't see the point without glasses :) ), more suitable for you is to prefix the name of the parameter with $npm_config_
, so your line should look like this:
"build:docker": "tsc -b && sh dist.sh && docker build -t repo_name/image:$npm_config_mytag ."
And then run it as:
npm run build:docker --mytag=1.0
Watch out for =
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With