Skip to content
This repository has been archived by the owner on Dec 6, 2021. It is now read-only.

Commit

Permalink
force reload when hmr failed
Browse files Browse the repository at this point in the history
  • Loading branch information
egoist committed Feb 16, 2017
1 parent d835713 commit 2c10592
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 4 deletions.
8 changes: 8 additions & 0 deletions lib/dev-client.es6
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
require('eventsource-polyfill')
const hotClient = require('webpack-hot-middleware/client?noInfo=true&reload=true&')

hotClient.subscribe(event => {
if (event.action === 'reload') {
window.location.reload()
}
})
3 changes: 1 addition & 2 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -262,9 +262,8 @@ function start(cliOptions) { // eslint-disable-line complexity

if (options.hot && !options.watch) {
const hmrEntry = options.hmrEntry
const hmrClient = require.resolve('webpack-hot-middleware/client') + `?reload=true&path=http://${options.host}:${options.port}/__webpack_hmr`
for (const entry of hmrEntry) {
webpackConfig.entry[entry].unshift(hmrClient)
webpackConfig.entry[entry].unshift(ownDir('lib/dev-client.es6'))
}

webpackConfig.plugins.push(new webpack.HotModuleReplacementPlugin())
Expand Down
3 changes: 2 additions & 1 deletion lib/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ module.exports = function (compiler, options) {

const devMiddleWare = require('webpack-dev-middleware')(compiler, {
quiet: true,
publicPath: compiler.options.output.publicPath
publicPath: compiler.options.output.publicPath,
path: `http://${options.host}:${options.port}/__webpack_hmr`
})

server.use(devMiddleWare)
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
"eslint": "^3.15.0",
"eslint-config-vue-app": "^1.0.0",
"eslint-loader": "^1.6.1",
"eventsource-polyfill": "^0.9.6",
"express": "^4.14.1",
"extract-text-webpack-plugin": "^2.0.0-rc.3",
"file-loader": "^0.10.0",
Expand Down Expand Up @@ -90,4 +91,4 @@
"webpack-merge": "^2.6.1",
"yarn-install": "^0.2.1"
}
}
}
4 changes: 4 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2381,6 +2381,10 @@ events@^1.0.0:
version "1.1.1"
resolved "https://registry.npmjs.org/events/-/events-1.1.1.tgz#9ebdb7635ad099c70dcc4c2a1f5004288e8bd924"

eventsource-polyfill@^0.9.6:
version "0.9.6"
resolved "https://registry.npmjs.org/eventsource-polyfill/-/eventsource-polyfill-0.9.6.tgz#10e0d187f111b167f28fdab918843ce7d818f13c"

evp_bytestokey@^1.0.0:
version "1.0.0"
resolved "https://registry.npmjs.org/evp_bytestokey/-/evp_bytestokey-1.0.0.tgz#497b66ad9fef65cd7c08a6180824ba1476b66e53"
Expand Down

0 comments on commit 2c10592

Please sign in to comment.