Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

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

visual studio code - Automatically start/stop webserver in vscode debug

When debugging a web project, it needs to be built, served by a webserver, and opened in a browser, with a debugger attached. The issue comes with the webserver. I'd like it to:

  • start automatically, when doing the first debugging
  • keep running, and not restart every time
  • stop, when vscode is closing (preferably along with a manual way to stop it, but that's typically easy)

Following are my observations, each of which may be wrong, along with some considerations:

For background tasks in vscode, there is no simple "is running" check. Task "completion" is measured by using regex on stdout. This is intended for watchers - a build edits a file, this is noticed, the watcher outputs some text message, and vscode accepts that as the task being completed. A normal webserver doesn't watch files though, it is simply running. Using anything but vscode tasks makes shutting down the webserver when exiting difficult, as there appears to be no "task on exit".

An attempt to solve the issues would be to introduce an intermediate (custom) program, and use that as background task, which in turn starts the webserver. It would be accompanied by yet another (custom) program, which would be put as a task in front, signals the background-task-program, which in turn then gives any output to stdout, so vscode finally accepts the task as completed. While i say "custom program", these would in reality probably be one script with different arguments. However, it still implies dealing with a multi-process environment, with all the difficulties involved, e.g. proper and guaranteed closing of child processes, IPS, etc.

This seems quite convoluted and dirty. Is there really no better way?


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

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...