A Webpack loader that automatically injects shared SASS/SCSS resources (variables, mixins, functions) into every imported SASS file, eliminating manual @import statements. Currently at version 2.2.5, it supports Webpack 4 and 5, and works with both node-sass and Dart sass. It also supports Sass @use syntax via the hoistUseStatements option when using Dart Sass. Unlike manual imports or other loaders like sass-loader's prependData, this loader specifically targets CSS Modules workflows and can hoist @use statements to comply with Sass module system rules.
npm install sass-resources-loaderVerified import paths — ran on the pinned version, not inferred.
Webpack configuration that injects variables.scss and mixins.scss into every SCSS file.
Use path.resolve(__dirname, 'src/resources.scss') or an absolute path.
Switch to the 'sass' package (Dart Sass) and set hoistUseStatements: true if using @use.
Configure rules: use: ['style-loader', 'css-loader', 'sass-loader', { loader: 'sass-resources-loader', options: {...} }].Use unique naming conventions for resources (e.g., prefix with project name).
Update webpack config: resources: ['file1.scss'] instead of resources: 'file1.scss' (though both still work).
Use absolute path: path.resolve(__dirname, 'resources.scss')
Check options: use exactly 'resources' (array or string) and 'hoistUseStatements' (boolean). Example: { loader: 'sass-resources-loader', options: { resources: [...] } }Set hoistUseStatements: true in loader options to hoist existing @use statements above resources.
Run npm install sass-resources-loader --save-dev