From ea03d76e852cad1f614ed810ce8476eca664f574 Mon Sep 17 00:00:00 2001 From: Sebastien Chopin Date: Fri, 2 Jun 2017 12:15:38 +0200 Subject: [PATCH] Fix issue #829 with onNuxtReady undefined --- lib/app/index.js | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/lib/app/index.js b/lib/app/index.js index 9e80d20401..a812d16426 100644 --- a/lib/app/index.js +++ b/lib/app/index.js @@ -12,9 +12,19 @@ import App from '<%= appPath %>' import { getContext } from './utils' +if (process.browser) { + // 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) + } +} + // Import SSR plugins <% plugins.forEach(function (plugin) { if (plugin.ssr) -{ %>import <%= plugin.name %> from '<%= r(plugin.src) %>' +{ %>let <%= plugin.name %> = require('<%= r(plugin.src) %>') +<%= plugin.name %> = <%= plugin.name %>.default || <%= plugin.name %> <% }}) %> // Component: @@ -58,12 +68,6 @@ async function createApp (ssrContext) { store.replaceState(window.__NUXT__.state) } <% } %> - // 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) - } } // root instance