I have npm scripts in the package.json
, I would like to provide custom parameter from the command line. I found many stackoverflow questions and answers but none of them works. I tried this solution:
JavaScript
x
4
1
"scripts": {
2
"foo": "echo $npm_config_foo && echo done"
3
},
4
When I run the command:
JavaScript
1
7
1
$ npm run foo --foo=test
2
3
> echo $npm_config_foo && echo done
4
5
$npm_config_foo
6
done
7
As you can see, it does not echo test
.
This is my configuration:
JavaScript
1
4
1
- OS: Windows
2
- Terminal: GitBash
3
- npm version: 7.14.0
4
I tried this, on Linux and it works. This is related to Windows.
Advertisement
Answer
The solution is to use % instead of $.
JavaScript
1
4
1
"scripts": {
2
"foo": "echo %npm_config_foo% && echo done",
3
},
4