如何在Visual Studio中为WebCompiler更新Browserslist?
解决Web Compiler 2022+中caniuse-lite过时的问题
方法1:使用Web Compiler自带的Node环境更新依赖
- 打开命令提示符,进入WebCompiler临时目录(示例路径:
C:\Users\[ME]\AppData\Local\Temp\WebCompiler1.14.11\) - 利用目录内自带的
node.exe执行npm命令,规避全局npm与Node版本不兼容的问题:.\node.exe .\node_modules\npm\bin\npm-cli.js install caniuse-lite@latest - 执行完成后重新编译SCSS文件,验证错误是否消失。
方法2:在项目目录配置本地依赖(无需全局Node)
- 在网站项目根目录创建
package.json文件,内容如下:{ "devDependencies": { "autoprefixer": "^10.4.16", "caniuse-lite": "^1.0.30001565" } } - 打开命令提示符进入项目根目录,使用WebCompiler的
node.exe安装依赖(替换为你的临时目录路径):C:\Users\[ME]\AppData\Local\Temp\WebCompiler1.14.11\node.exe C:\Users\[ME]\AppData\Local\Temp\WebCompiler1.14.11\node_modules\npm\bin\npm-cli.js install - 修改
compilerconfig.json.defaults,指定Web Compiler使用项目本地的依赖:"sass": { "autoPrefix": "last 2 versions", "nodeModulesPath": "./node_modules" } - 重新编译SCSS文件即可。
方法3:临时禁用警告(应急方案,不推荐长期使用)
如果暂时无需更新依赖,可在compilerconfig.json.defaults中添加配置关闭Browserslist警告:
"sass": { "autoPrefix": "last 2 versions", "autoprefixerOptions": { "ignoreUnknownVersions": true } }
内容的提问来源于stack exchange,提问作者HFloyd
相关产品推荐
相关产品推荐

