I have an npm script to start the webpack dev server, but first, my env setup -
in my .zshrc - export DEV_SERVER_PORT=8001
echo returns expected results
>echo $DEV_SERVER_PORT
8001
here's the script i'm running from package.json via npm run
webpack-dev-server --inline --hot --port 8001
this executes correctly via npm run -
echo $DEV_SERVER_PORT
result: 8001
this produces disappointing results via npm run-
webpack-dev-server --inline --hot --port $DEV_SERVER_PORT
result webpack-dev-server --inline --hot --port $DEV_SERVER_PORT
system()from npm, it's just"$varname"as usual; for native JavaScript code it'sprocess.env.varname. But the difference between regular shell variables and environment variables is critical here -- if you didn't export it to the environment, it won't be present.