Prettier - HTML 和 JS 的配置

Prettier - Config for HTML and JS

我想在一个配置文件 .prettierrc.

中为 HTML 和 JS 指定字符串长度
 module.exports = {
  singleQuote: true,
  printWidth: 80,
  [HTML]: {
    printWidth: 150,
  },
};

但在日志中我得到:

ReferenceError: HTML is not defined

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

您收到错误是因为:

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

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

.prettierrc

{
  "singleQuote": true,
  "printWidth": 80,
  "overrides": [
    {
      "files": ["**/*.html"],
      "options": {
        "printWidth": 150
      }
    }
  ]
}