码迷,mamicode.com
首页 > 其他好文 > 详细

[NPM] Pass arguments to npm scripts

时间:2017-02-06 21:02:42      阅读:148      评论:0      收藏:0      [点我收藏+]

标签:spec   var   gis   create   als   rom   scripts   code   mod   

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

标签:spec   var   gis   create   als   rom   scripts   code   mod   

原文地址:http://www.cnblogs.com/Answer1215/p/6371579.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!