Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
195 views
in Technique[技术] by (71.8m points)

How to set shell for npm run-scripts in Windows

I'm running npm on Windows and would like to use & style parallel operations in run-scripts but running in parallel in cmd is kind of messy in my package.json file I'd like to write-

scripts: { "go": "cmd1 & cmd2"} 

but npm executes the script under cmd.exe which does not know about ; I could change this to scripts: { "go": "bats/bat1.bat") where bat1.bat is a cmd bat file that uses the windows style call or start commands to run commands in parallel. which works but gives me a script that only works on Windows.

It would be a lot simpler if I could get npm to run the script under a bash clone or cygwin.

I tried config: { "shell": "bash"} but that still ran cmd.exe

Is there any way to tell npm to run-scripts using a specific shell (not cmd.exe)?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Since npm 5.1

npm config set script-shell "C:\Program Files (x86)\git\bin\bash.exe"  

or (64bit installation)

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

Note that you need to have git for windows installed.

You can revert it by running:

npm config delete script-shell

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...