简体   繁体   English

为什么我仍然需要为每个单独的项目安装 prettier,而它已经作为 vs code 中的扩展安装了?

[英]Why do I still need to install prettier to each individual project while it has already been installed as an extension in vs code?

I am confused with how the extensions in VS Code work.我对 VS Code 中的扩展的工作方式感到困惑。 The "Prettier - Code formatter" extension (by Esben Petersen) is already installed as an extension in my VS Code. “Prettier - Code formatter”扩展(由 Esben Petersen 提供)已经作为扩展安装在我的 VS Code 中。 My question is why I still need to run npm install prettier --save-dev in each individual project?我的问题是为什么我仍然需要在每个单独的项目中运行npm install prettier --save-dev Isn't it true that the extensions are already applied to all files?扩展名不是已经应用于所有文件吗?

You don't?你没有?

Should prettier not be installed locally with your project's dependencies or globally on the machine, the version of prettier that is bundled with the extension will be used.如果 prettier 没有与您的项目的依赖项一起安装在本地或在机器上全局安装,则将使用与扩展捆绑在一起的 prettier 版本。

https://github.com/prettier/prettier-vscode#prettier-resolution https://github.com/prettier/prettier-vscode#prettier-resolution

It seems like you want Prettier to be your code formatter in VS Code for all of your projects.似乎您希望 Prettier 成为 VS Code 中所有项目的代码格式化程序。

In VS Code navigate to:在 VS Code 中导航到:

File > Preferences > Settings文件 > 首选项 > 设置

Search for "Default formatter"搜索“默认格式化程序”

And then select "esbenp.prettier-vscode"然后选择“esbenp.prettier-vscode”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM