Saturday 11 March 2017

Inject argument into npm script command

I have an npm script that looks like:

"scripts": {
    "example": "webpack-dev-server --content-base examples/embeddable/"
},

I'd like to form the --content-base argument dynamically based on whatever's passed when calling the npm script, like:

npm run example -- embeddable

I know the -- syntax works for making args available to process.argv, but I'm not calling a Node script here so I'm not sure how to access them when forming the command. Does anyone else know of a good, cross-platform way to do this? (Must work on Windows.)



via Jura

No comments:

Post a Comment