mirror of
https://github.com/nuxt/nuxt.git
synced 2025-02-21 07:59:33 +00:00
feat(webpack): support build.hotMiddleware.client
(#4796)
This commit is contained in:
parent
fa78f5396e
commit
dcdbaba710
@ -182,6 +182,7 @@ export class WebpackBundler {
|
|||||||
|
|
||||||
const { name } = compiler.options
|
const { name } = compiler.options
|
||||||
const { nuxt: { server }, options } = this.context
|
const { nuxt: { server }, options } = this.context
|
||||||
|
const { client, ...hotMiddlewareOptions } = options.build.hotMiddleware || {}
|
||||||
|
|
||||||
// Create webpack dev middleware
|
// Create webpack dev middleware
|
||||||
this.devMiddleware[name] = pify(
|
this.devMiddleware[name] = pify(
|
||||||
@ -209,7 +210,7 @@ export class WebpackBundler {
|
|||||||
log: false,
|
log: false,
|
||||||
heartbeat: 10000
|
heartbeat: 10000
|
||||||
},
|
},
|
||||||
options.build.hotMiddleware,
|
hotMiddlewareOptions,
|
||||||
{
|
{
|
||||||
path: `/__webpack_hmr/${name}`
|
path: `/__webpack_hmr/${name}`
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import path from 'path'
|
import path from 'path'
|
||||||
import fs from 'fs'
|
import fs from 'fs'
|
||||||
|
import querystring from 'querystring'
|
||||||
import consola from 'consola'
|
import consola from 'consola'
|
||||||
import webpack from 'webpack'
|
import webpack from 'webpack'
|
||||||
import HTMLPlugin from 'html-webpack-plugin'
|
import HTMLPlugin from 'html-webpack-plugin'
|
||||||
@ -159,6 +160,20 @@ export default class WebpackClientConfig extends WebpackBaseConfig {
|
|||||||
config() {
|
config() {
|
||||||
const config = super.config()
|
const config = super.config()
|
||||||
|
|
||||||
|
const { client = {} } = this.options.build.hotMiddleware || {}
|
||||||
|
const { ansiColors, overlayStyles, ...options } = client
|
||||||
|
const hotMiddlewareClientOptions = {
|
||||||
|
reload: true,
|
||||||
|
timeout: 30000,
|
||||||
|
ansiColors: JSON.stringify(ansiColors),
|
||||||
|
overlayStyles: JSON.stringify(overlayStyles),
|
||||||
|
...options,
|
||||||
|
name: this.name
|
||||||
|
}
|
||||||
|
const clientPath = `${this.options.router.base}/__webpack_hmr/${this.name}`
|
||||||
|
const hotMiddlewareClientOptionsStr =
|
||||||
|
`${querystring.stringify(hotMiddlewareClientOptions)}&path=${clientPath}`.replace(/\/\//g, '/')
|
||||||
|
|
||||||
// Entry points
|
// Entry points
|
||||||
config.entry = {
|
config.entry = {
|
||||||
app: [path.resolve(this.options.buildDir, 'client.js')]
|
app: [path.resolve(this.options.buildDir, 'client.js')]
|
||||||
@ -170,9 +185,7 @@ export default class WebpackClientConfig extends WebpackBaseConfig {
|
|||||||
// https://github.com/webpack-contrib/webpack-hot-middleware/issues/53#issuecomment-162823945
|
// https://github.com/webpack-contrib/webpack-hot-middleware/issues/53#issuecomment-162823945
|
||||||
'eventsource-polyfill',
|
'eventsource-polyfill',
|
||||||
// https://github.com/glenjamin/webpack-hot-middleware#config
|
// https://github.com/glenjamin/webpack-hot-middleware#config
|
||||||
`webpack-hot-middleware/client?name=${this.name}&reload=true&timeout=30000&path=${
|
`webpack-hot-middleware/client?${hotMiddlewareClientOptionsStr}`
|
||||||
this.options.router.base
|
|
||||||
}/__webpack_hmr/${this.name}`.replace(/\/\//g, '/')
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user