Prettier is great for code formatting but it breaks Django templates when handling template tags. Thanks to @sezze, prettier-plugin-django-alpine now offers a starting point to solve this problem with relative ease
If you use Prettier for code formatting, and find yourself setting up the prettier plugin for many projects. You might want to automate the prettier configuration steps since it can be repetitive, this script will do that for you.
- VSCode
- VSCode Prettier extension(must be installed via extensions tab in VSCode)
1 install prettier(local installation from npm)
npm install --save-dev --save-exact prettier
2 install prettier-plugin-django-alpine
npm install --save-dev prettier-plugin-django-alpine
3 add .prettierrc file to the project root folder
4 add below code to your .prettierrc file to register the plugin
{
"plugins": ["prettier-plugin-django-alpine"]
}
-
Download this script and save it to any folder of your choice on your computer
-
In your project's root folder, open a terminal and run the code below
python ~/path/to/configure_prettier.py
You can set a bash/cmd/ps alias name for the above command on your OS and call just one command(the alias name) to get up and running
Happy Coding 😊