[NPM] Pass arguments to npm scripts
Posted Answer1215
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[NPM] Pass arguments to npm scripts相关的知识,希望对你有一定的参考价值。
Often times you’ll have variations that you’ll want to make to your npm scripts and repeating yourself is inefficient and verbose. Instead you can create a base script and pass arguments into it from another script.
For example, you have a script:
"test": "mocha spec/ --require babel-register",
And you want to add a watcher to the test script:
"test:watch": "mocha spec/ --require babel-register --watch",
Here what we do is copy the script and add a ‘--watch‘ behind. This is not good enough, because if you want to change the ‘test‘ script, you also need to modify the ‘test:watch‘ script.
So what you can do:
"test:watch": "npm t -- --watch"
First ‘--‘ tell the compiler that we still need to pass in some arguments; And ‘--watch‘ is what we want to pass in.
以上是关于[NPM] Pass arguments to npm scripts的主要内容,如果未能解决你的问题,请参考以下文章
English Snippet 5 - How to Pass Arguments to a Bash-Script
pycharm运行Pytest警告:passing a string to pytest.main() is deprecated, pass a list of arguments instead.
npm命令Error: EINVAL: invalid argument, mkdir