Support config file in ESM (#13130)
This commit is contained in:
1 parent
bb203e3fa5
commit
44d246a2a2
61 files changed
+442
-31
No files matched your search
+21
-5
@@ -8,7 +8,9 @@ Prettier uses [cosmiconfig](https://github.com/davidtheclark/cosmiconfig) for co
|
||||
- A `"prettier"` key in your `package.json` file.
|
||||
- A `.prettierrc` file written in JSON or YAML.
|
||||
- A `.prettierrc.json`, `.prettierrc.yml`, `.prettierrc.yaml`, or `.prettierrc.json5` file.
|
||||
- A `.prettierrc.js`, `.prettierrc.cjs`, `prettier.config.js`, or `prettier.config.cjs` file that exports an object using `module.exports`.
|
||||
- A `.prettierrc.js`, or `prettier.config.js` file that exports an object using `export default` or `module.exports` (depends on the [`type`](https://nodejs.org/api/packages.html#type) value in your `package.json`).
|
||||
- A `.prettierrc.mjs`, or `prettier.config.mjs` file that exports an object using `export default`.
|
||||
- A `.prettierrc.cjs`, or `prettier.config.cjs` file that exports an object using `module.exports`.
|
||||
- A `.prettierrc.toml` file.
|
||||
|
||||
The configuration file will be resolved starting from the location of the file being formatted, and searching up the file tree until a config file is (or isn’t) found.
|
||||
@@ -30,10 +32,22 @@ JSON:
|
||||
}
|
||||
```
|
||||
|
||||
JS:
|
||||
JS(ESM):
|
||||
|
||||
```js
|
||||
// prettier.config.js or .prettierrc.js
|
||||
// prettier.config.js, .prettierrc.js, prettier.config.mjs, or .prettierrc.mjs
|
||||
export default {
|
||||
trailingComma: "es5",
|
||||
tabWidth: 4,
|
||||
semi: false,
|
||||
singleQuote: true,
|
||||
};
|
||||
```
|
||||
|
||||
JS(CommonJS):
|
||||
|
||||
```js
|
||||
// prettier.config.js, .prettierrc.js, prettier.config.cjs, or .prettierrc.cjs
|
||||
module.exports = {
|
||||
trailingComma: "es5",
|
||||
tabWidth: 4,
|
||||
@@ -130,8 +144,10 @@ An example configuration repository is available [here](https://github.com/azz/p
|
||||
> Note: This method does **not** offer a way to _extend_ the configuration to overwrite some properties from the shared configuration. If you need to do that, import the file in a `.prettierrc.js` file and export the modifications, e.g:
|
||||
>
|
||||
> ```js
|
||||
> module.exports = {
|
||||
> ...require("@company/prettier-config"),
|
||||
> import companyPrettierConfig from "@company/prettier-config";
|
||||
>
|
||||
> export default {
|
||||
> ...companyPrettierConfig,
|
||||
> semi: false,
|
||||
> };
|
||||
> ```
|
||||
|
||||
Reference in new issue
Block a user