open-browser-webpack-plugin
Advanced tools
Comparing version 0.0.3 to 0.0.4
39
index.js
var open = require('open'); | ||
/** | ||
* Removes an element from the an array if exist. | ||
* @param {Array} array | ||
* @param {*} item Item to delete | ||
* @returns {*} removed item if was found. False otherwise. | ||
* Creates a function that is restricted to invoking func once. | ||
* Repeat calls to the function return the value of the first invocation. | ||
* The func is invoked with the this binding and arguments of the created function. | ||
* @param {Function} function The function to restrict. | ||
* @returns {Function} Returns the new restricted function. | ||
*/ | ||
function removeFromArray(array, item) { | ||
var index = array.indexOf(item); | ||
return index >= 0 ? array.splice(index, 1) : false; | ||
function once(fn) { | ||
var called = false; | ||
return function() { | ||
if (!called) { | ||
called = true; | ||
fn.apply(this, arguments); | ||
} | ||
} | ||
} | ||
@@ -37,17 +43,18 @@ | ||
var ignoreErrors = this.ignoreErrors; | ||
var executeOpen = once(function() { | ||
setTimeout(function () { | ||
open(url, browser, function(err) { | ||
if (err) throw err; | ||
}); | ||
}, delay); | ||
}) | ||
compiler.plugin('watch-run', function checkWatchingMode(watching, done) { | ||
compiler.plugin('watch-run', once(function checkWatchingMode(watching, done) { | ||
isWatching = true; | ||
removeFromArray(watching.compiler._plugins['watch-run'], checkWatchingMode); | ||
done(); | ||
}); | ||
})); | ||
compiler.plugin('done', function doneCallback(stats) { | ||
if (isWatching && (!stats.hasErrors() || ignoreErrors)) { | ||
removeFromArray(stats.compilation.compiler._plugins['done'], doneCallback); | ||
setTimeout(function () { | ||
open(url, browser, function(err) { | ||
if (err) throw err; | ||
}); | ||
}, delay); | ||
executeOpen(); | ||
} | ||
@@ -54,0 +61,0 @@ }); |
{ | ||
"name": "open-browser-webpack-plugin", | ||
"version": "0.0.3", | ||
"version": "0.0.4", | ||
"description": "Opens the browser when Webpack is ready serving your files.", | ||
@@ -8,3 +8,4 @@ "main": "index.js", | ||
"debug": "node fixtures/debug.js", | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
"test": "echo \"Error: no test specified\" && exit 1", | ||
"postversion": "git push && git push --tags" | ||
}, | ||
@@ -11,0 +12,0 @@ "repository": { |
# Open Browser Webpack Plugin | ||
Opens a new browser tab when Webpack loads. Very useful if you're lazy and don't want to force yourself to open a new tab when Webpack is ready to play! | ||
## Installation | ||
``` | ||
npm install open-browser-webpack-plugin --save-dev | ||
``` | ||
## Usage | ||
@@ -58,2 +64,6 @@ | ||
### 0.0.4 - 2017-02-19 | ||
#### Fixes | ||
- Fix issue where other Webpack callbacks were removed. (Thanks to @plemarquand) | ||
### 0.0.3 - 2016-10-31 | ||
@@ -60,0 +70,0 @@ #### Added |
5590
79
87