Use in big projects
Este conteúdo não está disponível em sua língua ainda.
In big projects, such as monorepos or workspaces that contain multiple projects, each project often needs its own settings. Biome lets you use a configuration file per project, extend the root configuration, and share configuration files between folders.
Use multiple configuration files
Section titled “Use multiple configuration files”Biome uses the nearest biome.json file. It starts in the folder you run it from and moves up through the parent folders until it finds one.
You can use this behavior to apply different settings to each project or folder. For example, take a project that contains a backend app and a frontend app:
Directoryapp
Directorybackend
- biome.json
- package.json
Directoryfrontend
- biome.json
Directorylegacy-app
- package.json
Directorynew-app
- package.json
When you run Biome inside app/backend, Biome uses the configuration file app/backend/biome.json. When you run it from app/frontend/legacy-app or app/frontend/new-app, Biome uses the configuration file app/frontend/biome.json.
Monorepo
Section titled “Monorepo”A monorepo is a repository that stores and maintains multiple packages. Each package can contain its own configuration.
Biome supports monorepos out of the box. The following steps set up a monorepo with three packages:
- biome.json
Directorypackages
Directoryanalytics
- biome.json
Directorygenerate
- biome.json
Directorylogger
- biome.json
-
Create a
biome.jsonfile at the root of the monorepo. This one enables the recommended rules and customizes the formatter options:biome.json {"linter": {"enabled": true,"rules": {"preset": "recommended"}},"formatter": {"lineWidth": 120,"indentStyle": "space","indentWidth": 4}}This file is the root configuration, and it sets the base options of the project. Nested configurations can choose whether to follow these options.
-
Create a nested configuration file in each package that needs one. A nested configuration file must set the
"root"field tofalse.To make a package follow the standards of the root configuration, use
"extends": "//". It tells Biome to extend the root configuration, wherever the nested configuration is.The following files configure two packages.
packages/loggerdisablesnoConsole, andpackages/generatedisables the formatter, because its files are generated:packages/logger/biome.json {"root": false,"extends": "//","linter": {"rules": {"suspicious": {"noConsole": "off"}}}}packages/generate/biome.json {"root": false,"extends": "//","formatter": {"enabled": false}}When you use
"extends": "//", you can omit"root": false, because"//"already implies that the configuration is not a root configuration:packages/generate/biome.json {"root": false,"extends": "//","formatter": {"enabled": false}} -
Configure a package that must not inherit the root options. In this example, a different team maintains
packages/analyticsand follows entirely different coding standards. Its configuration omits"extends": "//"and sets its own formatting options:packages/analytics/biome.json {"root": false,"formatter": {"lineWidth": 100}} -
Run
biomecommands from the root of the project or from a single package. Biome applies the settings of every configuration file in both cases.
Share the configuration
Section titled “Share the configuration”The extends field splits your configuration across multiple files, so you can share common settings across different projects or folders. "extends": "//" is a shortcut to extend the root configuration from a nested configuration. For other setups, extends also accepts an array, where every value is the path to another configuration to extend.
For example, this configuration extends a common.json configuration file:
{ "extends": ["./common.json"]}Biome resolves the entries of extends from the path of the biome.json file. It processes them in the order they are listed, and settings in later files override earlier ones.
Files that you extend can also extend other files.
Relative paths in a shared configuration are resolved from the directory containing the configuration that extends it, not from the directory containing the shared file. Plugin paths follow the same rule by default.
To load a plugin that ships with a shared configuration, see Load a plugin from a shared configuration.
For example, take a project with two directories, backend/ and frontend/. Each has its own biome.json, and both extend a common.json configuration in the root folder:
Directorybackend/
Directorysrc/
- …
Directorytest/
- …
- biome.json
Directoryfrontend/
Directorysrc/
- …
Directorytest/
- …
- biome.json
- common.json
{ "files": { "includes": ["src/**/*.js", "test/**/*.js"] }, "linter": { "includes": ["**", "!test/**"] }}{ "extends": ["../common.json"]}- When you run Biome from the
frontend/folder, it formats all JavaScript files in thefrontend/src/andfrontend/test/folders, and only lints the files in thefrontend/src/folder. This works because Biome interprets the paths incommon.jsonfrom thefrontend/folder, where thebiome.jsonfile is. - If
backend/biome.jsonhas the same content asfrontend/biome.json, Biome behaves the same way, except that it interprets the paths from thebackend/folder.
In this setup, both frontend/biome.json and backend/biome.json are root configurations. You cannot run Biome from the root of the repository, unless you use the --config-path CLI option and point it at one of the configurations.
To share your configuration file across multiple projects, publish it as an npm package.
© 2023-present Biome developers and contributors.