首页 > 代码库 > [NPM] Pass arguments to npm scripts
[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
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。