Installations
npm install fast-sass-loader
Releases
Unable to fetch releases
Developer
yibn2008
Developer Guide
Module System
CommonJS
Min. Node Version
Typescript Support
No
Node Version
12.20.1
NPM Version
8.1.3
Statistics
250 Stars
131 Commits
38 Forks
10 Watching
1 Branches
10 Contributors
Updated on 07 Jul 2024
Bundle Size
140.98 kB
Minified
43.24 kB
Minified + Gzipped
Languages
SCSS (96.7%)
JavaScript (3.3%)
Total Downloads
Cumulative downloads
Total Downloads
13,143,549
Last day
11.4%
7,189
Compared to previous day
Last week
2%
32,863
Compared to previous week
Last month
42%
134,271
Compared to previous month
Last year
-61.6%
1,380,597
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
fast-sass-loader
Blazingly fast sass loader for webpack.
Tips: using with fast-css-loader you will get more than 10 times css build performance
Features:
- 5~10 times faster than
sass-loader
in large sass project - support sass file dedupe, never worry about
@import
same file in different place - support url resolve, never worry about the problem with
url(...)
(see https://github.com/webpack-contrib/sass-loader#problems-with-url)
fast sass loader for webpack. 5~10 times faster than sass-loader, and support url resolve.
version 2.x notes
Since libsass has been deprecated, fast-sass-loader will use sass instead of node-sass, you can use options.implement
to specify any compatible sass compiler.
vs sass-loader
Features | fast-sass-loader | sass-loader |
---|---|---|
Performance | Fast (5~10 times) | Slow |
Sass Dedupe | ✓ | × |
Url Resolve | ✓ | × (need resolve-url-loader, it's buggy) |
Loader Config | × | ✓ |
Source Map | × | ✓ |
Internal Cache | ✓ | × |
Performance
performance benchmark (run npm run perf
):
Since the sass-loader
doesn't dedupe repeated sass files, the result will be very very large (6.95MB!!!), and the total compile time takes 64.9 seconds (nearly 6 times longer than fast-sass-loader
).
Why fast-sass-loader
is faster than sass-loader
?
- Support sass file dedupe, so
node-sass
won't compile same file repeatedly, the performance improvement is s ignificant when your sass files number grows very large. - Before node-sass compile,
fast-sass-loader
will merge all sass files into a single file, so node-sass only need to compile one large file, it's faster than@importer
of libsass. - The internal cache will store all result for every entry, only compile sass when related file changed.
Install
install by npm:
1npm install fast-sass-loader --save-dev
and you need install node-sass and webpack as peer dependencies.
Configuration
webpack 2, 3 and 4:
{
module: {
rules: [
{
test: /\.(scss|sass)$/,
use: [
'css-loader',
{
loader: 'fast-sass-loader',
options: {
includePaths: [ ... ]
}
}
]
},
// other loaders ...
]
}
}
webpack 1:
{
module: {
loaders: [
{
test: /\.(scss|sass)$/,
loader: 'css!fast-sass'
},
// other loaders ...
]
}
}
Options
implementation
since version 2.x, fast-sass-loader use dart-sass (npm sass
) instead of original node-sass, if you want use node-sass please use this options to modify.
1{ 2 loader: 'fast-sass-loader', 3 options: { 4 implementation: require('node-sass') 5 } 6}
includePaths:
An array of paths that node-sass can look in to attempt to resolve your @import declarations. When using data, it is recommended that you use this.
data:
If you want to prepend Sass code before the actual entry file, you can set the data option. In this case, the loader will not override the data option but just append the entry's content. This is especially useful when some of your Sass variables depend on the environment:
1{ 2 loader: "fast-sass-loader", 3 options: { 4 data: "$env: " + process.env.NODE_ENV + ";" 5 } 6}
Please note: Since you're injecting code, this will break the source mappings in your entry file. Often there's a simpler solution than this.
transformers:
If you want to import files that aren't basic Sass or css files, you can use the transformers option. This option takes an array of transformer entries, each with a list of file extensions and a tranform function. If an imported file's extension matches one of the transformers' extensions, the file contents will be passed to the corresponding transform function. Your transform function should return a sass string that will be directly written into your compiled Sass file. This is especially useful if you use .json files to share your basic styles across platforms and you'd like to import your .json files directly into your Sass.
1{ 2 loader: "fast-sass-loader", 3 options: { 4 transformers: [ 5 { 6 extensions: [".json"], 7 transform: function(rawFile) { 8 return jsonToSass(rawFile); 9 } 10 } 11 ] 12 } 13}
outputStyle:
The outputStyle option is passed to the render method of node-sass. See node-sass OutputStyle. This can be used to create smaller css files if set to "compressed".
resolveURLs:
By default fast-sass-loader
resolves and rewrites paths inside url()
. This behavior can be turned off with resolveURLs: false
option so all URLs will remain intact.
Warning
Mixing import .scss
and.sass
file is not allowed
Since fast-sass-loader
will parse @import
and merge all files into single sass file, you cannot import .scss
file from .sass
(or opposite).
For example:
1// file: entry.scss 2@import "path/to/file.sass"; // cannot import `path/to/file.sass` in a `.scss` file 3 4body { 5 background: #FFF; 6}
Avoid same variable name in different sass files
Since fast-sass-loader
will dedupe sass file, later imported file will be ignored. Using same variable name in different sass fill would produce unexpected output.
For example (compile entry.scss
with fast-sass-loader):
1// a.scss 2$foobar: #000;
1// b.scss 2@import "a.scss"; 3$foobar: #AAA; 4 5h1 { color: $foobar; }
1// entry.scss 2@import "b.scss"; 3@import "a.scss"; // this file will be ignore: $foobar === #AAA 4 5h2 { color: $foobar; } 6 7// will output: 8// h1 { color: #AAA; } 9// h2 { color: #AAA; }
You can use variable prefix to bypass.
Avoid nested @import in sass rules
fast-sass-loader doesn't support @import
statement in sass rules, for example:
1.a { 2 @import 'group' 3} 4 5.b { 6 @import 'group' 7}
you should wrap the rules that you want to import with mixin, then include them in your .a { ... }
or .b { ... }
License
MIT
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
Found 3/13 approved changesets -- score normalized to 2
Reason
dependency not pinned by hash detected -- score normalized to 2
Details
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/node.js.yml:23: update your workflow using https://app.stepsecurity.io/secureworkflow/yibn2008/fast-sass-loader/node.js.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/node.js.yml:25: update your workflow using https://app.stepsecurity.io/secureworkflow/yibn2008/fast-sass-loader/node.js.yml/master?enable=pin
- Warn: npmCommand not pinned by hash: .github/workflows/node.js.yml:30
- Info: 0 out of 2 GitHub-owned GitHubAction dependencies pinned
- Info: 1 out of 2 npmCommand dependencies pinned
Reason
detected GitHub workflow tokens with excessive permissions
Details
- Warn: no topLevel permission defined: .github/workflows/node.js.yml:1
- Info: no jobLevel write permissions found
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
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
license file not detected
Details
- Warn: project does not have a license file
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 20 are checked with a SAST tool
Score
3.4
/10
Last Scanned on 2024-11-18
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