use*_*444 61 windows shell npm
我在windows上运行npm并且想在运行脚本中使用&style并行操作但是在cmd中并行运行在我的package.json文件中有点乱 - 我想写 -
脚本:{"go":"cmd1&cmd2"}
但是npm执行cmd.exe下的脚本,该脚本不知道; 我可以将其更改为脚本:{"go":"bats/bat1.bat")其中bat1.bat是一个cmd bat文件,它使用windows样式调用或启动命令来并行运行命令.哪个有效,但给了我一个仅适用于Windows的脚本
如果我可以让npm在bash克隆或cygwin下运行脚本我会尝试配置:{"shell":"bash"}但是仍然运行cmd.exe会简单得多
有没有办法告诉npm使用特定的shell(而不是cmd.exe)运行脚本?
Dun*_*Kim 97
从npm 5.1开始
npm config set script-shell "C:\\Program Files (x86)\\git\\bin\\bash.exe"
Run Code Online (Sandbox Code Playgroud)
或(64位安装)
npm config set script-shell "C:\\Program Files\\git\\bin\\bash.exe"
Run Code Online (Sandbox Code Playgroud)
请注意,您需要安装git for windows.
npm config delete script-shell
Run Code Online (Sandbox Code Playgroud)
Cra*_*sen 23
这是一种方法:
在package.json文件中,添加一行以使用bash运行脚本.例如:
"scripts": {
"boogie": "bash bin/my_script.sh"
}
Run Code Online (Sandbox Code Playgroud)现在,您可以通过以下命令从npm运行bash脚本:
npm run-script boogie
Run Code Online (Sandbox Code Playgroud)
不是很优雅,但它的工作原理.
如果您在Windows和Linux/Unix中进行开发,那么至少这种方法对两种环境都是相当便携的.
Jer*_*yal 16
您还可以对 npm 脚本使用跨平台 powershell https://github.com/powershell/powershell#get-powershell。
要设置单个项目,请从项目根文件夹运行:
npm config set script-shell pwsh --userconfig ./.npmrc
Run Code Online (Sandbox Code Playgroud)
为所有节点项目进行全局设置:
npm config set script-shell pwsh [--global]
Run Code Online (Sandbox Code Playgroud)
Cra*_*sen 15
理想情况下,覆盖npm shell配置参数应该可以工作,但是在Windows中似乎npm(至少版本1.4.14)忽略该设置并改为使用cmd.exe.
在bash或Git Bash shell中使用以下命令来查找shell设置:
$ npm config ls -l | grep shell
Run Code Online (Sandbox Code Playgroud)
默认情况下,输出将是:
shell = "C:\\WINDOWS\\system32\\cmd.exe"
Run Code Online (Sandbox Code Playgroud)
但是,要覆盖默认的shell参数,可以将npmrc文件添加(或编辑)到\ Users\yourusername\AppData\Roaming \npm\etc目录.只需添加以下行:
shell = "C:\\Program Files (x86)\\git\\bin\\bash.exe"
Run Code Online (Sandbox Code Playgroud)
您使用的路径可以是bash.exe的任何有效路径.现在,如果运行上面的"npm config ls -l | grep shell"命令,您将看到以下输出,表明shell参数已被覆盖:
shell = "C:\\Program Files (x86)\\git\\bin\\bash.exe"
; shell = "C:\\WINDOWS\\system32\\cmd.exe" (overridden)
Run Code Online (Sandbox Code Playgroud)
也许有一天,新版本的npm会关注被覆盖的shell参数.
归档时间: |
|
查看次数: |
34431 次 |
最近记录: |