Gathering detailed insights and metrics for style-resources-loader
Gathering detailed insights and metrics for style-resources-loader
Gathering detailed insights and metrics for style-resources-loader
Gathering detailed insights and metrics for style-resources-loader
npm install style-resources-loader
Typescript
Module System
Min. Node Version
Node Version
NPM Version
87.8
Supply Chain
68.5
Quality
73.1
Maintenance
100
Vulnerability
98.2
License
TypeScript (67.48%)
CSS (7.12%)
SCSS (6.81%)
Less (6.75%)
Sass (5.84%)
Stylus (5.09%)
JavaScript (0.91%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
261 Stars
104 Commits
10 Forks
3 Watchers
15 Branches
2 Contributors
Updated on May 22, 2025
Latest Version
1.5.0
Package Id
style-resources-loader@1.5.0
Unpacked Size
46.05 kB
Size
14.02 kB
File Count
65
NPM Version
6.14.13
Node Version
14.17.3
Published on
Dec 08, 2021
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
4
1
26
1npm i style-resources-loader -D
This loader is a CSS processor resources loader for webpack, which injects your style resources (e.g. variables, mixins
) into multiple imported css, sass, scss, less, stylus
modules.
It's mainly used to
variables, mixins, functions
across all style files, so you don't need to @import
them manually.variables
in style files provided by other libraries (e.g. ant-design) and customize your own theme.See automatic imports for more details.
Prepends variables
and mixins
to all scss
files with default resources injector.
webpack.config.js
1module.exports = { 2 // ... 3 module: { 4 rules: [{ 5 test: /\.scss$/, 6 use: ['style-loader', 'css-loader', 'sass-loader', { 7 loader: 'style-resources-loader', 8 options: { 9 patterns: [ 10 './path/from/context/to/scss/variables/*.scss', 11 './path/from/context/to/scss/mixins/*.scss', 12 ] 13 } 14 }] 15 }] 16 }, 17 // ... 18}
Appends variables
to all less
files and overrides original less variables
.
webpack.config.js
1module.exports = { 2 // ... 3 module: { 4 rules: [{ 5 test: /\.less$/, 6 use: ['style-loader', 'css-loader', 'less-loader', { 7 loader: 'style-resources-loader', 8 options: { 9 patterns: path.resolve(__dirname, 'path/to/less/variables/*.less'), 10 injector: 'append' 11 } 12 }] 13 }] 14 }, 15 // ... 16}
Prepends variables
and mixins
to all stylus
files with customized resources injector.
webpack.config.js
1module.exports = { 2 // ... 3 module: { 4 rules: [{ 5 test: /\.styl$/, 6 use: ['style-loader', 'css-loader', 'stylus-loader', { 7 loader: 'style-resources-loader', 8 options: { 9 patterns: [ 10 path.resolve(__dirname, 'path/to/stylus/variables/*.styl'), 11 path.resolve(__dirname, 'path/to/stylus/mixins/*.styl') 12 ], 13 injector: (source, resources) => { 14 const combineAll = type => resources 15 .filter(({ file }) => file.includes(type)) 16 .map(({ content }) => content) 17 .join(''); 18 19 return combineAll('variables') + combineAll('mixins') + source; 20 } 21 } 22 }] 23 }] 24 }, 25 // ... 26}
Name | Type | Default | Description |
---|---|---|---|
patterns | string | string[] | / | Path to the resources you would like to inject |
injector | Injector | 'prepend' | 'append' | 'prepend' | Controls the resources injection precisely |
globOptions | GlobOptions | {} | An options that can be passed to glob(...) |
resolveUrl | boolean | true | Enable/Disable @import url to be resolved |
See the type definition file for more details.
patterns
A string or an array of string, which represents the path to the resources you would like to inject. If the path is relative, it would relative to webpack context.
It supports globbing. You could include many files using a file mask.
For example, './styles/*/*.less'
would include all less
files from variables
and mixins
directories and ignore reset.less
in such following structure.
./src <-- webpack context
/styles
/variables
|-- fonts.less
|-- colors.less
/mixins
|-- size.less
|-- reset.less
Only supports .css
.sass
.scss
.less
.styl
as resources file extensions.
injector
An optional function which controls the resources injection precisely. It also supports 'prepend'
and 'append'
for convenience, which means the loader will prepend or append all resources to source files, respectively.
It defaults to 'prepend'
, which implements as an injector function internally.
Furthermore, an injector function should match the following type signature:
1type Injector = ( 2 this: LoaderContext, 3 source: string, 4 resources: StyleResource[], 5) => string | Promise<string>
It receives two parameters:
Name | Type | Description |
---|---|---|
source | string | Content of the source file |
resources | StyleResource[] | Resource descriptors |
It is called with this
context pointing to the loader context.
resources
An array of resource descriptor, each contains file
and content
properties:
Name | Type | Description |
---|---|---|
file | string | Absolute path to the resource |
content | string | Content of the resource file |
It can be asynchronous. You could use async / await
syntax in your own injector function or just return a promise.
globOptions
Options that can be passed to glob(...)
. See node-glob options for more details.
resolveUrl
A boolean which defaults to true
. It represents whether the relative path in @import
or @require
statements should be resolved.
If you were to use @import
or @require
statements in style resource files, you should make sure that the URL is relative to that resource file, rather than the source file.
You could disable this feature by setting resolveUrl
to false
.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
Found 2/29 approved changesets -- score normalized to 0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
43 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-06-30
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 Morevue-cli-plugin-style-resources-loader
vue-cli plugin to add style-resources-loader
craco-style-resources-loader
A craco plugin to use styles-resources-loader with create-react-app
craco-plugin-style-resources-loader
A craco plugin to use style-resources-loader with create-react-app
@ben_lau/style-resources-loader
CSS processor resources loader for webpack