3

Pass command line args to npm scripts in package.json is almost what I'm looking for.

I use Gulp to do our NPM builds. I am able to do this, using the yargs plugin

$ gulp build --gitTag 1.0.0

and it produces dist/packageName-1.0.0.zip file. However, I need to be able to do this

$ npm run build --gitTag=1.0.0

I tried this,

  "scripts": {
    "build": "npm ci && gulp build --gitTag %npm_config_gitTag%"
  }

...and this

  "scripts": {
    "build": "export GIT_TAG=%npm_config_gitTag% && npm ci && gulp build"
  }

However, the %npm_config_gitTag% is not substituted with my passed-in gitTag argument, meaning the resulting artifact is packageName-%npm_config_gitTag%.zip

What should my build script look like in my package.json file?

1 Answer 1

2

I found the magic recipe

I simply have this in my package.json

  "scripts": {
    "build": "npm ci && gulp build"
  }

and use the following command line

$ npm run build -- --gitTag 1.0.0

and get the wanted packageName-1.0.0.zip artifact.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.