Commit f7669ef0 authored by Evan You's avatar Evan You

improve dev server compile error handling

parent 4537fdd6
...@@ -4,6 +4,12 @@ const MFS = require('memory-fs') ...@@ -4,6 +4,12 @@ const MFS = require('memory-fs')
const clientConfig = require('./webpack.client.config') const clientConfig = require('./webpack.client.config')
const serverConfig = require('./webpack.server.config') const serverConfig = require('./webpack.server.config')
const readFile = (fs, file) => {
try {
return fs.readFileSync(path.join(clientConfig.output.path, file), 'utf-8')
} catch (e) {}
}
module.exports = function setupDevServer (app, cb) { module.exports = function setupDevServer (app, cb) {
let bundle, clientManifest let bundle, clientManifest
let resolve let resolve
...@@ -28,10 +34,16 @@ module.exports = function setupDevServer (app, cb) { ...@@ -28,10 +34,16 @@ module.exports = function setupDevServer (app, cb) {
noInfo: true noInfo: true
}) })
app.use(devMiddleware) app.use(devMiddleware)
clientCompiler.plugin('done', () => { clientCompiler.plugin('done', stats => {
const fs = devMiddleware.fileSystem stats = stats.toJson()
const readFile = file => fs.readFileSync(path.join(clientConfig.output.path, file), 'utf-8') stats.errors.forEach(err => console.error(err))
clientManifest = JSON.parse(readFile('vue-ssr-client-manifest.json')) stats.warnings.forEach(err => console.warn(err))
if (stats.errors.length) return
clientManifest = JSON.parse(readFile(
devMiddleware.fileSystem,
'vue-ssr-client-manifest.json'
))
if (bundle) { if (bundle) {
ready(bundle, { ready(bundle, {
clientManifest clientManifest
...@@ -49,12 +61,10 @@ module.exports = function setupDevServer (app, cb) { ...@@ -49,12 +61,10 @@ module.exports = function setupDevServer (app, cb) {
serverCompiler.watch({}, (err, stats) => { serverCompiler.watch({}, (err, stats) => {
if (err) throw err if (err) throw err
stats = stats.toJson() stats = stats.toJson()
stats.errors.forEach(err => console.error(err)) if (stats.errors.length) return
stats.warnings.forEach(err => console.warn(err))
const readFile = file => mfs.readFileSync(path.join(clientConfig.output.path, file), 'utf-8')
// read bundle generated by vue-ssr-webpack-plugin // read bundle generated by vue-ssr-webpack-plugin
bundle = JSON.parse(readFile('vue-ssr-server-bundle.json')) bundle = JSON.parse(readFile(mfs, 'vue-ssr-server-bundle.json'))
if (clientManifest) { if (clientManifest) {
ready(bundle, { ready(bundle, {
clientManifest clientManifest
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment