为什么我仍然需要为每个单独的项目安装 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?

我对 VS Code 中的扩展如何工作感到困惑。 "Prettier - Code formatter" 扩展(由 Esben Petersen 设计)已经作为扩展安装在我的 VS Code 中。我的问题是为什么我仍然需要在每个单独的项目中 运行 npm install prettier --save-dev?扩展名不是已经应用到所有文件了吗?

你不知道吗?

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.

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

您似乎希望 Prettier 成为您所有项目在 VS Code 中的代码格式化程序。

在 VS Code 中导航到:

File > Preferences > Settings

搜索“默认格式化程序”

然后select“esbenp.prettier-vscode”