Gathering detailed insights and metrics for sass-resources-loader
Gathering detailed insights and metrics for sass-resources-loader
Gathering detailed insights and metrics for sass-resources-loader
Gathering detailed insights and metrics for sass-resources-loader
style-resources-loader
CSS processor resources loader for webpack
craco-sass-resources-loader
A craco plugin to use sass-resources-loader with create-react-app
nuxt-sass-resources-loader
SASS resources (e.g. variables, mixins etc.) module for NuxtJs
vue-cli-plugin-sass-resources-loader
Vue CLi 3.x plugin for sass-resources-loader
SASS resources (e.g. variables, mixins etc.) loader for Webpack. Also works with less, post-css, etc.
npm install sass-resources-loader
Typescript
Module System
Node Version
NPM Version
97.5
Supply Chain
99
Quality
80.4
Maintenance
100
Vulnerability
98.6
License
JavaScript (90.37%)
SCSS (7.22%)
Shell (1.18%)
HTML (1.11%)
CSS (0.12%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
979 Stars
173 Commits
64 Forks
22 Watchers
5 Branches
75 Contributors
Updated on Mar 30, 2025
Minified
Minified + Gzipped
Latest Version
2.2.5
Package Id
sass-resources-loader@2.2.5
Unpacked Size
28.95 kB
Size
8.65 kB
File Count
12
NPM Version
8.3.1
Node Version
16.14.0
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
This loader will load your SASS resources into every required
SASS module. So you can use your shared variables, mixins and functions across all SASS styles without manually loading them in each file.
@use
syntax. You must use Dart Sass (sass
, not node-sass
npm package). See the hoistUseStatements
option.This project is maintained by the software consulting firm ShakaCode. We focus on Ruby on Rails applications with React front-ends, often using TypeScript or ReasonML. We also build Gatsby sites. See our recent work for examples of what we do. Feel free to contact Justin Gordon, justin@shakacode.com, for more information.
Slack Room: Click for a Slack invite.
Get it via npm:
1npm install sass-resources-loader
Create your file (or files) with resources, which are snippets of Sass that you want available to places like CSS modules Sass:
1/* resources.scss */ 2 3$section-width: 700px; 4 5@mixin section-mixin { 6 margin: 0 auto; 7 width: $section-width; 8}
Name | Type | Default | Description |
---|---|---|---|
resources | {String|String[]} | undefined | Resources to include in files |
hoistUseStatements | {Boolean} | false | If true, entry file @use imports will be hoisted. This means the @use statements will go above the inclusion of resources. |
resources
Specify resources, contents of these will be prepended to each file.
If file example/a.scss
has content of $my-variable: #fff
, we could do this
1{ 2 loader: 'sass-resources-loader', 3 options: { 4 resources: 'example/a.scss' 5 } 6}
This would output the following:
1// Entry file 2 3$my-variable: #fff; 4 5// Entry file's contents go here
hoistUseStatements
Tells the compiler if an existing @use
statement is found in entry file, it should be hoisted to the top.
The reason is that @use
must go before most other declarations, except variable declarations, per the docs.
If our entry file has the following content
1// Entry file 2@use 'my/definitions/file'; 3@use 'my/other/definitions/file'; 4 5// Entry file's contents go here
and our resource file contains this
1$my-variable: #fff; 2 3@mixin some-mixin { 4 color: #000; 5}
Then the output, with hoistUseStatements set to true would be the following.
Note that the @use
statements are above the inclusion of resources.
1// Entry file 2@use 'my/definitions/file'; 3@use 'my/other/definitions/file'; 4 5// Resources 6$my-variable: #fff; 7 8@mixin some-mixin { 9 color: #000; 10} 11 12// Rest of entry file's content goes here
You can also use this multi-line syntax:
1@use 'config' with ( 2 $text-color: #FAFAFA 3);
See ./test/scss/hoist-multiline.scss for an example.
As mentioned in the docs for Sass @use, you don't need to hoist if your "resources" only contains variable definitions.
If you get the error:
SassError: @use rules must be written before any other rules.
then you need to use the hoistUseStatements: true
option.
sassResources
array in webpack config instead. If you concerned about location of your resources index, you might want to check out the solution outlined in this comment.~
(~
is resolved to node_modules
folder).Apply loader in webpack config (v1.x.x
& v2.x.x
are supported) and provide path to the file with resources:
1/* Webpack@2: webpack.config.js */ 2 3module: { 4 rules: [ 5 // Apply loader 6 { 7 test: /\.scss$/, 8 use: [ 9 'style-loader', 10 'css-loader', 11 'postcss-loader', 12 'sass-loader', 13 { 14 loader: 'sass-resources-loader', 15 options: { 16 // Provide path to the file with resources 17 resources: './path/to/resources.scss', 18 19 // Or array of paths 20 resources: [ 21 './path/to/vars.scss', 22 './path/to/mixins.scss', 23 './path/to/functions.scss' 24 ] 25 }, 26 }, 27 ], 28 }, 29 ], 30}, 31 32/* Webpack@1: webpack.config.js */ 33 34module: { 35 loaders: [ 36 // Apply loader 37 { test: /\.scss$/, loader: 'style!css!sass!sass-resources' }, 38 ], 39}, 40 41// Provide path to the file with resources 42sassResources: './path/to/resources.scss', 43 44// Or array of paths 45sassResources: ['./path/to/vars.scss', './path/to/mixins.scss'],
NOTE: If
webpackConfig.context
is not defined,process.cwd()
will be used to resolve files with resource.
Now you can use these resources without manually loading them:
1/* component.scss */ 2 3.section { 4 @include section-mixin; // <--- `section-mixin` is defined here 5}
1import React from 'react'; 2import css from './component.scss'; 3 4// ... 5 6render() { 7 return ( 8 <div className={css.section} /> 9 ); 10}
You can specify glob patterns to match your all of your files in the same directory.
1// Specify a single path 2resources: './path/to/resources/**/*.scss', // will match all files in folder and subdirectories 3// or an array of paths 4resources: [ './path/to/resources/**/*.scss', './path/to/another/**/*.scss' ]
Note that sass-resources-loader
will resolve your files in order. If you want your variables to be accessed across all of your mixins you should specify them in first place.
1resources: [ './path/to/variables/vars.scss', './path/to/mixins/**/*.scss' ]
module: {
rules: [
{
test: /\.vue$/,
use: 'vue-loader'
},
{
test: /\.css$/,
use: [
{ loader: 'vue-style-loader' },
{ loader: 'css-loader', options: { sourceMap: true } },
]
},
{
test: /\.scss$/,
use: [
{ loader: 'vue-style-loader' },
{ loader: 'css-loader', options: { sourceMap: true } },
{ loader: 'sass-loader', options: { sourceMap: true } },
{ loader: 'sass-resources-loader',
options: {
sourceMap: true,
resources: [
resolveFromRootDir('src/styles/variables.scss'),
]
}
}
]
}
]
}
If you wish to use this loader in the VueJS Webpack template you need to add the following code in build/utils.js
after line 42 :
1if (loader === 'sass') { 2 loaders.push({ 3 loader: 'sass-resources-loader', 4 options: { 5 resources: 'path/to/your/file.scss', 6 }, 7 }); 8}
If you are using vue-cli@3, you need create a vue.config.js
file in your project root(next to package.json). Then, add the following code :
1// vue.config.js 2module.exports = { 3 chainWebpack: config => { 4 const oneOfsMap = config.module.rule('scss').oneOfs.store 5 oneOfsMap.forEach(item => { 6 item 7 .use('sass-resources-loader') 8 .loader('sass-resources-loader') 9 .options({ 10 // Provide path to the file with resources 11 resources: './path/to/resources.scss', 12 13 // Or array of paths 14 resources: ['./path/to/vars.scss', './path/to/mixins.scss', './path/to/functions.scss'] 15 }) 16 .end() 17 }) 18 } 19}
This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the code of conduct.
See Contributing to get started.
sass-resources-loader is available under MIT. See LICENSE for more details.
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
Found 23/30 approved changesets -- score normalized to 7
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
security policy file not detected
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
59 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-05-26
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More