Skip to content

Commit

Permalink
addition to the noderat's pull request. minor naming improvements. lo…
Browse files Browse the repository at this point in the history
…dash dependency update. version 1.1.0
  • Loading branch information
Valentyn committed Jul 6, 2016
1 parent 7a41c7b commit 7311115
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
22 changes: 12 additions & 10 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,38 +1,40 @@
var _ = require('lodash');
var browserSync = require('browser-sync');

function BrowserSyncPlugin(browserSyncOptions, options) {
function BrowserSyncPlugin(browserSyncOptions, pluginOptions) {
var self = this;

var defaultOptions = {
var defaultPluginOptions = {
reload: true,
name: 'bs-webpack-plugin',
callback: undefined
};

self.browserSyncOptions = _.extend({}, browserSyncOptions);
self.options = _.extend({}, defaultOptions, options);
self.options = _.extend({}, defaultPluginOptions, pluginOptions);

self.browserSync = browserSync.create(self.options.name);
self.webpackIsWatching = false;
self.browserSyncIsRunning = false;
self.isWebpackWatching = false;
self.isBrowserSyncRunning = false;
}

BrowserSyncPlugin.prototype.apply = function (compiler) {
var self = this;

compiler.plugin('watch-run', function (watching, callback) {
self.webpackIsWatching = true;
self.isWebpackWatching = true;
callback(null, null);
});

compiler.plugin('compilation', function () {
self.browserSync.notify('Rebuilding');
if (self.isBrowserSyncRunning) {

This comment has been minimized.

Copy link
@noderat

noderat Jul 7, 2016

Contributor

Ah, good catch @Va1 while I don't believe that browserSync minds that could change - better off checking then be left with a future issue.

self.browserSync.notify('Rebuilding...');
}
});

compiler.plugin('done', function (stats) {
if (self.webpackIsWatching) {
if (self.browserSyncIsRunning) {
if (self.isWebpackWatching) {
if (self.isBrowserSyncRunning) {
if (self.options.reload) {
self.browserSync.reload();
}
Expand All @@ -43,7 +45,7 @@ BrowserSyncPlugin.prototype.apply = function (compiler) {
self.browserSync.init(self.browserSyncOptions);
}

self.browserSyncIsRunning = true;
self.isBrowserSyncRunning = true;
}
}
});
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "browser-sync-webpack-plugin",
"version": "1.0.3",
"version": "1.1.0",
"description": "BrowserSync and Webpack integration",
"keywords": [
"webpack",
Expand All @@ -12,7 +12,7 @@
],
"main": "index.js",
"dependencies": {
"lodash": "^3.x.x"
"lodash": "^4.x.x"
},
"devDependencies": {},
"peerDependencies": {
Expand Down

0 comments on commit 7311115

Please sign in to comment.