vscode + wsl2

1. enable wsl2

2. install ubuntu

3. 

sudo apt update
sudo apt install nodejs
sudo apt install npm
npm install --global yarn
sudo apt install git-all

3.1 ---题外话

  遇到了node版本过高导致无法 install 的问题。所以 使用nvm安装低版本的nodejs

  

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bash

or
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bash

关闭窗口重新打开,

export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"  # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && . "$NVM_DIR/bash_completion"  # This loads nvm bash_completion

查看version list

nvm ls-remote
nvm install 6.14.4 # or 10.10.0, 8.9.1, etc
nvm install node # "node" is an alias for the latest version
nvm use node

4. clone the repo

5. npm install under the repo

6. access wsl:Ubuntu via vs-code's Remote tool

 7. current issue, seems wsl app can not access windows host api TODO: -- should be fix this

8. 获取wsl ip 配置

ip route | grep default | awk '{print $3}'

hostname -I | awk '{print $1}'
# 直接放开 `vEthernet (WSL)` 这张网卡的防火墙
New-NetFirewallRule -DisplayName "WSL" -Direction Inbound -InterfaceAlias "vEthernet (WSL)" -Action Allow

 9. 如果访问外部api,则没有问题了。但是如果想本地debug,那么iis express 无法在局域网内访问,

安装ConveyorbyKeyoti, 并且需要注意,wsl2 的内部ip是类似于172.21.127.140这类的,外部主机是172.21.127.1,

所以需要在ConveyorbyKeyoti中进行一下配置映射。

https://marketplace.visualstudio.com/items?itemName=vs-publisher-1448185.ConveyorbyKeyoti

10. all work now。 这样子,在有linebreak-style检查的项目中就不会 很难受了。毕竟windows下的这种检查很是烦人。



原文地址:https://www.cnblogs.com/fengyishou/p/14585183.html