Fortunately I finally figured out how to do it:
- Install NodeJS (I recommend doing it using nvm) and Yarn (npm is fine as well, but I prefer Yarn)
- Set up a package.json file, e.g. by running yarn init
- Install Prettier, Babel-eslint, eslint and eslint-plugin-babel:
yarn add --dev prettier eslint babel-eslint eslint-plugin-babel - In IntelliJ, go to File > Settings > Plugins > Marketplace and install "File Watchers" and "Prettier"
- In IntelliJ, set up File Watchers for HTML under File > Settings > Tools > File Watchers and add a watcher for the file type HTML, set up the arguments --parser html --write $FilePathRelativeToProjectRoot$ and under "Advanced Options" make sure that the options "Auto-save edited files to trigger the watcher" and "Trigger the watcher regardless of syntax erorrs" are unchecked.
- Create a .prettierrc file in the project's root directory with at least this configuration: {
"htmlWhitespaceSensitivity": "ignore"
} - this will prevent Prettier formatting closing ">" characters from inline HTML tags to sometimes end up on separate lines.
Hooray, now IntelliJ does a nice HTML file formatting the way a frontend developer like me can enjoy it.