webpack-hot-middleware
Advanced tools
Comparing version 2.3.0 to 2.4.0
@@ -24,3 +24,2 @@ /*eslint-env browser*/ | ||
lines.forEach(function(msg) { | ||
console.warn("[HMR] " + msg); | ||
var pre = document.createElement('pre'); | ||
@@ -27,0 +26,0 @@ pre.textContent = msg; |
@@ -8,24 +8,23 @@ /*eslint-env browser*/ | ||
overlay: true, | ||
reload: false | ||
reload: false, | ||
log: true, | ||
warn: true | ||
}; | ||
if (__resourceQuery) { | ||
var pathMatch = /path=(.*?)(\&|$)/.exec(__resourceQuery); | ||
if (pathMatch) { | ||
options.path = pathMatch[1]; | ||
var querystring = require('querystring'); | ||
var overrides = querystring.parse(__resourceQuery); | ||
if (overrides.path) options.path = overrides.path; | ||
if (overrides.timeout) options.timeout = overrides.timeout; | ||
if (overrides.overlay) options.overlay = overrides.overlay !== 'false'; | ||
if (overrides.reload) options.reload = overrides.reload !== 'false'; | ||
if (overrides.noInfo && overrides.noInfo !== 'false') { | ||
options.log = false; | ||
} | ||
var timeoutMatch = /timeout=(.*?)(\&|$)/.exec(__resourceQuery); | ||
if (timeoutMatch) { | ||
options.timeout = parseFloat(timeoutMatch[1]); | ||
if (overrides.quiet && overrides.quiet !== 'false') { | ||
options.log = false; | ||
options.warn = false; | ||
} | ||
var overlayMatch = /overlay=(.*?)(\&|$)/.exec(__resourceQuery); | ||
if (overlayMatch) { | ||
options.overlay = overlayMatch[1] !== 'false'; | ||
} | ||
var reloadMatch = /reload=(.*?)(\&|$)/.exec(__resourceQuery); | ||
if (reloadMatch) { | ||
options.reload = reloadMatch[1] !== 'false'; | ||
} | ||
} | ||
if (typeof window.EventSource !== 'function') { | ||
if (typeof window.EventSource === 'undefined') { | ||
console.warn( | ||
@@ -55,3 +54,3 @@ "webpack-hot-middleware's client requires EventSource to work. " + | ||
function handleOnline() { | ||
console.log("[HMR] connected"); | ||
if (options.log) console.log("[HMR] connected"); | ||
lastActivity = new Date(); | ||
@@ -68,3 +67,5 @@ } | ||
} catch (ex) { | ||
console.warn("Invalid HMR message: " + event.data + "\n" + ex); | ||
if (options.warn) { | ||
console.warn("Invalid HMR message: " + event.data + "\n" + ex); | ||
} | ||
} | ||
@@ -89,7 +90,7 @@ } | ||
function problems(type, obj) { | ||
console.warn("[HMR] bundle has " + type + ":"); | ||
if (options.warn) console.warn("[HMR] bundle has " + type + ":"); | ||
var list = []; | ||
obj[type].forEach(function(msg) { | ||
var clean = strip(msg); | ||
console.warn("[HMR] " + clean); | ||
if (options.warn) console.warn("[HMR] " + clean); | ||
list.push(clean); | ||
@@ -109,5 +110,5 @@ }); | ||
if (obj.action == "building") { | ||
console.log("[HMR] bundle rebuilding"); | ||
if (options.log) console.log("[HMR] bundle rebuilding"); | ||
} else if (obj.action == "built") { | ||
console.log("[HMR] bundle rebuilt in " + obj.time + "ms"); | ||
if (options.log) console.log("[HMR] bundle rebuilt in " + obj.time + "ms"); | ||
if (obj.errors.length > 0) { | ||
@@ -122,3 +123,3 @@ problems('errors', obj); | ||
processUpdate(obj.hash, obj.modules, options.reload); | ||
processUpdate(obj.hash, obj.modules, options); | ||
} | ||
@@ -125,0 +126,0 @@ } else if (customHandler) { |
{ | ||
"name": "webpack-hot-middleware", | ||
"version": "2.3.0", | ||
"version": "2.4.0", | ||
"description": "Webpack hot reloading you can attach to your own server", | ||
@@ -17,2 +17,3 @@ "main": "middleware.js", | ||
"dependencies": { | ||
"querystring": "^0.2.0", | ||
"strip-ansi": "^2.0.1" | ||
@@ -19,0 +20,0 @@ }, |
@@ -22,5 +22,6 @@ /** | ||
module.exports = function(hash, moduleMap, reload) { | ||
module.exports = function(hash, moduleMap, options) { | ||
var reload = options.reload; | ||
if (!upToDate(hash) && module.hot.status() == "idle") { | ||
console.log("[HMR] Checking for updates on the server..."); | ||
if (options.log) console.log("[HMR] Checking for updates on the server..."); | ||
check(); | ||
@@ -34,4 +35,6 @@ } | ||
if(!updatedModules) { | ||
console.warn("[HMR] Cannot find update (Full reload needed)"); | ||
console.warn("[HMR] (Probably because of restarting the server)"); | ||
if (options.warn) { | ||
console.warn("[HMR] Cannot find update (Full reload needed)"); | ||
console.warn("[HMR] (Probably because of restarting the server)"); | ||
} | ||
performReload(); | ||
@@ -57,9 +60,11 @@ return null; | ||
if(unacceptedModules.length > 0) { | ||
console.warn( | ||
"[HMR] The following modules couldn't be hot updated: " + | ||
"(Full reload needed)" | ||
); | ||
unacceptedModules.forEach(function(moduleId) { | ||
console.warn("[HMR] - " + moduleMap[moduleId]); | ||
}); | ||
if (options.warn) { | ||
console.warn( | ||
"[HMR] The following modules couldn't be hot updated: " + | ||
"(Full reload needed)" | ||
); | ||
unacceptedModules.forEach(function(moduleId) { | ||
console.warn("[HMR] - " + moduleMap[moduleId]); | ||
}); | ||
} | ||
performReload(); | ||
@@ -69,13 +74,15 @@ return; | ||
if(!renewedModules || renewedModules.length === 0) { | ||
console.log("[HMR] Nothing hot updated."); | ||
} else { | ||
console.log("[HMR] Updated modules:"); | ||
renewedModules.forEach(function(moduleId) { | ||
console.log("[HMR] - " + moduleMap[moduleId]); | ||
}); | ||
} | ||
if (options.log) { | ||
if(!renewedModules || renewedModules.length === 0) { | ||
console.log("[HMR] Nothing hot updated."); | ||
} else { | ||
console.log("[HMR] Updated modules:"); | ||
renewedModules.forEach(function(moduleId) { | ||
console.log("[HMR] - " + moduleMap[moduleId]); | ||
}); | ||
} | ||
if (upToDate()) { | ||
console.log("[HMR] App is up to date."); | ||
if (upToDate()) { | ||
console.log("[HMR] App is up to date."); | ||
} | ||
} | ||
@@ -86,14 +93,18 @@ } | ||
if (module.hot.status() in failureStatuses) { | ||
console.warn("[HMR] Cannot check for update (Full reload needed)"); | ||
console.warn("[HMR] " + err.stack || err.message); | ||
if (options.warn) { | ||
console.warn("[HMR] Cannot check for update (Full reload needed)"); | ||
console.warn("[HMR] " + err.stack || err.message); | ||
} | ||
performReload(); | ||
return; | ||
} | ||
console.warn("[HMR] Update check failed: " + err.stack || err.message); | ||
if (options.warn) { | ||
console.warn("[HMR] Update check failed: " + err.stack || err.message); | ||
} | ||
} | ||
function performReload() { | ||
console.warn("[HMR] Reloading page"); | ||
if (options.warn) console.warn("[HMR] Reloading page"); | ||
if (reload) window.location.reload(); | ||
} | ||
}; |
@@ -80,2 +80,4 @@ # Webpack Hot Middleware | ||
* **reload** - Set to `true` to auto-reload the page when webpack gets stuck. | ||
* **noInfo** - Set to `true` to disable informational console logging. | ||
* **reload** - Set to `true` to disable all console logging. | ||
@@ -82,0 +84,0 @@ ## How it Works |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
29619
653
110
2
+ Addedquerystring@^0.2.0
+ Addedquerystring@0.2.1(transitive)