11'use strict'
22
3+ require ( './check-versions' ) ( )
4+
35const path = require ( 'path' )
46const express = require ( 'express' )
57const webpack = require ( 'webpack' )
@@ -12,6 +14,8 @@ const webpackConfig = process.env.NODE_ENV === 'testing'
1214
1315// default port where dev server listens for incoming traffic
1416const port = process . env . PORT || config . dev . port
17+ // automatically open browser, if not set will be false
18+ const autoOpenBrowser = Boolean ( config . dev . autoOpenBrowser )
1519// Define HTTP proxies to your custom API backend
1620// https://github.com/chimurai/http-proxy-middleware
1721const proxyTable = config . dev . proxyTable
@@ -42,7 +46,7 @@ Object.keys(proxyTable).forEach(context => {
4246 if ( typeof options === 'string' ) {
4347 options = { target : options }
4448 }
45- app . use ( proxyMiddleware ( context , options ) )
49+ app . use ( proxyMiddleware ( options . filter || context , options ) )
4650} )
4751
4852// handle fallback for HTML5 history API
@@ -59,12 +63,20 @@ app.use(hotMiddleware)
5963const staticPath = path . posix . join ( config . dev . assetsPublicPath , config . dev . assetsSubDirectory )
6064app . use ( staticPath , express . static ( './assets' ) )
6165
66+ const uri = 'http://localhost:' + port
67+
68+ devMiddleware . waitUntilValid ( ( ) => {
69+ console . log ( '> Listening at ' + uri + '\n' )
70+ } )
71+
6272module . exports = app . listen ( port , err => {
6373 if ( err ) {
6474 console . log ( err )
6575 return
6676 }
67- const uri = 'http://localhost:' + port
68- console . log ( 'Listening at ' + uri + '\n' )
69- opn ( uri )
77+
78+ // when env is testing, don't need open it
79+ if ( autoOpenBrowser && process . env . NODE_ENV !== 'testing' ) {
80+ opn ( uri )
81+ }
7082} )
0 commit comments