The way I found to share my favorite prettier config across projects
npm i -D @tidusia/prettier-config prettier
Then create a .prettierrc.js
file at the root of your project with the following content :
module.exports = require("@tidusia/prettier-config");
Add the following scripts to your package.json :
{
"scripts": {
"prettier:write": "prettier . --write",
"prettier:check": "prettier . --check"
}
}
The prettier:write
command will format all files in your project.
The format:check
do not change files but check that all files are formatted properly. Something you can use in a pre-commit / CI for example.
For example, in Webstorm, open "Preferences" -> "Languages & Frameworks" -> "JavaScript" -> "Prettier" (you need the Prettier plugin).
Choose your preferred prettier package (from node_module VS globally installed for example). Update the "Run for files:" glob pattern to whatever you find usefull in your project.