Add window.onNuxtReady before plugins

This commit is contained in:
Sébastien Chopin 2016-12-07 23:58:32 +01:00
parent 78a2c5afe7
commit 48c544b106
2 changed files with 11 additions and 8 deletions

View File

@ -222,20 +222,14 @@ const resolveComponents = flatMapComponents(router.match(path), (Component, _, m
return Component
})
// window.onNuxtReady(() => console.log('Ready')) hook
// Useful for jsdom testing or plugins (https://github.com/tmpvar/jsdom#dealing-with-asynchronous-script-loading)
let _readyCbs = []
window.onNuxtReady = function (cb) {
_readyCbs.push(cb)
}
function nuxtReady (app) {
_readyCbs.forEach((cb) => {
window._nuxtReadyCbs.forEach((cb) => {
if (typeof cb === 'function') {
cb(app)
}
})
// Add router hooks
router.afterEach(function (to) {
router.afterEach(function (to, from) {
app.$nuxt.$emit('routeChanged', to, from)
})
}

View File

@ -21,6 +21,15 @@ Vue.use(Meta, {
tagIDKeyName: 'hid' // the property name that vue-meta uses to determine whether to overwrite or append a tag
})
if (process.BROWSER_BUILD) {
// window.onNuxtReady(() => console.log('Ready')) hook
// Useful for jsdom testing or plugins (https://github.com/tmpvar/jsdom#dealing-with-asynchronous-script-loading)
window._nuxtReadyCbs = []
window.onNuxtReady = function (cb) {
window._nuxtReadyCbs.push(cb)
}
}
// Includes external plugins
<% plugins.forEach(function (pluginPath) { %>
require('<%= pluginPath %>')