From 0e8d82aa6339b8c342facda28c285f41d5dffd93 Mon Sep 17 00:00:00 2001 From: Stephan Date: Thu, 11 Aug 2016 14:01:28 +0200 Subject: [PATCH] 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 --- .gitignore | 3 +++ server.js | 25 ++++++++++++++++++++++--- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 7830694..fb1fbda 100644 --- a/.gitignore +++ b/.gitignore @@ -28,3 +28,6 @@ node_modules # Bower bower_components/ + +# IDE/Editor data +.idea diff --git a/server.js b/server.js index 9fd4659..1030b2e 100644 --- a/server.js +++ b/server.js @@ -6,12 +6,31 @@ const WebpackDevServer = require('webpack-dev-server'); const config = require('./webpack.config'); const open = require('open'); -new WebpackDevServer(webpack(config), config.devServer) +/** + * Flag indicating whether webpack compiled for the first time. + * @type {boolean} + */ +let isInitialCompilation = true; + +const compiler = webpack(config); + +new WebpackDevServer(compiler, config.devServer) .listen(config.port, 'localhost', (err) => { if (err) { console.log(err); } console.log('Listening at localhost:' + config.port); - console.log('Opening your system browser...'); - open('http://localhost:' + config.port + '/webpack-dev-server/'); +}); + +compiler.plugin('done', () => { + if (isInitialCompilation) { + // Ensures that we log after webpack printed its stats (is there a better way?) + setTimeout(() => { + console.log('\n✓ The bundle is now ready for serving!\n'); + console.log(' Open in iframe Mode:\t\x1b[33m%s\x1b[0m', 'http://localhost:' + config.port + '/webpack-dev-server/'); + console.log(' Open in inline Mode:\t\x1b[33m%s\x1b[0m', 'http://localhost:' + config.port + '/\n'); + console.log(' \x1b[33mHRM is active\x1b[0m. The bundle will automatically rebuild and live-update on changes.') + }, 350); + } + isInitialCompilation = false; });