Does anybody know how to use variables from package.json config object under windows? Here is my current config object:
"config": {
"webpack_server_port": "8080",
"mockup_server_port": "3000"
}
And here is my npm script command:
"dev:server": "npm run clean && webpack-dev-server --progress --colors --port $npm_package_config_webpack_server_port",
It's working fine under Linux and MAC OS, but windows have problem with it.
To use variable, you need to declare a section named config (or something else, but not a name was already taken by the package. json ). And in this section, you can declare ALL YOUR VARIABLES : { ... "config": { "path": ".
Yes, you're allowed to add custom entries to package. json .
name — This is the most important and required field in the package. json file. This should represent the name of the project.
bin. A lot of packages have one or more executable files that they'd like to install into the PATH. npm makes this pretty easy (in fact, it uses this feature to install the "npm" executable.) To use this, supply a bin field in your package. json which is a map of command name to local file name.
Try this:
"dev:server": "npm run clean && webpack-dev-server --progress --colors --port %npm_package_config_webpack_server_port%"
For Linux and windows:
Use cross-env's cross-env-shell
"dev:server": "cross-env-shell 'echo ${npm_package_config_webpack_server_port}'"
Source
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