Ignoring Code
Use .prettierignore to ignore (i.e. not reformat) certain files and folders completely.
Use “prettier-ignore” comments to ignore parts of files.
Ignoring Files: .prettierignore
To exclude files from formatting, create a .prettierignore file in the root of your project. .prettierignore uses gitignore syntax.
Example:
# Ignore artifacts:
build
coverage
# Ignore all HTML files:
**/*.html
It’s recommended to have a .prettierignore in your project! This way you can run prettier --write . to make sure that everything is formatted (without mangling files you don’t want, or choking on generated files). And – your editor will know which files not to format!
By default prettier ignores files in version control systems directories (".git", ".jj", ".sl", ".svn" and ".hg") and node_modules (unless the --with-node-modules CLI option is specified). Prettier will also follow rules specified in the ".gitignore" file if it exists in the same directory from which it is run.
So by default it will be
**/.git
**/.svn
**/.hg
**/node_modules
and
**/.git
**/.svn
**/.hg
if --with-node-modules CLI option provided
(See also the --ignore-path CLI option.)
JavaScript
A JavaScript comment of // prettier-ignore will exclude the next node in the abstract syntax tree from formatting.
For example:
matrix(
1, 0, 0,
0, 1, 0,
0, 0, 1,
);
// prettier-ignore
matrix(
1, 0, 0,
0, 1, 0,
0, 0, 1,
);
will be transformed to:
matrix(1, 0, 0, 0, 1, 0, 0, 0, 1);
// prettier-ignore
matrix(
1, 0, 0,
0, 1, 0,
0, 0, 1,
);
JSX
<div>
{/* prettier-ignore */}
<span ugly format='' />
</div>
HTML
<!-- prettier-ignore -->
<div class="x" >hello world</div >
<!-- prettier-ignore-attribute -->
<div
(mousedown)=" onStart ( )