はじめる
インストール方法
Section titled “インストール方法”Biomeをインストールする最も速い方法は、 npm
またはお好みのパッケージマネージャーを使用することです。
これにはNode.js v14.18以降が必要です。
Node.jsをインストールせずにBiomeを使用したい場合は、スタンドアロン実行形式としてCLIを利用できます。
Biomeをインストールするには、 package.json
ファイルが含まれるディレクトリで次のコマンドを実行します。
npm install --save-dev --save-exact @biomejs/biome
pnpm add --save-dev --save-exact @biomejs/biome
bun add --dev --exact @biomejs/biome
deno add --dev npm:@biomejs/biome
yarn add --dev --exact @biomejs/biome
プロジェクトごとに biome.json
または biome.jsonc
(設定ファイル)を作成することを推奨します。
これにより、コマンドを実行するたびにCLIのオプションを繰り返し指定する必要がなくなり、エディタ上で同じ設定を適用できるようになります。
もしBiomeのデフォルト設定に満足している場合は、新たに設定ファイルを作成する必要はありません。
biome.json
ファイルを作成するには、プロジェクトのルートディレクトリで init
コマンドを実行します:
npx @biomejs/biome init
pnpm exec biome init
bunx --bun biome init
deno run -A npm:@biomejs/biome init
yarn exec biome init
--jsonc
オプションを渡すことで、 biome.jsonc
ファイルを代わりに生成します。
init
コマンドを実行すると、そのディレクトリに biome.json
ファイルが新規作成されます:
{ "$schema": "https://biomejs.dev/schemas/2.0.6/schema.json", "vcs": { "enabled": false, "clientKind": "git", "useIgnoreFile": false }, "files": { "ignoreUnknown": false }, "formatter": { "enabled": true, "indentStyle": "tab" }, "linter": { "enabled": true, "rules": { "recommended": true } }, "javascript": { "formatter": { "quoteStyle": "double" } }, "assist": { "enabled": true, "actions": { "source": { "organizeImports": "on" } } }}
linter.enabled: true
はリンタを有効にし、 rules.recommended: true
は推奨ルールを有効にします。
これはデフォルトの設定と対応しています。
この設定では、formatter.enabled: false
で明示的にフォーマットを無効化していないため、フォーマットは有効になっています。
Biome CLIには多くのコマンドとオプションが用意されているので、あなたが必要なものだけを使用できます。
format
コマンドを --write
オプションを指定し実行することで、ファイルやディレクトリをフォーマットできます。
npx @biomejs/biome format --write <files>
pnpm exec biome format --write <files>
bunx --bun biome format --write <files>
deno run -A npm:@biomejs/biome format --write <files>
yarn exec biome format --write <files>
lint
コマンドを --write
オプションを指定し実行することで、ファイルやディレクトリに対してLintを実行し、安全な修正を適用できます。
npx @biomejs/biome lint --write <files>
pnpm exec biome lint --write <files>
bunx --bun biome lint --write <files>
deno run -A npm:@biomejs/biome lint --write <files>
yarn exec biome lint --write <files>
check
コマンドを実行することで、それら両方のコマンドを実行できます。
npx @biomejs/biome check --write <files>
pnpm exec biome check --write <files>
bunx --bun biome check --write <files>
deno run -A npm:@biomejs/biome check --write <files>
yarn exec biome check --write <files>
check
コマンドは複数のツールを一度に実行するためのコマンドです。現在は以下のことを行います。
- ファイルのフォーマット
- ファイルのリント
- インポートの整理
エディタプラグインのインストール
Section titled “エディタプラグインのインストール”Biomeの機能を最大限活用するために、エディタプラグインをインストールすることを推奨しています。エディタのページを参照して、どのエディタがBiomeをサポートしているかを確認してください。
CIのセットアップ
Section titled “CIのセットアップ”Node.jsを使用している場合、BiomeをCIで実行するには、お気に入りのパッケージマネージャを使用することが推奨されます。 このようにすることで、CIパイプラインがエディタ上やローカルでCLIコマンドを実行するときと同じバージョンのBiomeを使用することを保証できます。 代わりに、専用のCIアクションを利用することもできます。
次のステップ
Section titled “次のステップ”成功です!これでBiomeを使う準備が整いました。🥳
- ESLintとPrettierと移行する
- Biomeの設定について詳しく知る
- Formatterの使い方と設定方法について詳しく知る
- Linterの使い方と設定方法について詳しく知る
- CLIオプションを使いこなす
- 設定オプションを使いこなす
- Discordのコミュニティに参加する