author: Nathannie
date: 2022 年 6 月 22 日 15:56:08
问题背景
环境参数:
在 vscode 编写网页,应用插件 Live Server, 在网页文件中,鼠标右键抉择【Open with Live Server】,弹出提示框,并未跳转到浏览器页面。
图 1 - 鼠标右键选项界面
报错信息
报错内容:Invalid Path in liveServer settings root settings Live Server will serve from workspace root
报错截图:
图 2 - 报错 提示框
问题剖析
一个我的项目能够有一个独自的 vscode 配置,构造如下。
project
|——.vscode
|——settings.json
而当前情况是在 c 盘桌面创立一个文件夹,并创立 .html
文件用于测试。live server 采纳的是默认 root
配置, 而不是我的项目的设置。因而须要批改 live server 的 root
配置,使得每一个我的项目都有各自的 root
配置。
问题解决
参考 github 上一个答复:
@cohn17 I had some issues too. What I did was:
援用
- Create a folder under the root of the site, called
.vscode
- Add a file there, called
settings.json
Edit the file and add the following:
援用{"liveServer.settings.root": "/dist"}
援用
(dist
being the root folder I want the liveserver to know about)
援用
Then I actually had to edit the global settings.json:
援用- CTRL+SHIFT+P and type “Preferences”.
- Search for “liveserver” and click “Edit in settings.json”
援用
援用- I then added the same code inside my global settings.json:
援用
援用- Then launched liveserver, killed it, removed the setting in the global settings.json and then relaunched the server.
援用
From now on, liveserver seems to follow whatever is written in the /.vscode/settings.json – file. Perhaps a bug in vscode?
援用
⚠️ 留神:批改为
liveServer.settings.root: "/dist"
后,以后演示的状况,点击【Open with Live Server】,后端口号一直的批改并且随同着提示框一直闪动。猜想可能是以后零碎端口号有余,live Server 正在寻找可用端口导致的。
"liveServer.settings.port": 3248
相干参考
- https://github.com/ritwickdey…
- https://github.com/ritwickdey…