fix: hmr in modern mode (#4623)

This commit is contained in:
Xin Du (Clark) 2018-12-24 16:26:39 +00:00 committed by Pooya Parsa
parent 8cd19f0bd4
commit df9b32a1c4
4 changed files with 19 additions and 10 deletions

View File

@ -34,19 +34,27 @@ const detectModernBuild = ({ options, resources }) => {
}
}
const detectModernBrowser = (req, options) => {
if (options.modern === 'server') {
const { socket = {}, headers } = req
if (socket.modernMode === undefined) {
const detectModernBrowser = ({ socket = {}, headers }) => {
if (socket.isModernBrowser === undefined) {
const ua = headers && headers['user-agent']
socket.modernMode = isModernBrowser(ua)
socket.isModernBrowser = isModernBrowser(ua)
}
req.modernMode = socket.modernMode
}
const setModernMode = (req, options) => {
const { socket = {} } = req
const isModernBrowser = socket.isModernBrowser
if (options.modern === 'server') {
req.modernMode = isModernBrowser
}
if (options.dev) {
req.devModernMode = isModernBrowser
}
}
export default ({ context }) => (req, res, next) => {
detectModernBuild(context)
detectModernBrowser(req, context.options)
detectModernBrowser(req)
setModernMode(req, context.options)
next()
}

View File

@ -83,7 +83,7 @@ export default class Server {
if (this.options.dev) {
this.useMiddleware(modernMiddleware)
this.useMiddleware(async (req, res, next) => {
const name = req.modernMode ? 'modern' : 'client'
const name = req.devModernMode ? 'modern' : 'client'
if (this.devMiddleware && this.devMiddleware[name]) {
await this.devMiddleware[name](req, res)
}

View File

@ -150,6 +150,7 @@ export default class VueRenderer {
if (isMFS) {
// Cleanup MFS as soon as possible to save memory
_fs.unlinkSync(fullPath)
delete this._assetsMapping
}
return contents
} catch (err) {

View File

@ -180,7 +180,7 @@ export class WebpackBundler {
webpackDev(compiler) {
consola.debug('Adding webpack middleware...')
const name = [compiler.options.name]
const name = compiler.options.name
const { nuxt: { server }, options } = this.context
// Create webpack dev middleware