Javascript 如何从 Windows 控制台停止 webpack 开发服务器?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/36921612/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can I stop webpack dev server from windows console?
提问by Rajab Shakirov
I run webpack-dev-server from windows console with the command:
我使用以下命令从 Windows 控制台运行 webpack-dev-server:
webpack-dev-server --content-base ./build --inline --hot
webpack-dev-server --content-base ./build --inline --hot
after this I see message webpack: bundle is now VALID.
and I can't type anythingthere. But if I change something in webpack.config.js I have to close console, open it again and start webpack-dev-server for apply my changes.
How can I stop webpack dev server withoutclose console?
在此之后,我看到消息webpack: bundle is now VALID.
并且我无法在那里输入任何内容。但是如果我更改 webpack.config.js 中的某些内容,我必须关闭控制台,再次打开它并启动 webpack-dev-server 以应用我的更改。如何在不关闭控制台的情况下停止 webpack 开发服务器?
回答by thitemple
You only need to type Ctrl+C two times
您只需要键入 Ctrl+C 两次
回答by Jason Slobotski
I run webpack devserver by issuing the "npm start" command. I've found that CTRL+C doesn't work for me and just creates an orphaned process. I'm able to kill the devserver by opening the task manager and killing any running node.exe processes.
我通过发出“npm start”命令来运行 webpack devserver。我发现 CTRL+C 对我不起作用,只会创建一个孤立的进程。我可以通过打开任务管理器并终止任何正在运行的 node.exe 进程来终止 devserver。
Another way to do this from plain jane windows console is to find the node process Ids and kill them.
从普通 jane Windows 控制台执行此操作的另一种方法是找到节点进程 ID 并杀死它们。
tasklist /FI "IMAGENAME eq node.exe"
Image Name PID Session Name Session# Mem Usage
========================= ======== ================ =========== ============
node.exe 4620 Console 2 44,568 K
node.exe 12452 Console 2 486,260 K
Then kill them with the following command.
然后使用以下命令杀死它们。
taskkill /F /PID 4620 /PID 12452
An alternative more direct approach as pointed out by a comment.
评论指出的另一种更直接的方法。
taskkill /F /IM node.exe
回答by Jordan Watkins
I have also been running into this hard-to-kill webpack-dev-server process on my Windows machine lately.
我最近也在我的 Windows 机器上遇到了这个难以杀死的 webpack-dev-server 进程。
Ctrl+C/break and even closing were getting me nowhere and I quickly tired of manually tracking down the process and killing it.
Ctrl+C/break 甚至关闭都让我无处可去,我很快厌倦了手动跟踪进程并杀死它。
This one-liner did the trick for me:
这个单线对我有用:
for /f "tokens=5" %a in ('netstat -aon ^| findstr 8080 ^| findstr LISTENING') do taskkill /pid %a /f
I went ahead and made a kill-server.bat file for it:
我继续为它制作了一个 kill-server.bat 文件:
@echo off
for /f "tokens=5" %%a in ('netstat -aon ^| findstr %1 ^| findstr LISTENING') do taskkill /pid %%a /f && echo killed PID %%a
I put that on my PATH, so now to kill a server using a specific port I can just:
我把它放在我的 PATH 上,所以现在要使用特定端口杀死服务器,我可以:
kill-server 8080
On a side note, this issue seems to happen for me only when I use console emulation tools, not when I am using the windows command prompt directly.
附带说明一下,这个问题似乎只有在我使用控制台仿真工具时才会发生,而不是在我直接使用 Windows 命令提示符时发生。
回答by Damien Sawyer
On Windows this Powershell seems to kill it (and all Node processes!)
在 Windows 上,这个 Powershell 似乎杀死了它(以及所有 Node 进程!)
get-process node | Stop-Process
回答by dwjohnston
There appears to be a bug on Git Bash not properly sending the signal to node correctly.
Git Bash 上似乎存在一个错误,无法正确地将信号发送到节点。
I created this bash script:
我创建了这个 bash 脚本:
echo killing process on port
taskkill //PID `netstat -aon | grep | grep -P '(?=LISTENING).*' -o -m1 | grep -P '\d*' -o` //F
Add add it to your PATH
添加 将其添加到您的 PATH
run with kill.sh 8000
for example.
kill.sh 8000
例如运行。
回答by Abdullah Ibn Mannan
- Type: Ctrl+Conce.
- When prompt Terminate batch job (Y/N)?Type: y
- 键入:Ctrl+C一次。
- 当提示Terminate batch job (Y/N) 时?类型:y
Works for me. I've attached the screenshot Thanks! command line screenshot
为我工作。我附上了截图谢谢! 命令行截图
回答by Fabian Picone
How can I stop webpack dev server without close console?
如何在不关闭控制台的情况下停止 webpack 开发服务器?
Go to Task-Manager and close the task Node.js: Server-side JavaScript
.
转到任务管理器并关闭任务Node.js: Server-side JavaScript
。
回答by Michal Filip
In my case it was enough to hit Ctrl+C once. After that, I get two prompts for terminating job: Terminate batch job (Y/N)? ^CTerminate batch job (Y/N)?
就我而言,按一次 Ctrl+C 就足够了。之后,我收到两个终止作业的提示:终止批处理作业 (Y/N)?^C终止批处理作业(是/否)?
After confirming the first, a regular command prompt is shown. But I have to once again write hit "Y" and confirm, which confirms the second background job termination. Otherwise it stays orphaned.
确认第一个后,将显示常规命令提示符。但是我必须再次写下“Y”并确认,这确认了第二个后台作业终止。否则它会保持孤立状态。