@@ -8,9 +8,10 @@ const chalk = require('chalk')
8
8
const webpack = require ( 'webpack' )
9
9
const config = require ( '../config' )
10
10
const webpackConfig = require ( './webpack.prod.conf' )
11
- const server = require ( 'pushstate-server' )
11
+ var connect = require ( 'connect' ) ;
12
+ var serveStatic = require ( 'serve-static' )
12
13
13
- var spinner = ora ( 'building for ' + process . env . env_config + ' environment...' )
14
+ const spinner = ora ( 'building for ' + process . env . env_config + ' environment...' )
14
15
spinner . start ( )
15
16
16
17
rm ( path . join ( config . build . assetsRoot , config . build . assetsSubDirectory ) , err => {
@@ -27,22 +28,29 @@ rm(path.join(config.build.assetsRoot, config.build.assetsSubDirectory), err => {
27
28
} ) + '\n\n' )
28
29
29
30
if ( stats . hasErrors ( ) ) {
30
- console . log ( chalk . red ( ' Build failed with errors.\n' ) )
31
+ console . log ( chalk . red ( ' Build failed with errors.\n' ) )
31
32
process . exit ( 1 )
32
33
}
33
34
34
- console . log ( chalk . cyan ( ' Build complete.\n' ) )
35
+ console . log ( chalk . cyan ( ' Build complete.\n' ) )
35
36
console . log ( chalk . yellow (
36
- ' Tip: built files are meant to be served over an HTTP server.\n' +
37
- ' Opening index.html over file:// won\'t work.\n'
37
+ ' Tip: built files are meant to be served over an HTTP server.\n' +
38
+ ' Opening index.html over file:// won\'t work.\n'
38
39
) )
39
- if ( process . env . npm_config_preview ) {
40
- server . start ( {
41
- port : 9526 ,
42
- directory : './dist' ,
43
- file : '/index.html'
40
+
41
+ if ( process . env . npm_config_preview ) {
42
+ const port = 9526
43
+ const host = "http://localhost:" + port
44
+ const basePath = config . build . assetsPublicPath
45
+ const app = connect ( )
46
+
47
+ app . use ( basePath , serveStatic ( './dist' , {
48
+ 'index' : [ 'index.html' , '/' ]
49
+ } ) )
50
+
51
+ app . listen ( port , function ( ) {
52
+ console . log ( chalk . green ( `> Listening at http://localhost:${ port } ${ basePath } ` ) )
44
53
} ) ;
45
- console . log ( '> Listening at ' + 'http://localhost:9526' + '\n' )
46
54
}
47
55
} )
48
56
} )
0 commit comments