Security News
How Threat Actors are Abusing GitHub’s File Upload Feature to Host Malware
GitHub is susceptible to a CDN flaw that allows attackers to host malware on any public repository.
css-hot-loader
Advanced tools
Readme
This is a css hot loader, which support hot module replacement for an extracted css file.
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.
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.
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.
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
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.
Force reload all css file.
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.
The realization principle of this loader is very simple. There are some assumed condition:
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.
(The MIT License)
FAQs
css hot reload work with extract-text-webpack-plugin
The npm package css-hot-loader receives a total of 23,929 weekly downloads. As such, css-hot-loader popularity was classified as popular.
We found that css-hot-loader demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
GitHub is susceptible to a CDN flaw that allows attackers to host malware on any public repository.
Security News
At Node Congress, Socket CEO Feross Aboukhadijeh uncovers the darker aspects of open source, where applications that rely heavily on third-party dependencies can be exploited in supply chain attacks.
Research
Security News
The Socket Research team found this npm package includes code for collecting sensitive developer information, including your operating system username, Git username, and Git email.