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!
"build:docker": "func() { tsc -b && sh dist.sh && docker build -t \"repo_name/image:${1}\" .; }; func"
- then runnpm run build:docker -- "1.0"
"1.0"
to the npm script, should the last part of your npm script example form:... && docker build -t repo_name/image:1.0 ."
? Presumable the$tag
in your example is a placeholder for where1.0
should go, or did I misunderstand?repo_name/image:1.0
was correct by logs - weird why is it re-building.