설치


pnpm add -D prettier
# with plugin
pnpm add -D prettier @ianvs/prettier-plugin-sort-imports prettier-plugin-sh

설정 파일


Configuration File · Prettier

prettier.config.mjs 예시

/** @type {import("prettier").Config} */
const config = {
  // default options (explicitly set options)
  printWidth: 80,
  trailingComma: "all",
  singleQuote: false,
  semi: true,
  arrowParens: "always",

  // plugins
  plugins: ["@ianvs/prettier-plugin-sort-imports", "prettier-plugin-sh"],

  importOrder: [
    "<BUILTIN_MODULES>",
    "<THIRD_PARTY_MODULES>",
    "^@/(.*)$",
    "^@test/(.*)$",
    "^[./]",
    "^public/(.*)$",
  ],
  importOrderParserPlugins: ["typescript", "jsx", "decorators-legacy"],
  importOrderTypeScriptVersion: "5.0.0",
};

export default config;

package.json에 format 명령어 추가

"format": "prettier --write \\"bsrc/**/*.{js,jsx,ts,tsx,md,json,css,html}\\""
"format": "prettier --write \\"{src,test}/**/*.{js,jsx,ts,tsx,md,json,css,html}\\""