1
1
require ( './check-versions' ) ( ) ; // 检查 Node 和 npm 版本
2
+
2
3
var config = require ( '../config' ) ;
3
4
if ( ! process . env . NODE_ENV ) {
4
5
process . env . NODE_ENV = JSON . parse ( config . dev . env . NODE_ENV )
@@ -28,8 +29,8 @@ var devMiddleware = require('webpack-dev-middleware')(compiler, {
28
29
} ) ;
29
30
30
31
var hotMiddleware = require ( 'webpack-hot-middleware' ) ( compiler , {
31
- log : ( ) => {
32
- }
32
+ log : false ,
33
+ heartbeat : 2000
33
34
} ) ;
34
35
35
36
// force page reload when html-webpack-plugin template changes
@@ -40,8 +41,6 @@ compiler.plugin('compilation', function (compilation) {
40
41
} )
41
42
} ) ;
42
43
43
- // compiler.apply(new DashboardPlugin());
44
-
45
44
// proxy api requests
46
45
Object . keys ( proxyTable ) . forEach ( function ( context ) {
47
46
var options = proxyTable [ context ]
@@ -67,18 +66,26 @@ app.use(staticPath, express.static('./static'));
67
66
68
67
var uri = 'http://localhost:' + port
69
68
70
- devMiddleware . waitUntilValid ( function ( ) {
71
- console . log ( '> Listening at ' + uri + '\n' )
72
- } ) ;
73
-
74
- module . exports = app . listen ( port , function ( err ) {
75
- if ( err ) {
76
- console . log ( err ) ;
77
- return
78
- }
79
-
80
- // when env is testing, don't need open it
81
- if ( autoOpenBrowser && process . env . NODE_ENV !== 'testing' ) {
82
- opn ( uri )
83
- }
84
- } ) ;
69
+ var _resolve
70
+ var readyPromise = new Promise ( resolve => {
71
+ _resolve = resolve
72
+ } )
73
+
74
+ console . log ( '> Starting dev server...' )
75
+ devMiddleware . waitUntilValid ( ( ) => {
76
+ console . log ( '> Listening at ' + uri + '\n' )
77
+ // when env is testing, don't need open it
78
+ if ( autoOpenBrowser && process . env . NODE_ENV !== 'testing' ) {
79
+ opn ( uri )
80
+ }
81
+ _resolve ( )
82
+ } )
83
+
84
+ var server = app . listen ( port )
85
+
86
+ module . exports = {
87
+ ready : readyPromise ,
88
+ close : ( ) => {
89
+ server . close ( )
90
+ }
91
+ }
0 commit comments