Webpack loader that injects CSS into the DOM by appending <style> or <link> tags. Version 4.0.0 (April 2024) requires webpack 5.27+ and Node.js 18.12+. Commonly paired with css-loader for development workflows. Supports multiple injection strategies (styleTag, singletonStyleTag, lazyStyleTag, linkTag) and can use CSS modules. Not recommended for production without additional configuration (e.g., ExtractTextPlugin). Maintained by the webpack-contrib team with regular updates.
npm install style-loaderVerified import paths — ran on the pinned version, not inferred.
Basic webpack configuration using style-loader and css-loader to bundle CSS into a JavaScript bundle.
Upgrade webpack to >=5.27.0 and Node.js to >=18.12.0.
Remove 'modules.namedExport' from style-loader options; configure CSS modules in css-loader instead.
Use MiniCssExtractPlugin for production builds instead of style-loader.
Use 'styleTag' (default) or 'linkTag' if source maps are needed.
If you used an inline function for 'insert', move it to a separate module and reference its path.
Use `import * as styles from './styles.css'` and access classes via `styles['my-class']`.
Run `npm install --save-dev style-loader` to install the package.
Add 'css-loader' to the use array: use: ['style-loader', 'css-loader']
Use a CSS selector string or a path to a module that exports the insert function.