npm 脚本:是否有跨平台条件语句?

Joh*_*lly 6 cross-platform npm

我正在尝试将 npm 包从依赖转变*nix为跨平台。我有以下脚本条目package.json

"scripts": {
    "build": "rimraf dist/ && tsc",
    // other entries
    "prepublish": "if [ ! $SKIP_PREPUBLISH ]; then npm run build; fi"
  },
Run Code Online (Sandbox Code Playgroud)

我想采用if [ ! $SKIP_PREPUBLISH ]; then npm run build; fi并使其跨平台。有没有办法做到这一点?

man*_*c66 -1

从 npm 开始,5.1.0您可以更改脚本 shell。

我将这一行放入.npmrc文件中并且它有效:

script-shell = C:\Program Files\Git\bin\bash.exe

您还可以运行此命令:

npm config set --userconfig script-shell "C:\\Program Files\\Git\\bin\\bash.exe"