Skip to content

Commit 0e8d82a

Browse files
authored
Disable opening web browser on npm start (#48)
This PR removed calling `open()` in `server.js` and added output with the dev server urls after the initial Webpack compilation. Closes #47
1 parent 8a1dd60 commit 0e8d82a

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,6 @@ node_modules
2828

2929
# Bower
3030
bower_components/
31+
32+
# IDE/Editor data
33+
.idea

server.js

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,31 @@ const WebpackDevServer = require('webpack-dev-server');
66
const config = require('./webpack.config');
77
const open = require('open');
88

9-
new WebpackDevServer(webpack(config), config.devServer)
9+
/**
10+
* Flag indicating whether webpack compiled for the first time.
11+
* @type {boolean}
12+
*/
13+
let isInitialCompilation = true;
14+
15+
const compiler = webpack(config);
16+
17+
new WebpackDevServer(compiler, config.devServer)
1018
.listen(config.port, 'localhost', (err) => {
1119
if (err) {
1220
console.log(err);
1321
}
1422
console.log('Listening at localhost:' + config.port);
15-
console.log('Opening your system browser...');
16-
open('http://localhost:' + config.port + '/webpack-dev-server/');
23+
});
24+
25+
compiler.plugin('done', () => {
26+
if (isInitialCompilation) {
27+
// Ensures that we log after webpack printed its stats (is there a better way?)
28+
setTimeout(() => {
29+
console.log('\n✓ The bundle is now ready for serving!\n');
30+
console.log(' Open in iframe Mode:\t\x1b[33m%s\x1b[0m', 'http://localhost:' + config.port + '/webpack-dev-server/');
31+
console.log(' Open in inline Mode:\t\x1b[33m%s\x1b[0m', 'http://localhost:' + config.port + '/\n');
32+
console.log(' \x1b[33mHRM is active\x1b[0m. The bundle will automatically rebuild and live-update on changes.')
33+
}, 350);
34+
}
35+
isInitialCompilation = false;
1736
});

0 commit comments

Comments
 (0)