Skip to content

Commit 27a66e3

Browse files
committed
first run.
1 parent 21a3c61 commit 27a66e3

File tree

2 files changed

+34
-26
lines changed

2 files changed

+34
-26
lines changed

lib/index.js

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ var WebpackShellPlugin = function () {
5050
} else {
5151
this.options = defaultOptions;
5252
}
53+
this.firstRun = true;
5354
}
5455

5556
babelHelpers.createClass(WebpackShellPlugin, [{
@@ -64,19 +65,22 @@ var WebpackShellPlugin = function () {
6465
}
6566

6667
compiler.plugin('done', function (compilation) {
67-
if (compilation.compilation.compiler._plugins['watch-run']) {
68-
// Running in dev-server @todo check and validate this
69-
var open = require('open');
70-
open('http://127.0.0.1:' + _this.options.port.toString() + '/');
71-
} else {
72-
var browserSync = require('browser-sync');
73-
browserSync.init({
74-
server: {
75-
baseDir: compilation.options.output.path,
76-
browser: _this.options.browser,
77-
port: _this.options.port
78-
}
79-
});
68+
if (_this.firstRun) {
69+
if (compilation.compilation.compiler._plugins['watch-run']) {
70+
// Running in dev-server @todo check and validate this
71+
var open = require('open');
72+
open('http://127.0.0.1:' + _this.options.port.toString() + '/');
73+
} else {
74+
var browserSync = require('browser-sync');
75+
browserSync.init({
76+
server: {
77+
baseDir: compilation.options.output.path,
78+
browser: _this.options.browser,
79+
port: _this.options.port
80+
}
81+
});
82+
}
83+
_this.firstRun = false;
8084
}
8185
});
8286
}

src/webpack-browser-plugin.js

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export default class WebpackShellPlugin {
1919
} else {
2020
this.options = defaultOptions;
2121
}
22+
this.firstRun = true;
2223
}
2324

2425
apply(compiler) {
@@ -29,19 +30,22 @@ export default class WebpackShellPlugin {
2930
}
3031

3132
compiler.plugin('done', (compilation) => {
32-
if (compilation.compilation.compiler._plugins['watch-run']) {
33-
// Running in dev-server @todo check and validate this
34-
const open = require('open');
35-
open(`http://127.0.0.1:${this.options.port.toString()}/`);
36-
} else {
37-
const browserSync = require('browser-sync');
38-
browserSync.init({
39-
server: {
40-
baseDir: compilation.options.output.path,
41-
browser: this.options.browser,
42-
port: this.options.port
43-
}
44-
});
33+
if (this.firstRun) {
34+
if (compilation.compilation.compiler._plugins['watch-run']) {
35+
// Running in dev-server @todo check and validate this
36+
const open = require('open');
37+
open(`http://127.0.0.1:${this.options.port.toString()}/`);
38+
} else {
39+
const browserSync = require('browser-sync');
40+
browserSync.init({
41+
server: {
42+
baseDir: compilation.options.output.path,
43+
browser: this.options.browser,
44+
port: this.options.port
45+
}
46+
});
47+
}
48+
this.firstRun = false;
4549
}
4650
});
4751
}

0 commit comments

Comments
 (0)