@better-css-modules/cli

中文文档
0.4.1发布于 2026/10/21MITES Module构建来源已验证近 30 天下载 9672

The generate, check and tokens commands of better-css-modules

原始使用文档
文档目录5 节
  1. Install
  2. Commands
  3. Exit codes
  4. Configuration
  5. License

@better-css-modules/cli

The generate, check and tokens commands of better-css-modules: .d.ts files for CSS Modules, a check for unused classes, impure modules and values that bypass the design tokens, and the tokens written out as DTCG.

Install

pnpm add -D @better-css-modules/cli @better-css-modules/core

The config file imports defineConfig from @better-css-modules/core.

Commands

better-css-modules generate                # write the .d.ts files
better-css-modules generate --watch        # and keep them in sync with the stylesheets
better-css-modules check                   # report problems
better-css-modules check --format github   # as GitHub Actions annotations
better-css-modules tokens                  # print the tokens as DTCG

Every command reads the better-css-modules.config.* in the working directory; --config <path> names another file, relative to the working directory. The directory of the config file is the project root.

check prints one line per problem, then how many there are:

src/Card.tsx:6:22 error usage/unanalyzable: a class is accessed dynamically here, so usage of src/badge.module.css cannot be determined
src/card.module.css:2:10 error tokens/color: #fff is a raw value for color; use a --color-* token
src/card.module.css:4:1 error usage/unused-class: .ghost is never used
src/card.module.css:5:10 error tokens/unknown: --color-fg-bsae is not defined in the global CSS; did you mean --color-fg-base?
src/orphan.module.css:1:1 error usage/unused-module: src/orphan.module.css is never imported
[better-css-modules] 5 problem(s)

and, when there are none:

[better-css-modules] no problems found (1 modules; tokens: color, spacing, radius)

Exit codes

Codegeneratechecktokens
0The types are written, also when include matches no fileNo problemsThe document is printed
1A stylesheet does not parse; its .d.ts is left as it wasProblems were found
2It could not run: an unknown command or option, or a config mistakeIt could not run: the same, an unknown --format, or include matches no file, the global CSS cannot be read, or it does not declare the layerIt could not run: the same, the global CSS cannot be read, or a token has no DTCG name

Configuration

The settings, the rules and how to disable them are described in the project README:

License

MIT

版本与发布记录

@better-css-modules/cli 共发布 8 个版本,首次发布于 2026/03/27;过去 12 个月发布了 8 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.4.1latest2026/10/2117 天前
0.4.02026/10/1425 天前
0.3.02026/10/1325 天前
0.2.12026/10/1326 天前
0.2.02026/10/1029 天前
0.1.32026/07/223 个月前

关于 @better-css-modules/cli 的常见问题

@better-css-modules/cli 是什么?

The generate, check and tokens commands of better-css-modules

如何安装 @better-css-modules/cli?

在项目目录运行 npm install @better-css-modules/cli,或使用 pnpm add / yarn add / bun add。它还提供命令行工具 better-css-modules,可以用 npx better-css-modules 直接运行。

@better-css-modules/cli 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/better-css-modules__cli 是否存在。

@better-css-modules/cli 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@better-css-modules/cli 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=24。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@better-css-modules/cli 可以商用吗?

@better-css-modules/cli 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@better-css-modules/cli 的下载量有多少?

根据 npm 官方下载统计,@better-css-modules/cli 在 2026/10/08 – 2026/11/06 这 30 天内被下载 9,672 次,日均约 322 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@better-css-modules/cli 还在维护吗?

最新版本 0.4.1 发布于 2026/10/21(17 天前);至今共发布 8 个版本,其中过去 12 个月发布了 8 个;首次发布于 2026/03/27。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。