Skip to content

Instantly share code, notes, and snippets.

@caseyWebb
Last active February 6, 2018 04:39
Show Gist options
  • Save caseyWebb/a5fdd929638f961ee673581e7d68ddb1 to your computer and use it in GitHub Desktop.
Save caseyWebb/a5fdd929638f961ee673581e7d68ddb1 to your computer and use it in GitHub Desktop.
Webpack HMR Bug
import { log } from './logger.js'
log()
module.hot.accept('./logger.js', () => log())
export function log() {
// toggle these, they should be printed to the screen one after another
document.body.innerText += 'foo\n'
// document.body.innerText += 'bar\n'
}
{
"license": "MIT",
"dependencies": {
"webpack": "^3.10.0",
"webpack-dev-server": "^2.11.1"
},
"scripts": {
"start": "webpack-dev-server --hot"
},
"devDependencies": {
"html-webpack-plugin": "^2.30.1"
}
}
'use strict'
const { HotModuleReplacementPlugin, NamedModulesPlugin } = require('webpack')
const HtmlWebpackPlugin = require('html-webpack-plugin')
module.exports = {
context: __dirname,
entry: {
app: './app.js'
},
output: {
filename: 'bundle.js',
path: __dirname + '/dist',
publicPath: '/'
},
plugins: [
// new NamedModulesPlugin(), // causes error
new HotModuleReplacementPlugin(),
new HtmlWebpackPlugin()
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment