No longer maintained, try https://github.com/mikew/prettier_d_slim instead (context)
Makes prettier the fastest formatter on the planet.
- "But prettier is pretty fast already, right?"
- Install
- Usage
- How does this work?
- Commands
- Editor integration
Yes, it's actually super fast. But the node.js startup time and loading all the
required modules slows down formatting times. prettier_d
reduces this
overhead by running a server in the background. It brings the formatting time
down from 0.25
seconds to 0.1
seconds on a 3265
byte file
If you want to format from within your editor whenever you save a file, prettier_d
is for you.
This will install the prettier_d
command globally:
yarn global add https://github.com/josephfrazier/prettier_d
# or
npm install -g https://github.com/josephfrazier/prettier_d
To start the server and format a file, just run:
prettier_d file.js
On the initial call, the prettier_d
server is launched and then the given file
is formatted. Subsequent invocations are super fast.
The first time you use prettier_d
, a little server is started in the background
and bound to a random port. The port number is stored along with a
token in the root directory of your repo (or ~/.prettier_d
if the repo root can't be found). You can then run prettier_d
commands the
same way you would use prettier
and it will delegate to the background server.
Control the server like this:
prettier_d <command>
Available commands:
start
: start the serverstop
: stop the serverstatus
: print out whether the server is currently runningrestart
: restart the server[options] file.js
file.js
: invokeprettier
with the given options. Theprettier
engine will be created in the current directory. If the server is not yet running, it is started.
prettier_d
will select a free port automatically and store the port number
along with an access token in the root directory of your repo (or ~/.prettier_d
if the repo root can't be found).
Type prettier_d --help
to see the supported prettier
options.
See https://github.com/prettier/prettier#editor-integration
If you use Vim, and you'd like prettier_d
to format your code as you type, install Neoformat and add this to your ~/.vimrc
:
autocmd FileType javascript setlocal formatprg=prettier_d\ --parser=babel
autocmd BufWritePre,TextChanged,InsertLeave *.js Neoformat
" Use formatprg when available
let g:neoformat_try_formatprg = 1
" https://github.com/sbdchd/neoformat/issues/25
let g:neoformat_only_msg_on_error = 1
Then, make sure you've started the server: prettier_d start
.
This will format your code:
- before each save
- whenever text is changed in normal mode
- whenever you leave insert mode
JavaScript
· TypeScript
· Flow
· JSX
· JSON
CSS
· SCSS
· Less
HTML
· Vue
· Angular
GraphQL
· Markdown
· YAML
Your favorite language?
Prettier is an opinionated code formatter. It enforces a consistent style by parsing your code and re-printing it with its own rules that take the maximum line length into account, wrapping code when necessary.
foo(reallyLongArg(), omgSoManyParameters(), IShouldRefactorThis(), isThereSeriouslyAnotherOne());
foo(
reallyLongArg(),
omgSoManyParameters(),
IShouldRefactorThis(),
isThereSeriouslyAnotherOne()
);
Prettier can be run in your editor on-save, in a pre-commit hook, or in CI environments to ensure your codebase has a consistent style without devs ever having to post a nit-picky comment on a code review ever again!
Show the world you're using Prettier →
[![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettier)
See CONTRIBUTING.md.