Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using environment variables in npm scripts across platforms

I am building a package.json and use "npm run" to run some scripts, to be exactly, https://docs.npmjs.com/misc/scripts.

My script would need to expand some environment variables and I want to make it cross platform compatible. For example, my script would say

"scripts": {
  "build": "md %npm_package_version%\helloworld"
}

But it's currently running on Windows because the expansion of environment variables. Linux would use md $npm_package_version\helloworld.

Does npm comes with a mechanism to convert environment variables expansion so that it works across platforms?

like image 788
Compulim Avatar asked Oct 25 '15 15:10

Compulim


1 Answers

To make it cross-platform, use cross-var:

"scripts": {
  "build": "cross-var md %npm_package_version%\helloworld"
}
like image 180
Mark Woon Avatar answered Oct 12 '22 15:10

Mark Woon