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

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 6 days ago
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 6 days ago
TypeScript
84%
Other

twenty

CRM

59,615

The open-source CRM you build, ship, and version like the rest of your stack — with customizable objects, AI agents, and a TypeScript SDK.

View details
92
Repo Health
82
Technical
64
Dependency
Built with
TypeScript 84%
MDX 14%
Updated 1 weeks ago
TypeScript
95%
Apache 2.0

Void

AI Code Assistants · Automation · Code Editors

28,733

Open-source AI code editor with direct LLM integration and data privacy

View details
44
Repo Health
84
Technical
68
Dependency
Built with
TypeScript 95%
Updated 5 months ago
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 1 weeks 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 1 weeks 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 6 days ago
TypeScript
96%
GPL 3.0

Wire

Collaboration · Team Chat · Video Conferencing

1,192

Open source end-to-end encrypted messaging for teams and enterprises — self-host for complete control over your communications and data.

View details
93
Repo Health
8
Technical
68
Dependency
Built with
TypeScript 96%
Updated 1 weeks ago
Python
57%
Apache 2.0

Zulip

Team Chat

26,102

Topic-based team chat that brings the structure of email threads to real-time messaging, so distributed teams never lose context across hundreds of concurrent conversations.

View details
96
Repo Health
86
Technical
60
Dependency
Built with
Python 57%
TypeScript 19%
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