|
| 1 | +# Migrating from Prettier to Oxfmt |
| 2 | + |
| 3 | +If you currently use Prettier as your code formatter, you can follow this guide to migrate to Oxfmt. |
| 4 | + |
| 5 | +Note that Oxfmt is in alpha, and may not be suitable for production use in complex setups. |
| 6 | +For the beta milestone, we may provide migration commands. |
| 7 | + |
| 8 | +> oxfmt: `--migrate prettier` · Issue #15849 · oxc-project/oxc\ |
| 9 | +> https://github.com/oxc-project/oxc/issues/15849 |
| 10 | +
|
| 11 | +## Caveats for migrating to Oxfmt |
| 12 | + |
| 13 | +Before migrating, ensure that the current release of the Oxfmt alpha meets your project's needs. It is almost entirely compatible with Prettier v3.7 already for basic configurations, but less-common config options and other features are not yet implemented. |
| 14 | + |
| 15 | +<!-- TODO: Remove this note when oxfmt 0.17.0 ships with many of the missing languages. --> |
| 16 | + |
| 17 | +The Oxfmt alpha only supports formatting JavaScript and TypeScript files (including those with JSX syntax). If you need support for non-JSX frameworks like Vue or Ember, or other languages like JSON, YAML, or Markdown, you will likely want to wait. |
| 18 | + |
| 19 | +Other important considerations when migrating from Prettier to Oxfmt: |
| 20 | + |
| 21 | +- Oxfmt's formatting output is closest to Prettier v3.7. You will see more differences migrating from an older version of Prettier. |
| 22 | +- Oxfmt uses a `printWidth` of 100 characters by default, whereas Prettier's default is 80. Make sure to set `"printWidth": 80` in `.oxfmtrc.jsonc` to minimize differences if you use the Prettier default. |
| 23 | +- Prettier plugins are not yet supported. |
| 24 | +- Some Prettier options are not supported. See the [oxfmt CLI documentation](/docs/guide/usage/formatter/config-file-reference.html) for the full list of currently-supported options. |
| 25 | +- Oxfmt supports an `--lsp` flag to spin up a Language Server Protocol server, but editor/IDE integration is still being developed and has not been tested/documented yet for most editors. |
| 26 | + |
| 27 | +Many of these limitations will be addressed in the future, with the Beta or Stable releases of Oxfmt. |
| 28 | + |
| 29 | +See also [the Oxfmt FAQ](/docs/guide/usage/formatter.html#faqs) for any other potential caveats or limitations you may need to consider. |
| 30 | + |
| 31 | +## Step 1: Upgrade Prettier to v3.7 (Optional) |
| 32 | + |
| 33 | +This step is optional, but will make it easier to determine which differences between Oxfmt and Prettier are "real". |
| 34 | + |
| 35 | +To minimize the number of changes when migrating to Oxfmt, you should upgrade Prettier to version 3.7 first and reformat all JS/TS files with it, as it is the latest release of Prettier (from Nov 2025) and will be most similar to the output of Oxfmt. |
| 36 | + |
| 37 | +## Step 2: Install Oxfmt |
| 38 | + |
| 39 | +Install Oxfmt as a development dependency with your package manager of choice: |
| 40 | + |
| 41 | +::: code-group |
| 42 | + |
| 43 | +```bash [npm] |
| 44 | +$ npm add -D oxfmt@latest |
| 45 | +``` |
| 46 | + |
| 47 | +```bash [pnpm] |
| 48 | +$ pnpm add -D oxfmt@latest |
| 49 | +``` |
| 50 | + |
| 51 | +```bash [yarn] |
| 52 | +$ yarn add -D oxfmt@latest |
| 53 | +``` |
| 54 | + |
| 55 | +```bash [bun] |
| 56 | +$ bun add -D oxfmt@latest |
| 57 | +``` |
| 58 | + |
| 59 | +```bash [deno] |
| 60 | +$ deno add -D npm:oxfmt@latest |
| 61 | +``` |
| 62 | + |
| 63 | +::: |
| 64 | + |
| 65 | +## Step 3: Migrate Prettier configuration file |
| 66 | + |
| 67 | +`.oxfmtrc.jsonc` is the configuration file for Oxfmt. Only JSON files are supported. |
| 68 | + |
| 69 | +A basic `.oxfmtrc.jsonc` file looks like this: |
| 70 | + |
| 71 | +```jsonc |
| 72 | +{ |
| 73 | + "$schema": "./node_modules/oxfmt/configuration_schema.json", |
| 74 | + "printWidth": 80, |
| 75 | +} |
| 76 | +``` |
| 77 | + |
| 78 | +If you have a basic `.prettierrc` file, you can simply rename the file with `mv .prettierrc .oxfmtrc.jsonc`. |
| 79 | + |
| 80 | +If you are using something other than JSON to configure Prettier, you will need to convert the configuration to JSON. |
| 81 | + |
| 82 | +### `prettierrc.js` |
| 83 | + |
| 84 | +Here's an example of migrating a `prettierrc.js` file. |
| 85 | + |
| 86 | +Before: |
| 87 | + |
| 88 | +```js |
| 89 | +module.exports = { |
| 90 | + singleQuote: true, |
| 91 | + jsxSingleQuote: true, |
| 92 | +}; |
| 93 | +``` |
| 94 | + |
| 95 | +After (`.oxfmtrc.jsonc`): |
| 96 | + |
| 97 | +```jsonc |
| 98 | +{ |
| 99 | + "$schema": "./node_modules/oxfmt/configuration_schema.json", |
| 100 | + "singleQuote": true, |
| 101 | + "jsxSingleQuote": true, |
| 102 | + "printWidth": 80, |
| 103 | +} |
| 104 | +``` |
| 105 | + |
| 106 | +### `prettierrc.yaml` |
| 107 | + |
| 108 | +Here's an example of migrating a `prettierrc.yaml` file. |
| 109 | + |
| 110 | +Before: |
| 111 | + |
| 112 | +```yaml |
| 113 | +trailingComma: "es5" |
| 114 | +tabWidth: 4 |
| 115 | +semi: false |
| 116 | +singleQuote: true |
| 117 | +``` |
| 118 | +
|
| 119 | +After (`.oxfmtrc.jsonc`): |
| 120 | + |
| 121 | +```jsonc |
| 122 | +{ |
| 123 | + "$schema": "./node_modules/oxfmt/configuration_schema.json", |
| 124 | + "trailingComma": "es5", |
| 125 | + "tabWidth": 4, |
| 126 | + "semi": false, |
| 127 | + "singleQuote": true, |
| 128 | + "printWidth": 80, |
| 129 | +} |
| 130 | +``` |
| 131 | + |
| 132 | +## Step 4: Update Formatting Scripts |
| 133 | + |
| 134 | +Update any formatting scripts you currently have, for example in `package.json`, shell scripts, or pre-commit scripts. |
| 135 | + |
| 136 | +### `package.json` scripts |
| 137 | + |
| 138 | +```diff |
| 139 | +{ |
| 140 | + "scripts": { |
| 141 | +- "format": "prettier --write .", |
| 142 | ++ "format": "oxfmt", |
| 143 | +- "format:check": "prettier --check ." |
| 144 | ++ "format:check": "oxfmt --check" |
| 145 | + } |
| 146 | +} |
| 147 | +``` |
| 148 | + |
| 149 | +### CI Workflows |
| 150 | + |
| 151 | +Update any CI workflows that run Prettier, particularly `prettier --check`. |
| 152 | + |
| 153 | +```diff |
| 154 | + - name: Check formatting |
| 155 | +- run: yarn prettier --check . |
| 156 | ++ run: yarn oxfmt --check |
| 157 | +``` |
| 158 | + |
| 159 | +### Git Hooks (e.g. husky, lint-staged) |
| 160 | + |
| 161 | +```diff |
| 162 | +"lint-staged": { |
| 163 | +- "*": "prettier --write --no-error-on-unmatched-pattern" |
| 164 | ++ "*": "oxfmt --no-error-on-unmatched-pattern" |
| 165 | +} |
| 166 | +``` |
| 167 | + |
| 168 | +## Step 5: Run formatter |
| 169 | + |
| 170 | +Run Oxfmt on your codebase to check for any changes and ensure that the configuration was migrated correctly: |
| 171 | + |
| 172 | +```sh |
| 173 | +# Your script specified in Step 4 |
| 174 | +npm run format |
| 175 | +``` |
| 176 | + |
| 177 | +If you no longer need Prettier, you can uninstall for now. |
| 178 | + |
| 179 | +## Done! |
| 180 | + |
| 181 | +You have now migrated to Oxfmt :) |
| 182 | + |
| 183 | +Please see the section below for any additional, optional steps you may need to take. |
| 184 | + |
| 185 | +These are only applicable for some setups, so skip them if they don't apply to you. |
| 186 | + |
| 187 | +### Update editor integrations |
| 188 | + |
| 189 | +See [the Formatter FAQ](../formatter.md#how-does-editor-integration-work') for details on editor/IDE integration with Oxfmt. |
| 190 | + |
| 191 | +### Update `CONTRIBUTING.md` and `AGENTS.md`/`CLAUDE.md` |
| 192 | + |
| 193 | +If you have a `CONTRIBUTING.md` file that references Prettier, update those references to use Oxfmt. |
| 194 | + |
| 195 | +If you use an `AGENTS.md` or `CLAUDE.md` file to help LLM tools understand your codebase, you should also check for references to Prettier in those files. |
| 196 | + |
| 197 | +### Update lint rules |
| 198 | + |
| 199 | +If you have any lint rules that explicitly check for Prettier formatting (e.g. `eslint-plugin-prettier`), you should remove them. |
| 200 | + |
| 201 | +While you're at it, you could also consider migrating to [oxlint](../linter.md) ;) |
| 202 | + |
| 203 | +### Create/update `.git-blame-ignore-revs` |
| 204 | + |
| 205 | +If you want to avoid extra noise in your `git blame` history, you can add the commit SHA where you reformatted files using Oxfmt to your `.git-blame-ignore-revs` file. This will make `git blame` ignore that commit when showing blame information. This file is supported natively by git, and by both GitHub and GitLab. |
0 commit comments