项目中为了保证import的内容按照一定的顺序进行排序,prettier中会引入prettier-plugin-organize-imports插件。但是此插件的默认行为会将引入但是没有使用的包在保存时直接删除掉,查询文档发现为了规避这种破坏性更改需要增加一条配置"organizeImportsSkipDestructiveCodeActions": true,

完整的.prettierrc配置内容为

{
  "printWidth": 100,
  "singleQuote": true,
  "trailingComma": "all",
  "proseWrap": "never",
  "Semicolons": true,
  "organizeImportsSkipDestructiveCodeActions": true,
  "overrides": [{ "files": ".prettierrc", "options": { "parser": "json" } }],
  "plugins": ["prettier-plugin-organize-imports", "prettier-plugin-packagejson"]
}