All Projects → yibn2008 → Fast Sass Loader

yibn2008 / Fast Sass Loader

High performance sass loader for webpack

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Fast Sass Loader

Azure Functions Pack
Easily package your Node.js Functions for Azure Functions
Stars: ✭ 149 (-34.93%)
Mutual labels:  webpack, webpack2
Webpack Chain
A chaining API to generate and simplify the modification of Webpack configurations.
Stars: ✭ 2,821 (+1131.88%)
Mutual labels:  webpack, webpack2
Angularjs Typescript Webpack
AngularJS 1.7, typescript 3 and webpack 4 starter project based on angular tutorial
Stars: ✭ 150 (-34.5%)
Mutual labels:  webpack, webpack2
Iceberg
Front-End Boilerplate built with React + Babel + Webpack + SASS
Stars: ✭ 144 (-37.12%)
Mutual labels:  webpack, webpack2
Docker Django Webpack Skeleton
Django Skeleton W/ Docker Dev & Production W/ Webpack 2 W/ BabelJS W/ Sass W/ PostgreSQL
Stars: ✭ 191 (-16.59%)
Mutual labels:  webpack, webpack2
React Redux Styled Hot Universal
react boilerplate used best practices and focus on performance
Stars: ✭ 147 (-35.81%)
Mutual labels:  webpack, webpack2
Webpack.js.org
Repository for webpack documentation and more!
Stars: ✭ 2,049 (+794.76%)
Mutual labels:  webpack, webpack2
Everything Is A Plugin
Everything is a Plugin: Mastering webpack from the inside out. NgConf 2017
Stars: ✭ 123 (-46.29%)
Mutual labels:  webpack, webpack2
Webpack2 Lessons
📖《webpack2 包教不包会》
Stars: ✭ 187 (-18.34%)
Mutual labels:  webpack, webpack2
Html Res Webpack Plugin
plugin for generating html in webpack
Stars: ✭ 170 (-25.76%)
Mutual labels:  webpack, webpack2
Svg Sprite Loader
Webpack loader for creating SVG sprites.
Stars: ✭ 1,822 (+695.63%)
Mutual labels:  webpack, webpack2
React Cordova Boilerplate
TodoMVC example for react with development tools to build a cordova application
Stars: ✭ 206 (-10.04%)
Mutual labels:  webpack, webpack2
React Webpack Rails Tutorial
Example of integration of Rails, react, redux, using the react_on_rails gem, webpack, enabling the es7 and jsx transpilers, and node integration. And React Native! Live Demo:
Stars: ✭ 1,669 (+628.82%)
Mutual labels:  webpack, webpack2
Devopenclub Tech Webpack2
Webpack 2 视频教程课程源码
Stars: ✭ 148 (-35.37%)
Mutual labels:  webpack, webpack2
Ie Webpack Start
webpack2编译打包支持到低版本IE。坑有多少?水有多深?自行体会!
Stars: ✭ 130 (-43.23%)
Mutual labels:  webpack, webpack2
Webpack2
基于webpack2和vue.js2构建饿了么多页面应用 🌹
Stars: ✭ 165 (-27.95%)
Mutual labels:  webpack, webpack2
Webpack Typescript Starter
A simple Webpack 2 + TypeScript starter
Stars: ✭ 117 (-48.91%)
Mutual labels:  webpack, webpack2
Reactly Starter Kit
Deployable React + Webpack 2 starter kit
Stars: ✭ 122 (-46.72%)
Mutual labels:  webpack, webpack2
Multipage Webpack Plugin
A plugin that makes handling templates and asset distribution for multi-page applications using webpack trivial
Stars: ✭ 168 (-26.64%)
Mutual labels:  webpack, webpack2
String Replace Loader
Replace loader for Webpack
Stars: ✭ 205 (-10.48%)
Mutual labels:  webpack, webpack2

fast-sass-loader

Build Status Coverage Status

Blazingly fast sass loader for webpack.

Tips: using with fast-css-loader you will get more than 10 times css build performance

Features:

fast sass loader for webpack. 5~10 times faster than sass-loader, and support url resolve.

version 2.x notes

Since libsass has beed 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):

image

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 ?

  1. 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.
  2. 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.
  3. The internal cache will store all result for every entry, only compile sass when related file changed.

Install

install by npm:

npm 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.

{
  loader: 'fast-sass-loader',
  options: {
    implementation: require('node-sass')
  }
}

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:

{
    loader: "fast-sass-loader",
    options: {
        data: "$env: " + process.env.NODE_ENV + ";"
    }
}

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.

{
    loader: "fast-sass-loader",
    options: {
        transformers: [
            {
                extensions: [".json"],
                transform: function(rawFile) {
                    return jsonToSass(rawFile);
                }
            }
        ]
    }
}

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:

// file: entry.scss
@import "path/to/file.sass";  // cannot import `path/to/file.sass` in a `.scss` file

body {
  background: #FFF;
}

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):

// a.scss
$foobar: #000;
// b.scss
@import "a.scss";
$foobar: #AAA;

h1 { color: $foobar; }
// entry.scss
@import "b.scss";
@import "a.scss"; // this file will be ignore: $foobar === #AAA

h2 { color: $foobar; }

// will output:
// h1 { color: #AAA; }
// 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:

.a {
  @import 'group'
}

.b {
  @import 'group'
}

you should wrap the rules that you want to import with mixin, then include them in your .a { ... } or .b { ... }

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].