forked from boranton/testcafe-workshop
add HMR
This commit is contained in:
parent
9add627b92
commit
19d9b92387
@ -34,7 +34,7 @@
|
||||
"prebuild:dev": "rimraf dist",
|
||||
"build:dev": "webpack --env.dev",
|
||||
"start": "http-server",
|
||||
"dev": "webpack-dev-server --env.dev",
|
||||
"dev": "webpack-dev-server --env.dev --hot",
|
||||
"debug": "node-nightly --inspect --debug-brk node_modules/.bin/webpack --env.debug",
|
||||
"debug:dev": "npm run debug -- --env.dev",
|
||||
"debug:prod": "npm run debug -- --env.prod",
|
||||
|
||||
26
src/bootstrap.js
vendored
26
src/bootstrap.js
vendored
@ -1,5 +1,27 @@
|
||||
/* eslint no-console:0 */
|
||||
var app = require('./app')
|
||||
var helpers = require('./helpers')
|
||||
|
||||
helpers.$on(window, 'load', app.onLoad)
|
||||
helpers.$on(window, 'hashchange', app.onLoad)
|
||||
// this is only relevant when using `hot` mode with webpack
|
||||
// special thanks to Eric Clemmons: https://github.com/ericclemmons/webpack-hot-server-example
|
||||
const reloading = document.readyState === 'complete'
|
||||
if (module.hot) {
|
||||
module.hot.accept(function(err) {
|
||||
console.log('❌ HMR Error:', err)
|
||||
})
|
||||
if (reloading) {
|
||||
console.log('🔁 HMR Reloading.')
|
||||
app.onLoad()
|
||||
} else {
|
||||
console.info('✅ HMR Enabled.')
|
||||
bootstrap()
|
||||
}
|
||||
} else {
|
||||
console.info('❌ HMR Not Supported.')
|
||||
bootstrap()
|
||||
}
|
||||
|
||||
function bootstrap() {
|
||||
helpers.$on(window, 'load', app.onLoad)
|
||||
helpers.$on(window, 'hashchange', app.onLoad)
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user