I have 3 React-related packages in my package.json, and the version numbers must be in sync. I know with Maven, you can define variables in the POM file to re-use and keep version numbers in sync across different packages.
I want to do the same thing with my npm package.json, like so:
...
"config": {
"react_version": "^15.4.1"
},
"dependencies": {
"react": "$npm_package_config_react_version",
"react-addons-test-utils": "$npm_package_config_react_version",
"react-dom": "$npm_package_config_react_version"
}
...
It seems that config
variables set in the package.json file can only be used inside your script
commands.
Is there a way to solve this problem at the moment? Will something like this be included in a future version of npm?
Use the engines keyword in the package. json file to specify the Node. js version that you want your application to use. You can also specify a version range using npm notation.
I've been wrestling with this too. The issue for me has been that I want to use different npm tags in different environments ('latest' for dev, 'prod' for prod). The solution I came up with is to use an environment variable for the tag. I set up something along the following in package.json. Since I'm using 'latest' everywhere except for production servers, I avoid the problem of inadvertently changing the git repo:
"scripts": {
"start": "perl -pi -e \"s#\\\"package_name\\\".*#\\\"package_name\\\": \\\"$TAG_VAR\\\",#\" package.json && node app.js"
},
"dependencies": {
"package_name": "latest",
"other_package": "^1.0.0"
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With