Sharing Prettier configurations.
Add @culur/prettier-config dependency to your project.
# Using npm
npm install @culur/prettier-config --save-dev
# Using yarn
yarn add @culur/prettier-config --devThere are three approaches to extend this shared config.
Example: .prettierrc.json.
"@culur/prettier-config"// .prettierrc.js
module.exports = {
...require('@culur/prettier-config'),
semi: false,
};Prettier does not provide a full solution to share the .prettierignore file. But we can still share the file between projects using one of two approaches below.
The simplest way to do this is using --ignore-path CLI option.
prettier ** --write --ignore-path node_modules/@culur/prettier-config/.prettierignoreBy this way, there's no need to create a new file in your project folder. But you also can't extend the .prettierignore file.
If you want to extend the ignore file, run the following command in the root of your project folder:
# unix
cp "node_modules\@culur\prettier-config\.prettierignore" ".prettierignore"
# windows
copy "node_modules\@culur\prettier-config\.prettierignore" ".prettierignore"It will copy the .prettierignore from @culur/prettier-config to your project root folder.
Some commonly used scripts in package.json.
{
"scripts": {
"fix:prettier": "prettier ** --write",
"test:prettier": "prettier ** --list-different"
}
}- Prettier - an opinionated code formatter.
- Prettier - Sharing configurations - Document on sharing prettier configurations.
- Prettier - Ignore Code - Use
.prettierignoreto ignore certain files and folders completely.
{ // ... "prettier": "@culur/prettier-config" }