A webpack loader that automatically injects CSS preprocessor resources (variables, mixins, functions) into all processed style files for Sass, SCSS, Less, and Stylus. v1.5.0 is the latest stable release, compatible with webpack 3, 4, and 5. It eliminates the need for manual @import statements in every file, simplifies theme customization (e.g., overriding Ant Design variables), and supports custom injectors (prepend/append) as well as glob patterns. Unlike similar tools (e.g., sass-loader prependData), it works across multiple preprocessors and allows resource file globbing.
npm install style-resources-loaderVerified import paths — ran on the pinned version, not inferred.
Configures style-resources-loader to automatically prepend SCSS variables and mixins to all .scss files via webpack.
Order in use array: ... 'style-loader', 'css-loader', 'sass-loader', 'style-resources-loader'
Use absolute paths with path.resolve(__dirname, ...) to avoid confusion.
Use 'prepend' (default) unless you intentionally want to override existing variables.
If you passed glob options as second argument of patterns, move them to options.globOptions.
Upgrade Node.js to version 8.9 or higher.
npm install style-resources-loader --save-dev
Ensure the loader is installed and your webpack resolve.modules includes node_modules.
Provide at least one pattern in options.patterns as a string or array of strings.
Update the test regex to match your file types (e.g., test: /\.(scss|sass)$/).