Repository URL to install this package:
|
Version:
3.8.1 ▾
|
import {
HotModuleReplacementPlugin,
WatchIgnorePlugin,
NamedModulesPlugin,
} from 'webpack'
import { resolveToRoot } from '../../resolveToRoot'
import { Configuration, Options } from '../../typings'
const IS_WEBPACK4 = true
const IS_BABEL_CACHE_ENABLED = false
const IGNORE_SOME = process.env.BABEL_CACHE || IS_BABEL_CACHE_ENABLED
/**
* @see https://github.com/webpack/webpack/issues/1151#issuecomment-138809417
* @see https://github.com/insin/nwb/blob/master/docs/Configuration.md#webpack-configuration
* @see http://stackoverflow.com/questions/32296967/webpack-dev-server-doesnt-generate-source-maps
* @see https://webpack.github.io/docs/configuration.html#devtool
* @see https://github.com/gaearon/react-hot-loader/blob/master/docs/Troubleshooting.md
* @see https://github.com/glenjamin/ultimate-hot-reloading-example
* @see https://hackernoon.com/hot-reload-all-the-things-ec0fed8ab0
* @see https://medium.com/@rajaraodv/webpacks-hmr-react-hot-loader-the-missing-manual-232336dc0d96
*/
export default function hmr(config: Configuration, options: Options) {
const { isDev, isServer } = options
if (isServer) {
// ignoring HMR on server
return
}
if (isDev) {
// webpack v4 - https://github.com/webpack/webpack/issues/6357
config.plugins.push(new NamedModulesPlugin())
/**
* @see https://github.com/gaearon/react-hot-loader/blob/master/docs/Troubleshooting.md#uncaught-rangeerror-maximum-call-stack-size-exceeded !!!!!!
* @todo https://webpack.js.org/configuration/output/#output-hotupdatefunction
*/
const hotModuleReplacementConfig = {
/**
* @see https://github.com/webpack/webpack/issues/2985
* @see https://github.com/webpack/webpack/issues/6693
*/
multiStep: true,
requestTimeout: 1000000,
}
if (process.env.IS_HMR_ENABLED) {
const plugin = new HotModuleReplacementPlugin(hotModuleReplacementConfig)
config.plugins.unshift(plugin)
}
// @NOTE !!!!!!!!!!!!! ignoring these makes it take 1/2 the time to HMR
const ignorePaths = [
'./modules/',
'./node_modules',
'./views/structured',
'./config',
'./scripts',
// @todo needs more ignoring...
'./client/workers',
].map(resolveToRoot)
// THIS BREAKS WHAT "HOT" does...
if (IGNORE_SOME) {
const ignore = new WatchIgnorePlugin(ignorePaths)
config.plugins.push(ignore)
}
}
}