style-loader

A webpack loader that injects bundled CSS into the DOM using style or link tags at runtime.

Tool
npm
v4.0.0
1,667 stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
57 /100 Fair
Development Activity 32
Maintenance 28
Community 80
Maturity 60
Momentum 28

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation. How we score it →
71 /100 Good
Architecture 78
Code Quality 78
Innovation 78
Learning Curve 50

style-loader is a webpack loader that takes the CSS output from css-loader and injects it into the document via <style> or <link> tags, letting import "./styles.css" work directly in a JavaScript bundle without a separate static-stylesheet build step. It supports seven injection strategies (injectType) — a plain per-module <style> tag, a shared singleton tag, an IE-aware auto mode, lazy on-demand variants exposing .use()/.unuse(), and a linkTag mode for external stylesheet injection — plus configurable insertion points, custom attributes (including CSP nonces), and CSS Modules class-name exports.

As of webpack 5.104+, native CSS support (experiments.css) covers much of what style-loader historically did, and the maintainers have marked the package deprecated in favor of that built-in path. The loader still works today and becomes a no-op for modules compiled through webpack’s native CSS type, so existing configurations keep functioning while teams migrate rule by rule.

What You Get

  • Seven injectType strategies (styleTag, singletonStyleTag, autoStyleTag, lazyStyleTag, lazySingletonStyleTag, lazyAutoStyleTag, linkTag) covering eager, lazy, and legacy-IE injection modes
  • Runtime DOM API modules (styleDomAPI, singletonStyleDomAPI, insertBySelector, insertStyleElement) that isolate style-tag creation, attribute assignment, and DOM insertion into swappable pieces
  • Hot Module Replacement support that patches injected style content and CSS Modules locals in place without a full page reload
  • CSS Modules support that re-exports the generated class-name locals object alongside the injected styles
  • Configurable attributes, including CSP nonce handling, and a custom insertion target via a CSS selector or an absolute path to a custom insert function

Common Use Cases

  • Development-mode webpack setups that want instant CSS updates via HMR without a separate extraction step
  • Prototypes and small apps where a single injected style tag is simpler than configuring MiniCssExtractPlugin
  • CSS Modules projects that need the generated class-name map exported alongside the injected styles
  • Migrating a rule-by-rule webpack config to native CSS support while leaving not-yet-migrated rules on style-loader

Under The Hood

Architecture

style-loader’s real work happens in loader.pitch (src/index.js), which runs before the request is resolved and returns a string of generated JavaScript rather than transforming file content directly — a standard webpack loader pattern but used here as the entire mechanism. Based on the injectType option, pitch selects which small runtime modules under src/runtime/ to stitch together (styleDomAPI/singletonStyleDomAPI for tag creation, insertBySelector/insertStyleElement for DOM placement, injectStylesIntoStyleTag/injectStylesIntoLinkTag as the reference-counted update orchestrator, isEqualLocals for HMR diffing), with src/utils.js providing a consistent family of getImportXCode/getXCode functions that emit either ESM or CJS import statements depending on the esModule option. The orchestrator in injectStylesIntoStyleTag.js maintains a module-level stylesInDOM array keyed by an id+index identifier and reference-counts each style block so shared CSS across multiple importing modules is inserted once and torn down only when its last reference is removed.

Tech Stack

The loader itself is plain JavaScript compiled with Babel (@babel/core, @babel/preset-env) from src/ to dist/cjs.js and dist/esm.js, then validated with es-check to confirm the runtime bundle stays ES3-compatible for legacy-browser support (a hard requirement since these runtime files ship inside end-user application bundles, not just the build). It declares zero runtime dependencies and a single peer dependency on webpack ^5.27.0. Tooling includes ESLint 9’s flat config with a shared eslint-config-webpack preset, Prettier, cspell for documentation spell-checking, and Husky/commitlint/standard-version enforcing conventional commits for changelog-driven releases.

Code Quality

The test suite (13 files under test/, run via Jest with jest-environment-jsdom) exercises each injectType mode, option combination (attributes, insert, esModule, base, styleTagTransform), and the CJS entry point, using snapshot testing for generated loader output. CI runs the full lint suite (ESLint, Prettier, cspell) across Node LTS on every push and PR, plus a separate GitHub Actions dependency-review job on PRs. There is no static typing (no TypeScript, no JSDoc type-checking) — correctness relies on the test suite and runtime es-check validation rather than a type system.

API Design The public surface is a single loader string plus a handful of well-documented options (injectType, attributes, insert, base, esModule, styleTagTransform), so a typical webpack rule needs only use: ["style-loader", "css-loader"] to work. The seven injectType values are additive rather than requiring separate configuration files, and the lazy variants expose a small, consistent .use()/.unuse() API for on-demand injection. The README documents every option with runnable webpack-config examples, keeping the boilerplate needed to get started minimal even though the underlying code-generation mechanism is non-trivial.

Used by 54 apps in this directory

TypeScript
99%
MIT

React Cosmos

Developer Tools

8,690

An open-source sandbox for developing and testing React and React Native UI components in isolation, with pluggable bundler support for Vite and Webpack.

View details
76
Repo Health
69
Technical
73
Dependency
Built with
TypeScript 99%
Updated 1 weeks ago
Python
45%
Other

Redash

Analytics · Data Engineering

28,849

Redash lets anyone connect to 35+ SQL and NoSQL data sources, write a query in the browser, and turn the result into a shared dashboard — no separate BI suite required.

View details
91
Repo Health
74
Technical
61
Dependency
Built with
Python 45%
JavaScript 29%
TypeScript 19%
Updated 1 weeks ago
TypeScript
97%
AGPL 3.0

Responsively App

Design Tools · Developer Tools

25,464

Preview and interact with your responsive web design across every device size simultaneously — no more manual resizing.

View details
79
Repo Health
71
Technical
66
Dependency
Built with
TypeScript 97%
Updated 3 weeks ago
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 6 days ago
TypeScript
67%
MIT

Scalar

Developer Tools

16,313

Beautiful, interactive OpenAPI documentation with a built-in offline-first API client and multi-language code generation — all in one open-source platform.

View details
90
Repo Health
89
Technical
65
Dependency
Built with
TypeScript 67%
Vue 29%
Updated 6 days ago
JavaScript
89%
GPL 3.0

Screenity

Productivity · Video Editors

18,806

Free, privacy-first Chrome screen recorder with real-time annotation, AI camera blur, and a built-in video editor — no sign-in or limits required.

View details
74
Repo Health
62
Technical
70
Dependency
Built with
JavaScript 89%
Updated 1 weeks ago
Python
57%
Other

Sentry

Analytics · Developer Tools · Monitoring

45,632

Developer-first error tracking and performance monitoring platform with AI-powered root-cause analysis across 20+ languages and frameworks.

View details
95
Repo Health
80
Technical
66
Dependency
Built with
Python 57%
TypeScript 42%
Updated 6 days ago
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 1 weeks ago
TypeScript
89%
Other

strapi

CMS

73,368

Open-source headless CMS that auto-generates REST and GraphQL APIs from your content models, with a fully customizable admin panel you control.

View details
93
Repo Health
84
Technical
63
Dependency
Built with
TypeScript 89%
JavaScript 11%
Updated 1 weeks ago

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