@@ -4,6 +4,12 @@ const MFS = require('memory-fs')
4
4
const clientConfig = require ( './webpack.client.config' )
5
5
const serverConfig = require ( './webpack.server.config' )
6
6
7
+ const readFile = ( fs , file ) => {
8
+ try {
9
+ return fs . readFileSync ( path . join ( clientConfig . output . path , file ) , 'utf-8' )
10
+ } catch ( e ) { }
11
+ }
12
+
7
13
module . exports = function setupDevServer ( app , cb ) {
8
14
let bundle , clientManifest
9
15
let resolve
@@ -28,10 +34,16 @@ module.exports = function setupDevServer (app, cb) {
28
34
noInfo : true
29
35
} )
30
36
app . use ( devMiddleware )
31
- clientCompiler . plugin ( 'done' , ( ) => {
32
- const fs = devMiddleware . fileSystem
33
- const readFile = file => fs . readFileSync ( path . join ( clientConfig . output . path , file ) , 'utf-8' )
34
- clientManifest = JSON . parse ( readFile ( 'vue-ssr-client-manifest.json' ) )
37
+ clientCompiler . plugin ( 'done' , stats => {
38
+ stats = stats . toJson ( )
39
+ stats . errors . forEach ( err => console . error ( err ) )
40
+ stats . warnings . forEach ( err => console . warn ( err ) )
41
+ if ( stats . errors . length ) return
42
+
43
+ clientManifest = JSON . parse ( readFile (
44
+ devMiddleware . fileSystem ,
45
+ 'vue-ssr-client-manifest.json'
46
+ ) )
35
47
if ( bundle ) {
36
48
ready ( bundle , {
37
49
clientManifest
@@ -49,12 +61,10 @@ module.exports = function setupDevServer (app, cb) {
49
61
serverCompiler . watch ( { } , ( err , stats ) => {
50
62
if ( err ) throw err
51
63
stats = stats . toJson ( )
52
- stats . errors . forEach ( err => console . error ( err ) )
53
- stats . warnings . forEach ( err => console . warn ( err ) )
54
- const readFile = file => mfs . readFileSync ( path . join ( clientConfig . output . path , file ) , 'utf-8' )
64
+ if ( stats . errors . length ) return
55
65
56
66
// read bundle generated by vue-ssr-webpack-plugin
57
- bundle = JSON . parse ( readFile ( 'vue-ssr-server-bundle.json' ) )
67
+ bundle = JSON . parse ( readFile ( mfs , 'vue-ssr-server-bundle.json' ) )
58
68
if ( clientManifest ) {
59
69
ready ( bundle , {
60
70
clientManifest
0 commit comments