@frappe/esbuild-plugin-postcss2

中文文档
0.1.3发布于 2022/03/15MITTypeScriptESM + CJS近 30 天下载 90.1万

Use postcss with esbuild

原始使用文档
文档目录5 节
  1. Install
  2. Usage
  3. PostCSS plugins
  4. CSS modules
  5. Preprocessors

Looking for a maintainer!

Unfortunately I don't have time for this plugin. Please contact me if you'd like to take on this project.

esbuild-plugin-postcss2

This plugin is an optimized, type-friendly version of esbuild-plugin-postcss. It supports CSS preprocessors and CSS modules.

Install

yarn add -D esbuild-plugin-postcss2

or

npm i -D esbuild-plugin-postcss2

Usage

Add the plugin to your esbuild plugins:

const esbuild = require("esbuild");
const postCssPlugin = require("esbuild-plugin-postcss2");

esbuild.build({
  ...
  plugins: [
    postCssPlugin.default()
  ]
  ...
});

PostCSS plugins

Add your desired PostCSS plugin to the plugins array:

const autoprefixer = require("autoprefixer");

esbuild.build({
  ...
  plugins: [
    postCssPlugin.default({
      plugins: [autoprefixer]
    })
  ]
  ...
});

CSS modules

PostCSS modules are enabled by default. You can pass in a config or disable it with the modules field:

postCssPlugin.default({
  // pass in `postcss-modules` custom options
  // set to false to disable
  modules: {
    getJSON(cssFileName, json, outputFileName) {
      const path = require("path");
      const cssName = path.basename(cssFileName, ".css");
      const jsonFileName = path.resolve("./build/" + cssName + ".json");

      fs.writeFileSync(jsonFileName, JSON.stringify(json));
    }
  }
});

As per standard any file having module before the extension (ie somefile.module.css) will be treated as a module. The option fileIsModule allows to override this behavior.

postCssPlugin.default({
  // pass a custom `fileIsModule` option to tell whether a file should be treated as a module
  // in this example we want everything to be a module except file finishing with `global.css`
  fileIsModule: (filepath) => !filepath.endsWith(".global.css")
});

Preprocessors

To use preprocessors (sass, scss, stylus, less), just add the desired preprocessor as a devDependency:

yarn add -D sass

版本与发布记录

@frappe/esbuild-plugin-postcss2 共发布 2 个版本,首次发布于 2022/03/14;过去 12 个月发布了 0 个版本。

版本发布日期距今
0.1.3latest2022/03/154 年前
0.1.22022/03/144 年前

关于 @frappe/esbuild-plugin-postcss2 的常见问题

@frappe/esbuild-plugin-postcss2 是什么?

Use postcss with esbuild

如何安装 @frappe/esbuild-plugin-postcss2?

在项目目录运行 npm install @frappe/esbuild-plugin-postcss2,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:less(^4.x)、sass(^1.x)、stylus(^0.x)、postcss(8.x)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@frappe/esbuild-plugin-postcss2 支持 TypeScript 吗?

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

@frappe/esbuild-plugin-postcss2 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@frappe/esbuild-plugin-postcss2 可以商用吗?

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

@frappe/esbuild-plugin-postcss2 的下载量有多少?

根据 npm 官方下载统计,@frappe/esbuild-plugin-postcss2 在 2026/10/16 – 2026/11/14 这 30 天内被下载 901,219 次,日均约 30,041 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@frappe/esbuild-plugin-postcss2 还在维护吗?

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