Assume that we have JS project and we need to enable there automatic formatting.
First of all we have to install prettier as dependency into the project. Execute in project directory where package.json is located:
npm install --save-dev --save-exact prettier
or using yarn
:
yarn add prettier --dev --exact
Now we need to enable formatting on save in Visual Studio Code.
Navigate to setting using menu File -> Preferences -> Settings
or using Ctrl+,
key combination. Then search in settings for Format On Save
and enable it.
At this moment everything should work. Try to navigate to some .ts
or .js
file, reindent some row and hit Ctrl+S
.