When using npm_package_config_<variable>
usage is different per OS.
package.json (Linux & Windows)
config: {
foo: "bar"
}
Then for usage:
Linux
node app.js --arg=$npm_package_config_foo
Windows
node app.js --arg=%npm_package_config_foo%
Thus I create 2 seperate scripts
in my package.json
but this feels cumbersome.
Any way to get this cross-platform?
P.S. I'm aware of the cross-env plugin, but this does not work for the above case, only for NODE_ENV.
UPDATE
To avoid misinterpretation of the context, here is a real case scenario I'm looking for, to use this for Docker commands to specify port numbers:
package.json
"config": {
"port": "3000"
}
...
"scripts": {
"docker:build": "docker build --build-arg PORT=$npm_package_config_port -t my-app .",
"docker:build:win": "docker build --build-arg PORT=%npm_package_config_port% -t my-app .",
}
cross-env-os Run scripts that set and use environment variables across platforms. cross-environment. environment variable.
You should use cross-var
.
Then you can simplify to:
"scripts": {
"docker:build": "cross-var docker build --build-arg PORT=$npm_package_config_port -t my-app .",
}
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