All Projects → shepherdwind → Css Hot Loader

shepherdwind / Css Hot Loader

Licence: mit
This is a css hot loader, which support hot module replacement for an extracted css file.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Css Hot Loader

mjml-loader
MJML loader for webpack
Stars: ✭ 27 (-91.48%)
Mutual labels:  webpack-loader
stylos
Webpack plugin to automatically generate and inject CSS utilities to your application
Stars: ✭ 60 (-81.07%)
Mutual labels:  webpack-loader
Ts Loader
TypeScript loader for webpack
Stars: ✭ 3,112 (+881.7%)
Mutual labels:  webpack-loader
yaml-frontmatter-loader
[DEPRECATED] Yaml frontmatter loader
Stars: ✭ 12 (-96.21%)
Mutual labels:  webpack-loader
Webpack-4-boilerplate
🚀 Webpack 4 with ES6+ and SASS,LESS/STYLUS support + dev-server and livereload
Stars: ✭ 55 (-82.65%)
Mutual labels:  webpack-loader
typed-css-modules-loader
💠 Webpack loader for typed-css-modules auto-creation
Stars: ✭ 62 (-80.44%)
Mutual labels:  webpack-loader
React-bookstore
Bookstore using google-book Apis made with reactjs🔥🚀
Stars: ✭ 14 (-95.58%)
Mutual labels:  webpack-loader
Extract Loader
webpack loader to extract HTML and CSS from the bundle
Stars: ✭ 297 (-6.31%)
Mutual labels:  webpack-loader
scalajs-webpack-loader
Webpack loader for Scala.js
Stars: ✭ 24 (-92.43%)
Mutual labels:  webpack-loader
Istanbul Instrumenter Loader
Istanbul Instrumenter Loader
Stars: ✭ 272 (-14.2%)
Mutual labels:  webpack-loader
slim-lang-loader
Webpack loader: slim => html => javascript
Stars: ✭ 20 (-93.69%)
Mutual labels:  webpack-loader
ts-interface-loader
Webpack support for validating TypeScript definitions at runtime.
Stars: ✭ 19 (-94.01%)
Mutual labels:  webpack-loader
sass-to-string
webpack loader that transform your SCSS file in a javascript string
Stars: ✭ 17 (-94.64%)
Mutual labels:  webpack-loader
standard-loader
webpack loader for linting your code with https://github.com/feross/standard
Stars: ✭ 66 (-79.18%)
Mutual labels:  webpack-loader
Graphql Let
A layer to start/scale the use of GraphQL code generator.
Stars: ✭ 282 (-11.04%)
Mutual labels:  webpack-loader
vue-template-compiler-loader
Webpack loader to pre-compile Vue 2.0 templates
Stars: ✭ 26 (-91.8%)
Mutual labels:  webpack-loader
web-components-loader
Webpack loader that makes it incredibly easy to import HTML-centric Web Components into your project.
Stars: ✭ 34 (-89.27%)
Mutual labels:  webpack-loader
Speedy.js
Accelerate JavaScript Applications by Compiling to WebAssembly
Stars: ✭ 300 (-5.36%)
Mutual labels:  webpack-loader
Source Map Loader
extract sourceMappingURL comments from modules and offer it to webpack
Stars: ✭ 294 (-7.26%)
Mutual labels:  webpack-loader
React Proxy Loader
Wraps a react component in a proxy component to enable Code Splitting.
Stars: ✭ 258 (-18.61%)
Mutual labels:  webpack-loader

CSS Hot Loader

build status Test coverage NPM version npm download

This is a css hot loader, which support hot module replacement for an extracted css file.

No more maintenance for this repo

Now the mini-css-extract-plugin now support css hot reload (since 0.6.x) , so that this plugin is no longer needed.

Why we need css hot loader

In most cases, we can realize css hot reload by style-loader . But style-loader need inject style tag into document, Before js ready, the web page will have no any style. That is not good experience.

Also, a lots of people thought about that, How can realize hot reload with extract-text-webpack-plugin. For example #30 , #!89.

So I wrote this loader, which supports hot module replacement for an extracted css file.

Install

First install package from npm

$ npm install css-hot-loader --save-dev

Then config webpack.config.js

module: {
  rules: [
    {
      test: /\.css/,
      use: [
        'css-hot-loader',
        MiniCssExtractPlugin.loader,
        'css-loader',
      ],
    },
  ] // end rules
},

There is an issue to work with webpack4 #37. Please use mini-css-extract-plugin to replace extract-text-webpack-plugin.

Attention

This plugin require the output css file name static. If output file name depend on css content, for example 'bundle.[name].[contenthash].css', HMR reload will fail, more detail refer to #21.

webpack 1.x

Config file example should like this

  module: {
    loaders: [{
      test: /\.less$/,
      loaders: [
        'css-hot-loader',
        'extract-text-webpack-plugin',
        'less',
        ...
       ],
      include: path.join(__dirname, 'src')
    }]
  }

See more examples code from https://github.com/shepherdwind/css-hot-loader/tree/v1.4.3/examples

options

fileMap

Option to define you css file reload rule. Since 1.1.0 .

For example 'css-hot-loader?fileMap='../css/{fileName}' , which mean

js/foo.js => css/foo.css

Default value is {fileName}.

see #3.

reloadAll

Force reload all css file.

cssModule

When this option is opened, every time you modify the css file, the js file will reload too. Default closed, this option use with css module.

see !47 and !51

How

The realization principle of this loader is very simple. There are some assumed condition:

  1. css required by js , so css also be a js file
  2. The name of css file, which need hot reload , is the same as js file excuted.

The secend assumption is often established. If you use extract-text-webpack-plugin , entry foo.js will extract css file foo.css. This principle will help us to locate the url of css file extracted.

Because every css file will be a js module , every css file change can affect a module change. CSS hot loader will accept this kind change, then find extracted css file by document.currentScript.

So when a css file changed, We just need find which css file link element, and reload css file.

License

(The MIT License)

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