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) => { const detectModernBrowser = ({ socket = {}, headers }) => {
if (options.modern === 'server') { if (socket.isModernBrowser === undefined) {
const { socket = {}, headers } = req
if (socket.modernMode === undefined) {
const ua = headers && headers['user-agent'] 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) => { export default ({ context }) => (req, res, next) => {
detectModernBuild(context) detectModernBuild(context)
detectModernBrowser(req, context.options) detectModernBrowser(req)
setModernMode(req, context.options)
next() next()
} }

View File

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

View File

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

View File

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