Coder Social home page Coder Social logo

fast-css-loader's Introduction

fast-css-loader

Blazingly fast css loader for webpack (about 10 times faster than css-loader when process large css files)

install

npm install fast-css-loader --save-dev

VS css-loader

fast-css-loader has higher performance when processing large css files, here is an example when process a 24200+ lines css file:

-------------------------------------
       CSS_LOADER COST: 1644 ms
  FAST_CSS_LOADER COST: 116 ms
-------------------------------------

image

Why faster?

fast-css-loader rewrites resolving parts of @import and url(...) with RegExp and some tricks, it's extramely faster than postcss used by css-loader.

Limitations

Compare with css-loader, fast-css-loader has these limitations:

  • doesn't support sourceMap
  • doesn't support minimize (you can minimize css with mini-css-extract-plugin)
  • doesn't support camelCase option
  • doesn't support css module

If you really need these features, just use original css-loader :)

Usage

just like css-loader:

module.exports = {
  module: {
    rules: [
      {
        test: /\.(svg|bmp|gif|png|jpe?g)$/,
        loader: require.resolve('file-loader'),
        options: {
          name: '[name].[hash:8].[ext]'
        }
      },
      {
        test: /\.css$/,
        use: [
          'style-loader',
          'fast-css-loader'   // replace you css-loader with fast-css-loader
        ]
      },
    ]
  }
}

Options

Name Type Default Description
root {String} / Path to resolve URLs, URLs starting with / will not be translated
url {Boolean} true Enable/Disable url() handling
alias {Object} {} Create aliases to import certain modules more easily
import {Boolean} true Enable/Disable @import handling
importLoaders {Number} 0 Number of loaders applied before CSS loader

The above listed options are consistent with css-loader, for more detail please refer to css-loader options

License

MIT

fast-css-loader's People

Contributors

yibn2008 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

fast-css-loader's Issues

Url alias is not being resolved properly

Looks like the loader is not being able to resolve url with alias. It's trying to load a module with a duplicated url.

Instead of ../../../sprites/leagues/~sprites/leagues/[email protected]
Should be ../../../sprites/leagues/[email protected]

Resolved Alias
../../../sprites/leagues/ ~sprites/leagues/
ERROR in ./src/ui/base-styles/themes/xxx/index.scss
Module not found: Error: Can't resolve '../../../sprites/leagues/~sprites/leagues/[email protected]' in 

Btw, It's working fine with css-loader

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.