To enable Prettier on save in Visual Studio Code
Install Prettier Extension:
- Open VS Code and go to the Extensions view by clicking on the Extensions icon in the Activity Bar on the side of the window.
- Search for "Prettier - Code formatter" and install it.
Set Prettier as Default Formatter:
- Open the Command Palette by pressing Ctrl + Shift + P (or Cmd + Shift + P on Mac).
- Type and select Preferences: Open Settings (JSON).
- Add the following lines to your settings.json file:
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnSave": true