0

Imagine I have the following package.json structure:

{
  "version": "2.0.1",
  "scripts": {
   "testing": "build --version 2.0.1"
  }
}

I know you could replace the actual version with environment variables but is it possible with a package.json attribute? For example:

{
  "version": "2.0.1",
  "scripts": {
   "testing": "build --version ${package.version}"
  }
}
rafaelmorais
  • 1,323
  • 2
  • 24
  • 49
  • 1
    Access the `npm_package_version` environment variable. Refer to my answer [here](https://stackoverflow.com/questions/48609931/how-can-i-reference-package-version-in-npm-script/48619640#48619640). On _*nix_ it would be `"testing": "build --version $npm_package_version"` (note the dollar sign `$` prefix). On windows (cmd) it would be `"testing": "build --version %npm_package_version%"` (note the `%...%`) - For a one script syntax that works cross-platform (i.e. using the dollar sign prefix) consider utilizing [cross-var](https://www.npmjs.com/package/cross-var). – RobC Nov 26 '20 at 10:29
  • 2
    Does this answer your question? [How can I reference package version in npm script?](https://stackoverflow.com/questions/48609931/how-can-i-reference-package-version-in-npm-script) – Trott Nov 26 '20 at 14:03

0 Answers0