code serve-web
is a locally hosted version of Visual Studio Code for the Web (Note that it's different from VSCode Server).
To run it within a WSL such that it can be accessed via the Windows host's browser:
- Install VSCode on the WSL distrbution via official download page. For example, download and install the
.deb
files on Debian WSL:sudo apt install ./code_xxxx.deb
- Enable WSL to run crontab on startup 1 (systemd is by default not available in WSL 2):
echo '[boot]\ncommand="service cron start"' | sudo tee -a /etc/wsl.conf > /dev/null
- Add the command into crontab:
crontab -e @reboot DONT_PROMPT_WSL_INSTALL=1 /usr/bin/code serve-web --host 127.0.0.1 --port 59005 --without-connection-token
- Restart WSL:
wsl.exe --shutdown
- Now open the browser on Windows host, and access http://127.0.0.1:59005.