prettier-tailwind-plugin 在我在 VSCode 中保存时没有按预期工作。

huangapple go评论62阅读模式
英文:

prettier-tailwind-plugin isn't working as expected when I hit save in VSCode

问题

I installed the prettier-plugin-tailwindcss and it successfully sorts the Tailwind classes when I run Prettier using npx prettier --write index.html. However, when I hit save in VScode, the prettier-plugin-tailwindcss doesn't sort the Tailwind classes as expected.

I'm following this tutorial and this documentation. As you can see I set the dev dependency correctly and have a .prettierrc.json in the project.``

prettier-tailwind-plugin 在我在 VSCode 中保存时没有按预期工作。

prettier-tailwind-plugin 在我在 VSCode 中保存时没有按预期工作。

I was expecting that when I hit save it will automatically work as expected which is to sort tailwind classes but the plugin only works if run the prettier using npx prettier --write index.html

Things I tried:

I set the format on save to true and set the paths but it didn't resolve the problem.

prettier-tailwind-plugin 在我在 VSCode 中保存时没有按预期工作。

英文:

I installed the prettier-plugin-tailwindcss and it successfully sorts the Tailwind classes when I run Prettier using npx prettier --write index.html. However, when I hit save in VScode, the prettier-plugin-tailwindcss doesn't sort the Tailwind classes as expected.

I'm following this tutorial and this documentation. As you can see I set the dev dependency correctly and have a .prettierrc.json in the project.``

prettier-tailwind-plugin 在我在 VSCode 中保存时没有按预期工作。

prettier-tailwind-plugin 在我在 VSCode 中保存时没有按预期工作。

I was expecting that when I hit save it will automatically work as expected which is to sort tailwind classes but the plugin only works if run the prettier using npx prettier --write index.html

Things I tried:

I set the format on save to true and set the paths but it didn't resolve the problem.

prettier-tailwind-plugin 在我在 VSCode 中保存时没有按预期工作。

答案1

得分: 1

转到“设置 > 文本编辑器 > 格式”并选择“保存时格式化”。

英文:

Go to Settings > Text Editor > Formatting and select "Format on Save".

答案2

得分: 1

EDIT:
此外,我发现如果有无效的HTML,prettier会报错,不会进行格式化。您可以在终端中检查这些错误 'CTRL + SHIFT + U'。这可能更多是关于'Prettier'而不是TailwindCSS的问题。

我过去几天一直遇到这个问题,经过数小时的浪费时间后,我终于解决了它,但我仍然不知道是什么确切地修复了它,但这是我所做的,希望能帮助其他人。

请注意,一切都对我正常工作,然后无缘无故停止工作,最后我通过变得沮丧并强行解决了这个问题,以下是我采取的最终步骤:

  1. 我彻底删除了 'the.prettierrc.json' 文件
  2. 设置 -> 搜索:'prettier' -> 取消选中 'Prettier: Require Config' 复选框。
  3. 我禁用了几乎所有我没有使用的扩展程序。我试图定位格式化应用程序并进行了大规模清理。
  4. 我打开了一个要测试的文件 -> CTRL + SHIFT + P -> 'Format Document With'

这导致了一个以前没有的提示,要求我选择默认的格式化程序 -> 选择 'Prettier'。

其中一个事情解决了问题,现在一切恢复正常。

英文:

EDIT:
Also, I found out that if there's invalid html, prettier will spit errors and no formatting will happen. You can check for those errors in the terminal 'CTRL + SHIFT + U'. Probably more of a 'Prettier' thing rather than TailwindCSS thing.


I've had this issue for the past few days and I've managed to solve it after hours of wasted time and I still don't know what precisely fixed it, but here's what I did, hopefully it will help someone else out.

Just note, everything was working normally for me, then it stopped for no apparent reason, in the end I solved it by getting frustrated and I just brute forcing my way out, here's the finals steps I took:

  1. I deleted 'the.prettierrc.json' file altogether
  2. Settings -> Search: 'prettier' -> Uncheck the 'Prettier:Require Config' box.
  3. I disabled pretty much any extension I wasn't using. I was trying to target formatting apps and decided on a big clean up.
  4. I opened a file to test with -> CTRL + SHIFT + P
    -> 'Format Document With'

This resulted in a prompt I hadn't had previously which asked me to choose my default formatter

-> Choose 'Prettier'.

One of those things did it, now I'm back in business.

huangapple
  • 本文由 发表于 2023年3月3日 23:24:39
  • 转载请务必保留本文链接:https://go.coder-hub.com/75628944.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定