Prettier - HTML 和 JS 的配置

我想在一个配置文件 .prettierrc 中为 HTML 和 JS 指定字符串长度。

 module.exports = {
  singleQuote: true,printWidth: 80,[HTML]: {
    printWidth: 150,},};

但在日志中我得到了:

ReferenceError: HTML is not defined
Bactryki 回答:Prettier - HTML 和 JS 的配置

您应该使用 .prettierrc 格式,当您使用此格式时,visual studio code 也会提供智能感知。

您收到错误是因为:

  • 文件需要为 JSON 格式,
  • 任何覆盖都需要在 overrides JSON 键下指定

在您的情况下,文件应如下所示:

.prettierrc

{
  "singleQuote": true,"printWidth": 80,"overrides": [
    {
      "files": ["**/*.html"],"options": {
        "printWidth": 150
      }
    }
  ]
}
本文链接:https://www.f2er.com/1877.html

大家都在问