Skip to content

获取已启动

¥Getting started

安装

¥Install

安装 @commitlint/cli 和你选择的 @commitlint/config-*/commitlint-config-* 作为 devDependency,并配置 commitlint 以使用它。

¥Install @commitlint/cli and a @commitlint/config-* / commitlint-config-* of your choice as devDependency and configure commitlint to use it.

sh
npm install -D @commitlint/cli @commitlint/config-conventional
sh
yarn add -D @commitlint/cli @commitlint/config-conventional
sh
pnpm add -D @commitlint/cli @commitlint/config-conventional
sh
bun add -d @commitlint/cli @commitlint/config-conventional
sh
deno add -D npm:@commitlint/cli npm:@commitlint/config-conventional

配置

¥Configuration

配置 commitlint 以使用常规配置

¥Configure commitlint to use conventional config

sh
echo "export default { extends: ['@commitlint/config-conventional'] };" > commitlint.config.js

Node v24 改变了模块的加载方式,这也包括 commitlint 配置文件。如果你的项目不包含 `package.json`,commitlint 可能无法加载配置,从而导致出现 `Please add rules to your commitlint.config.js` 错误消息。此问题可通过以下任一方式解决:

¥[!WARNING] Node v24 changes the way that modules are loaded, and this includes the commitlint config file. If your project does not contain a package.json, commitlint may fail to load the config, resulting in a Please add rules to your commitlint.config.js error message. This can be fixed by doing either of the following:

  • 添加一个 package.json 文件,将你的项目声明为 ES6 模块。运行 npm init es6 即可轻松完成此操作。

    ¥Add a package.json file, declaring your project as an ES6 module. This can be done easily by running npm init es6.

  • 将配置文件从 commitlint.config.js 重命名为 commitlint.config.mjs

    ¥Rename the config file from commitlint.config.js to commitlint.config.mjs.

请参阅 配置文档 获取更多信息。

¥Refer to configuration documentation for more information.