Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

css-hot-loader

Package Overview
Dependencies
Maintainers
1
Versions
33
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

css-hot-loader - npm Package Compare versions

Comparing version 1.0.4 to 1.1.0-beta

64

hotModuleReplacement.js

@@ -11,25 +11,45 @@ var getCurrentScriptUrl = function() {

}
return function() {
return src.replace('.js', '.css');
return function(fileMap) {
var splitResult = src.exec(/([^\\/])+\.js$/);
var filename = splitResult && splitResult[1];
if (!filename) {
return [src.replace('.js', '.css')];
}
return fileMap.split(',').map(function(mapRule) {
var reg = new RegExp(fileName + '\\.js$', 'g')
return src.replace(reg, mapRule.replace(/{fileName}/g, filename) + '.css');
});
};
}
var getScriptSrc = getCurrentScriptUrl();
var getScriptSrc = getCurrentScriptUrl(fileMap);
function getLinkElement() {
var element;
var src = getScriptSrc();
function reloadStyle(src) {
var elements = document.querySelectorAll('link');
var loaded = false;
for (var i = 0, el = null; el = elements[i]; i++) {
if (el.href.indexOf(src) > -1) {
element = el;
var getReloadUrl(el.href, src);
if (url) {
el.href = url + '?' + Date.now();
loaded = true;
}
}
return element;
return loaded;
}
function getReloadUrl(href, src) {
var ret;
src.some(function(url) {
if (href.indexOf(src) > -1) {
ret = url;
}
});
return ret;
}
function reloadAll() {
var elements = document.querySelectorAll('link');
for (var i = 0, el = null; el = elements[i]; i++) {
const src = el.href.split('?')[0];
var src = el.href.split('?')[0];
el.href = src + '?' + Date.now();

@@ -39,15 +59,17 @@ }

module.exports = function() {
if (typeof document === 'undefined') {
return;
}
module.exports = function(options) {
return function() {
if (typeof document === 'undefined') {
return;
}
var src = getScriptSrc();
var el = getLinkElement();
if (el) {
el.href = src + '?' + Date.now();
console.log('[HMR] css reload %s', src);
} else {
reloadAll();
var src = getScriptSrc(options.fileMap);
var reloaded = reloadStyle(src);
if (reloaded) {
console.log('[HMR] css reload %s', src);
} else {
console.log('[HMR] css reload all css');
reloadAll();
}
}
};

@@ -0,7 +1,17 @@

const loaderUtils = require('loader-utils');
const defaultOptions = {
fileMap: '{fileName}',
};
module.exports = function(content) {
this.cacheable();
const options = Object.assign(
{},
loaderUtils.getOptions(this), // it is safe to pass null to Object.assign()
defaultOptions
);
return content + `
if(module.hot) {
// ${Date.now()}
const cssReload = require('${require.resolve('./hotModuleReplacement')}');
const cssReload = require('${require.resolve('./hotModuleReplacement')}')(options);
module.hot.dispose(cssReload);

@@ -8,0 +18,0 @@ module.hot.accept(undefined, cssReload);

{
"name": "css-hot-loader",
"version": "1.0.4",
"version": "1.1.0-beta",
"description": "css hot reload work with extract-text-webpack-plugin",

@@ -16,3 +16,6 @@ "main": "index.js",

"author": "shepherdwind",
"license": "ISC"
"license": "ISC",
"dependencies": {
"loader-utils": "^1.1.0"
}
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc