Created
March 22, 2019 06:10
-
-
Save Rulexec/c3aca12196668e3bc2d6eee988ebab22 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export { getResult }; | |
function getResult() { | |
return 42; | |
} | |
// If you uncomment this, HRM in `main.js` will stop work and `getResult()` will return 42 everytime | |
//if (module.hot) module.hot.accept(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { getResult } from './dep.js'; | |
let button = document.getElementById('button'); | |
let resultEl = document.getElementById('result'); | |
button.addEventListener('click', function() { | |
resultEl.textContent = '' + getResult(); | |
}); | |
if (module.hot) module.hot.accept('./dep.js'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "webpack-hrm-bug", | |
"version": "1.0.0", | |
"description": "", | |
"main": "webpack.config.js", | |
"scripts": { | |
"test": "echo \"Error: no test specified\" && exit 1" | |
}, | |
"author": "", | |
"license": "ISC", | |
"dependencies": { | |
"webpack": "^4.29.6", | |
"webpack-cli": "^3.3.0", | |
"webpack-dev-server": "^3.2.1" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const path = require('path'); | |
const webpack = require('webpack'); | |
let config = { | |
mode: 'development', | |
entry: { | |
main: path.resolve(__dirname, 'main.js'), | |
}, | |
output: { | |
filename: '[name].js', | |
path: path.resolve(__dirname, 'dist'), | |
}, | |
plugins: [new webpack.HotModuleReplacementPlugin()], | |
devServer: { | |
hotOnly: true, | |
before: function(app, server) { | |
app.use((req, res, next) => { | |
if (req.path !== '/' && req.path !== '/index.html') { | |
next(); | |
return; | |
} | |
res.setHeader('Content-Type', 'text/html'); | |
res.end('<!doctype html><html><head><meta charset="utf-8"></head><body><div><button id="button">Call fun()</button></div><div id="result"></div><script src="main.js"></script></body></html>'); | |
}); | |
}, | |
}, | |
}; | |
module.exports = config; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment