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) => {
|
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()
|
||||||
}
|
}
|
||||||
|
@ -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)
|
||||||
}
|
}
|
||||||
|
@ -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) {
|
||||||
|
@ -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
|
||||||
|
Loading…
Reference in New Issue
Block a user