Setting up Prettier
Quickly configure Prettier for your Astro project!
Prettier Plugin for Astro
Start by installing prettier
& prettier-plugin-astro
using your preferred package manager:
Next, update your Prettier config in the project’s root to include prettier-plugin-astro
plugin. This example will use .prettierrc.json
:
That’s it. Run prettier --write .
command with your preferred package manager to format all of the astro files in the project.
Additionally if you are using the VSCode Prettier Extension, you can set the following VSCode Config in your User/Workspace Settings:
and now Prettier will format any selected document.
Adding an NPM script
You can use Prettier CLI with your preferred package manager by adding following scripts in package.json
of your project’s directory:
Prettier Plugin for Tailwind CSS
When using the Tailwind CSS integration, there is another dev dependency for automated class sorting: prettier-plugin-tailwindcss.
Start by installing prettier-plugin-tailwindcss
using your preferred package manager:
Next, update the Prettier Config to include following plugins. This example will use .prettierrc
:
Make sure to place the Tailwind CSS plugin at the end. Additionally, you might need to reload your VSCode Window if Prettier is not working as expected.