postcss-loader

Runs PostCSS plugins on your CSS as part of a webpack build pipeline.

Tool
npm
v8.2.1
2,839 stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
64 /100 Good
Development Activity 52
Maintenance 36
Community 68
Maturity 60
Momentum 40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation. How we score it →
80 /100 Excellent
Architecture 85
Code Quality 88
Innovation 80
Learning Curve 65

postcss-loader integrates PostCSS into webpack’s module pipeline, letting any file matched by a CSS-type rule pass through a chain of PostCSS plugins before webpack’s built-in CSS support (or css-loader) processes it further. It resolves plugins and options either from loader options or from a standalone PostCSS config file, walking up the directory tree via cosmiconfig to find package.json’s postcss key, a postcss.config.js, or a .postcssrc variant, and it forwards PostCSS’s dependency, warning, and asset messages back into the webpack compilation so watch mode and caching stay accurate.

Because it sits directly ahead of tools like autoprefixer, postcss-preset-env, and CSS Modules processing, it’s the piece that makes those plugins run at build time rather than only at authoring time — most teams that use PostCSS inside a webpack project reach it through this loader rather than calling PostCSS’s own API directly.

What You Get

  • Plugin pipeline integration — runs any PostCSS plugin chain against matched files inside a webpack use array, either as static options or an object built from a function of the loader context.
  • Automatic config discovery — searches package.json, postcss.config.{js,mjs,cjs,ts,mts,cts}, and .postcssrc variants up the directory tree via cosmiconfig, so most projects need zero loader options.
  • Source map passthrough — honors webpack’s devtool setting or an explicit sourceMap option, normalizing map source paths before and after PostCSS processing.
  • CSS-in-JS support — the execute option runs JS-authored style modules through Node’s module system first, so the postcss-js parser can process them like ordinary CSS.
  • Dependency and asset wiring — converts PostCSS’s own dependency, build-dependency, missing-dependency, context-dependency, and asset messages into webpack’s addDependency/emitFile calls automatically.

Common Use Cases

  • Running autoprefixer or postcss-preset-env inside a webpack CSS pipeline for vendor prefixing and future-syntax support.
  • Processing CSS Modules alongside PostCSS transforms using webpack’s built-in css/auto module type.
  • Compiling SugarSS or other custom PostCSS syntaxes ahead of the rest of a webpack CSS build.
  • Sharing a single postcss.config.js across multiple tools — webpack via this loader, and CI/scripts via postcss-cli.
  • Styling with CSS-in-JS by pairing the execute option with the postcss-js parser.

Under The Hood

Architecture

The project is a single-purpose webpack loader split cleanly into two files: src/index.js, the loader entry point that follows webpack’s async loader contract (this.async(), this.getOptions(schema), addDependency/emitFile) and orchestrates config loading, plugin resolution, PostCSS execution, and message translation; and src/utils.js, a set of pure/stateless helpers for config discovery, plugin normalization, source-map path rewriting, and error/warning formatting. The loader detects a compatible PostCSS AST already produced by an earlier loader in the chain (meta.ast, version-checked with semver) and reuses it instead of re-parsing, and it falls back to a one-time warning (guarded by module-level state in hasExplicitDependencyOnPostCSS) when it detects a PostCSS 7 processor without an explicit postcss dependency. The design is shallow and easy to reason about — one stateful entry point, one library of pure helpers.

Tech Stack

Written in modern JavaScript (ES modules), built to CommonJS via Babel (@babel/cli/@babel/preset-env) for distribution as dist/cjs.js. Configuration discovery is delegated to cosmiconfig 9, with jiti 2 used to load TypeScript/ESM config files on the fly and semver 7 used for AST-version compatibility checks. postcss and webpack are peer dependencies (webpack optional, @rspack/core also supported as an optional peer), keeping the loader’s own dependency footprint deliberately small. Tests run under Jest with ts-jest/babel-jest transforms and a custom in-repo webpack-compile harness; releases are cut with standard-version.

Code Quality

The repo has nine dedicated Jest test files (loader, config-autoload, execute, implementation, postcssOptions, sourceMap, validate-options, builtInCss, cjs) using snapshot assertions against a shared test/helpers webpack-compile harness, giving good coverage of the loader’s actual runtime behavior rather than just its exports. Errors are handled explicitly throughout — config loading, plugin loading, and PostCSS processing are each wrapped in try/catch and converted into loader callback errors, with a dedicated CssSyntaxError formatter for readable output. CI (GitHub Actions nodejs.yml) runs lint and test on every push, eslint-config-webpack plus cspell enforce style and spelling, and husky/lint-staged/commitlint gate commits. There are no TypeScript source files (options are validated at runtime via a JSON Schema in src/options.json), though src/config.d.ts ships hand-written types for consumers.

API Design The public surface is deliberately small: a single postcssOptions value that can be a static object or a function of the loader context, plus sourceMap, implementation, and execute. Config-file cascading (via cosmiconfig) means most projects need no loader options at all — use: ["postcss-loader"] and a postcss.config.js is enough — while defaults for source maps (inherited from webpack’s devtool) and config lookup keep everyday configuration close to zero. Escape hatches (implementation override for downstream tooling migrating PostCSS majors, execute for CSS-in-JS, string paths for parser/stringifier/syntax) are opt-in rather than required, which keeps the common path simple without limiting advanced use.

Used by 38 apps in this directory

TypeScript
97%
Other

Rocket.Chat

Team Chat

46,304

The secure, self-hosted team communications platform for organizations that cannot compromise on data sovereignty.

View details
96
Repo Health
79
Technical
63
Dependency
Built with
TypeScript 97%
Updated yesterday
TypeScript
83%
AGPL 3.0

Standard Notes

Note Taking

6,681

End-to-end encrypted notes and files — private by design, built to last, and fully self-hostable.

View details
89
Repo Health
83
Technical
68
Dependency
Built with
TypeScript 83%
JavaScript 14%
Updated 2 days ago
Python
71%
Apache 2.0

SurfSense

AI Assistants · Search

16,586

The open-source, unlimited NotebookLM alternative with real-time collaboration, a desktop app, and no vendor lock-in.

View details
88
Repo Health
71
Technical
66
Dependency
Built with
Python 71%
TypeScript 27%
Updated yesterday
JavaScript
93%
Apache 2.0

swagger-ui

Developer Tools

29,042

Transform OpenAPI specifications into interactive, browser-based API documentation that developers and consumers can explore and test live.

View details
98
Repo Health
83
Technical
62
Dependency
Built with
JavaScript 93%
Updated 2 days ago
HTML
68%
AGPL 3.0

ToolJet

AI Agents · Low Code Platforms · No Code Platforms

41,123

Open-source AI-native platform to build and deploy internal tools, workflows, and AI agents with a visual drag-and-drop builder and 80+ data source integrations.

View details
94
Repo Health
81
Technical
63
Dependency
Built with
HTML 68%
JavaScript 20%
Updated yesterday
TypeScript
99%
Apache 2.0

Trigger.dev

AI Development · Automation · Developer Tools

16,606

Build and deploy fully-managed AI agents and background jobs in TypeScript — with no timeouts, durable retries, real-time observability, and elastic scaling built in.

View details
90
Repo Health
9
Technical
63
Dependency
Built with
TypeScript 99%
Updated yesterday
PHP
84%
MIT

wallabag

Bookmarks Archiving

13,023

Self-hosted read-it-later app that saves clean, ad-free articles from any webpage for distraction-free reading across all your devices.

View details
93
Repo Health
81
Technical
60
Dependency
Built with
PHP 84%
Twig 13%
Updated 2 days ago
TypeScript
87%
Other

Webiny JS

Blogging · CMS · Ecommerce

8,047

Open-source, self-hosted CMS on AWS serverless — a TypeScript framework you extend with code, not a product you configure through a UI.

View details
90
Repo Health
86
Technical
61
Dependency
Built with
TypeScript 87%
JavaScript 12%
Updated 2 days ago
TypeScript
41%
AGPL 3.0

Wiki.js

Collaboration · Knowledge Management

29,081

A modern, self-hosted wiki platform built on Node.js with a rich plugin ecosystem for authentication, search, storage, and rendering that adapts to any team's infrastructure.

View details
95
Repo Health
67
Technical
60
Dependency
Built with
TypeScript 41%
Vue 39%
JavaScript 16%
Updated yesterday

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers