import SSR plugins

This supports proper functionality of plugins registering Vue Components.
Also we await for each plugin to make sure that they are initialized before createApp
This commit is contained in:
Pooya Parsa 2017-05-22 15:30:04 +04:30
parent eaee5afbde
commit bbd2eddb40

View File

@ -12,6 +12,11 @@ import App from '<%= appPath %>'
import { getContext } from './utils'
// Import SSR plugins
<% plugins.forEach(function (plugin) { if (plugin.ssr)
{ %>import <%= plugin.name %> from '<%= r(plugin.src) %>'
<% }}) %>
// Component: <nuxt-child>
Vue.component(NuxtChild.name, NuxtChild)
// Component: <nuxt-link>
@ -113,20 +118,18 @@ async function createApp (ssrContext) {
delete ctx.redirect
delete ctx.error
// Includes & Inject external plugins
// Inject external plugins
<% plugins.forEach(function (plugin) {
if (plugin.ssr) { %>
let <%= plugin.name %> = require('<%= plugin.src %>')
<%= plugin.name %> = <%= plugin.name %>.default || <%= plugin.name %>
if (typeof <%= plugin.name %> === 'function') {
<%= plugin.name %>(ctx)
await <%= plugin.name %>(ctx)
}
<% } else { %>
if (process.browser) {
let <%= plugin.name %> = require('<%= plugin.src %>')
<%= plugin.name %> = <%= plugin.name %>.default || <%= plugin.name %>
if (typeof <%= plugin.name %> === 'function') {
<%= plugin.name %>(ctx)
await <%= plugin.name %>(ctx)
}
}
<% }