简体   繁体   中英

How to base .prettierignore file on .gitignore

Looking at the Prettier docs, there is a tip to base your.prettierignore file on your.gitignore file.

https://prettier.io/docs/en/install.html

Tip. Base your.prettierignore on.gitignore and.eslintignore (if you have one).

Can someone explain what this means and how to do this? Is there a way to automatically add everything to your.prettierignore included in your.gitignore?

You can actually pass a flag to your prettier command --ignore-path and then give it the path of your .gitignore file so it will use that instead of the .prettierignore file.

prettier --ignore-path .gitignore

They're not implying there's an automatic way to do this, but you could cp.gitignore.prettierignore (or copy it some other way, such as in your IDE). There is a proposal to include other ignore files as well as a node tool to automate this for you if you want to, though.

From what I can tell from reading the docs is they mean to have the same files in your .prettierignore as you do in your .gitignore , since anything in .gitignore won't be check into your repository anyway, not that you can point the .prettierignore to .gitignore and have it use that file, though that would be cool. There's a similar issue raised and close here that mentions using symlink since they use the same structure.

Don't copy the file, link it to your.gitignore so they keep in sync if you edit them in the future:

ln -s .gitignore .prettierignore

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM