mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-27 08:02:01 +00:00
fix: hmr in modern mode (#4623)
This commit is contained in:
parent
8cd19f0bd4
commit
df9b32a1c4
@ -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()
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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) {
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user