splincode
splincode

Reputation: 183

How to use a package script under a different platform?

I have to have this line package.json

"scripts": {
  "default_linux": "export NODE_ENV=default&& export NODE_MINIFIED=false&& webpack",
  "default_windows": "set NODE_ENV=default&& set NODE_MINIFIED=false&& webpack",
  "default_linux_min": "export NODE_ENV=default&& export NODE_MINIFIED=true&& webpack",
  "default_windows_min": "set NODE_ENV=default&& set NODE_MINIFIED=true&& webpack",
},

But to run a not very nice to think about each version separately and so as to correctly configure scripts for different platforms to make it as a team, not ..?

$ npm run default_linux #  frontend assembly under linux

Upvotes: 1

Views: 95

Answers (1)

user5483398
user5483398

Reputation:

You can use the cross-env package on npm. It allows you to use unix style scripts, and handles all the cross-platform issues. It works for linux and windows, but I haven't tested it for Mac. Also, there's no need for export.

After you install cross-env, you can replace your scripts field with this:

"scripts": {
    "build": "cross-env NODE_ENV=default NODE_MINIFIED=false webpack",
    "build-min": "cross-env NODE_ENV=default NODE_MINIFIED=true webpack",
},

Upvotes: 2

Related Questions