April 5, 2020
VSCode has great support for prettier. Learn how to configure it to maximize using pretter across your company's projects and teams.
Hit the ground running with Visual Studio Code (VSCode) by installing the best extensions to make you productive.
While Visual Studio 2019 is a great IDE, its support for modern web development front-end toolkits is lacking. One such integration that is fairly incomplete in Visual Studio 2019 is integration with is the Prettier code formatter.
Install through VS Code extensions. Search for Prettier - Code formatter
Visual Studio Code Market Place: Prettier - Code formatter
Can also be installed in VS Code:
shellext install esbenp.prettier-vscode
Format on Save
From VSCode, open "File > Preferences > Settings"
Choose the level of setting you'd like to manage:
User
(applies to all workspaces on this machine)Workspace
(applies to just this workspace)Search for format on save
Editor: Format on Save
if it isn't already checkedRequire Prettier config to avoid mistakenly formatting files that are not explicitly opted in to using prettier.
From VSCode, open "File > Preferences > Settings"
Choose the level of setting you'd like to manage:
User
(applies to all workspaces on this machine)Workspace
(applies to just this workspace)Search for prettier
Prettier: Require Config
Prettier: Require Config
if it isn't already checkedVisual Studio will now look for a prettier config and, if it finds one, will format the file any time you save! Don't worry about tabbing or semicolons again -- prettier will handle all the heavy lifting.
Prettier (and its VSCode extension supports) a number of configuration files:
"prettier"
key in your package.json
file..prettierrc
file, written in JSON or YAML, with optional extensions: .json/.yaml/.yml
(without extension takes precedence)..prettierrc.js
or prettier.config.js
file that exports an object..prettierrc.toml
file, written in TOML (the .toml
extension is required).I recommend using all the prettier defaults, and creating a .prettierrc
file in the topmost directory in your project you want to use prettier with
An empty .prettierrc
file will do the trick to enable auto-formatting.
.prettierrc{}
Once added benefit to the Prettier: Require Config
setting in VSCode if you're working with a large project that hasn't fully been migrated to use prettier for the whole setup, adding directory-level configuration files enables granular migration to prettier.
Further reading...