@better-css-modules/turbopack

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

Next.js / Turbopack integration for better-css-modules

原始使用文档
文档目录4 节
  1. Install
  2. Usage
  3. Configuration
  4. License

@better-css-modules/turbopack

Next.js (Turbopack) integration for better-css-modules. It generates the .d.ts files for CSS Modules when Next.js loads its config, keeps them in sync during next dev, and puts every module in the cascade layer the config names.

Install

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

The config file imports defineConfig from @better-css-modules/core, and the CLI runs check. The integration needs Next.js 16.

Usage

// next.config.ts
import type { NextConfig } from "next";
import { withBetterCssModules } from "@better-css-modules/turbopack";

const nextConfig: NextConfig = {
  reactStrictMode: true,
};

export default withBetterCssModules(nextConfig);

withBetterCssModules(nextConfig?, { config? }) returns an async config function. Put it outside every other wrapper, around the config object they return: a wrapper that takes only an object cannot take a function. config is the config file to use, relative to the working directory; by default it is the better-css-modules.config.* there.

  • When Next.js loads its config in the development server or production build phase, as next dev, next build and next typegen do, it reads the config and generates every .d.ts once. In any other phase it leaves the Next.js config as it is.
  • In the development server phase, as during next dev, a watcher brings the .d.ts of each added, changed or removed stylesheet in line. It does not keep the process alive.
  • A config it cannot load rejects the config function, which stops Next.js. A stylesheet that does not parse is reported, and its .d.ts is left as it was.
  • Only when the config names a layer does it add a loader to turbopack.rules["*.module.css"], which puts each included module in the layer. The loader runs before any loaders already under that key and keeps the files CSS Modules under their own names; it refuses a list of several rules under that key. It reads the global CSS again when one of its files changes.
  • The better-css-modules config is read when Next.js loads its own, so restart next dev after changing it.

The types are generated here rather than in the loader, because Turbopack's persistent cache skips loaders for files that did not change. The integration runs no checks; run better-css-modules check for them.

Configuration

The settings go in better-css-modules.config.ts; see the project README for setting up Next.js, including tsconfig.json, the configuration and cascade layers.

License

MIT

版本与发布记录

@better-css-modules/turbopack 共发布 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/turbopack 的常见问题

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

Next.js / Turbopack integration for better-css-modules

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

在项目目录运行 npm install @better-css-modules/turbopack,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:next(^16.0.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

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

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

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

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

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

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

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

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

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

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

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

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