Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using package.json config object variables under windows

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.

like image 372
Geril Avatar asked Jun 15 '15 10:06

Geril


People also ask

Can I use variables in package json?

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": ".

Can I add custom properties to package json?

Yes, you're allowed to add custom entries to package. json .

Which fields are the most important in your package json?

name — This is the most important and required field in the package. json file. This should represent the name of the project.

What is bin in package json?

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.


2 Answers

Try this:

"dev:server": "npm run clean && webpack-dev-server --progress --colors --port %npm_package_config_webpack_server_port%"
like image 103
marcel Avatar answered Nov 15 '22 00:11

marcel


For Linux and windows:

Use cross-env's cross-env-shell

"dev:server": "cross-env-shell 'echo ${npm_package_config_webpack_server_port}'"

Source

like image 38
user2835192 Avatar answered Nov 14 '22 23:11

user2835192