Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for custom hot reload config #823

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -494,11 +494,19 @@ In order to extend our usage of `webpack`, you can define a function that extend

module.exports = {
webpack: (config, { dev }) => {
   // Perform customizations to config
   // Perform customizations to webpack config

   // Important: return the modified config
return config
}
},
webpackDevMiddleware: (config) => {
// Perform customizations to webpack dev middleware config

    // Important: return the modified config
return config
},
// Enable / disable X-Powered-By, enabled by default
poweredByHeader: true
}
```

Expand Down
1 change: 1 addition & 0 deletions server/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const cache = new Map()

const defaultConfig = {
webpack: null,
webpackDevMiddleware: null,
poweredByHeader: true
}

Expand Down
13 changes: 11 additions & 2 deletions server/hot-reloader.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ import isWindowsBash from 'is-windows-bash'
import webpack from './build/webpack'
import clean from './build/clean'
import readPage from './read-page'
import getConfig from './config'

export default class HotReloader {
constructor (dir, { quiet } = {}) {
this.config = getConfig(dir)
this.dir = dir
this.quiet = quiet
this.middlewares = []
Expand Down Expand Up @@ -130,7 +132,7 @@ export default class HotReloader {
}
} : {}

this.webpackDevMiddleware = webpackDevMiddleware(compiler, {
let webpackDevMiddlewareConfig = {
publicPath: '/_webpack/',
noInfo: true,
quiet: true,
Expand All @@ -142,7 +144,14 @@ export default class HotReloader {
]
},
...windowsSettings
})
}

if (this.config.webpackDevMiddleware) {
console.log('> Using "webpackDevMiddleware" config function defined in next.config.js.')
webpackDevMiddlewareConfig = this.config.webpackDevMiddleware(webpackDevMiddlewareConfig)
}

this.webpackDevMiddleware = webpackDevMiddleware(compiler, webpackDevMiddlewareConfig)

this.webpackHotMiddleware = webpackHotMiddleware(compiler, { log: false })

Expand Down