mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-26 07:32:01 +00:00
make use of runInNewContext: false
This commit is contained in:
parent
5d4f289911
commit
1bd8f4ea45
@ -2,13 +2,15 @@
|
|||||||
|
|
||||||
import Vue from 'vue'
|
import Vue from 'vue'
|
||||||
import middleware from './middleware'
|
import middleware from './middleware'
|
||||||
import { app, router<%= (store ? ', store' : '') %>, NuxtError } from './index'
|
import { createApp, NuxtError } from './index'
|
||||||
import { applyAsyncData, getMatchedComponents, getMatchedComponentsInstances, flatMapComponents, getContext, promiseSeries, promisify, getLocation, compile } from './utils'
|
import { applyAsyncData, getMatchedComponents, getMatchedComponentsInstances, flatMapComponents, getContext, promiseSeries, promisify, getLocation, compile } from './utils'
|
||||||
const noopData = () => { return {} }
|
const noopData = () => { return {} }
|
||||||
const noopFetch = () => {}
|
const noopFetch = () => {}
|
||||||
let _lastPaths = []
|
let _lastPaths = []
|
||||||
let _lastComponentsFiles = []
|
let _lastComponentsFiles = []
|
||||||
|
|
||||||
|
const { app, router<%= (store ? ', store' : '') %> } = createApp()
|
||||||
|
|
||||||
function mapTransitions(Components, to, from) {
|
function mapTransitions(Components, to, from) {
|
||||||
return Components.map((Component) => {
|
return Components.map((Component) => {
|
||||||
let transition = Component.options.transition
|
let transition = Component.options.transition
|
||||||
|
@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
import Vue from 'vue'
|
import Vue from 'vue'
|
||||||
import Meta from 'vue-meta'
|
import Meta from 'vue-meta'
|
||||||
import router from './router.js'
|
import { createRouter } from './router.js'
|
||||||
<% if (store) { %>import store from './store.js'<% } %>
|
<% if (store) { %>import { createStore } from './store.js'<% } %>
|
||||||
import NuxtChild from './components/nuxt-child.js'
|
import NuxtChild from './components/nuxt-child.js'
|
||||||
import NuxtLink from './components/nuxt-link.js'
|
import NuxtLink from './components/nuxt-link.js'
|
||||||
import NuxtError from '<%= components.ErrorPage ? components.ErrorPage : "./components/nuxt-error.vue" %>'
|
import NuxtError from '<%= components.ErrorPage ? components.ErrorPage : "./components/nuxt-error.vue" %>'
|
||||||
@ -25,7 +25,20 @@ Vue.use(Meta, {
|
|||||||
tagIDKeyName: 'hid' // the property name that vue-meta uses to determine whether to overwrite or append a tag
|
tagIDKeyName: 'hid' // the property name that vue-meta uses to determine whether to overwrite or append a tag
|
||||||
})
|
})
|
||||||
|
|
||||||
if (process.browser) {
|
const defaultTransition = <%=
|
||||||
|
serialize(transition)
|
||||||
|
.replace('beforeEnter(', 'function(').replace('enter(', 'function(').replace('afterEnter(', 'function(')
|
||||||
|
.replace('enterCancelled(', 'function(').replace('beforeLeave(', 'function(').replace('leave(', 'function(')
|
||||||
|
.replace('afterLeave(', 'function(').replace('leaveCancelled(', 'function(')
|
||||||
|
%>
|
||||||
|
|
||||||
|
export { NuxtError }
|
||||||
|
|
||||||
|
export function createApp (ssrContext) {
|
||||||
|
const store = createStore()
|
||||||
|
const router = createRouter()
|
||||||
|
|
||||||
|
if (process.browser) {
|
||||||
<% if (store) { %>
|
<% if (store) { %>
|
||||||
// Replace store state before calling plugins
|
// Replace store state before calling plugins
|
||||||
if (window.__NUXT__ && window.__NUXT__.state) {
|
if (window.__NUXT__ && window.__NUXT__.state) {
|
||||||
@ -38,20 +51,15 @@ if (process.browser) {
|
|||||||
window.onNuxtReady = function (cb) {
|
window.onNuxtReady = function (cb) {
|
||||||
window._nuxtReadyCbs.push(cb)
|
window._nuxtReadyCbs.push(cb)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// root instance
|
// root instance
|
||||||
// here we inject the router and store to all child components,
|
// here we inject the router and store to all child components,
|
||||||
// making them available everywhere as `this.$router` and `this.$store`.
|
// making them available everywhere as `this.$router` and `this.$store`.
|
||||||
const defaultTransition = <%=
|
let app = {
|
||||||
serialize(transition)
|
|
||||||
.replace('beforeEnter(', 'function(').replace('enter(', 'function(').replace('afterEnter(', 'function(')
|
|
||||||
.replace('enterCancelled(', 'function(').replace('beforeLeave(', 'function(').replace('leave(', 'function(')
|
|
||||||
.replace('afterLeave(', 'function(').replace('leaveCancelled(', 'function(')
|
|
||||||
%>
|
|
||||||
let app = {
|
|
||||||
router,
|
router,
|
||||||
<%= (store ? 'store,' : '') %>
|
<%= (store ? 'store,' : '') %>
|
||||||
|
ssrContext,
|
||||||
_nuxt: {
|
_nuxt: {
|
||||||
defaultTransition: defaultTransition,
|
defaultTransition: defaultTransition,
|
||||||
transitions: [ defaultTransition ],
|
transitions: [ defaultTransition ],
|
||||||
@ -85,26 +93,27 @@ let app = {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
...App
|
...App
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Includes & Inject external plugins
|
// Includes & Inject external plugins
|
||||||
<% plugins.forEach(function (plugin) {
|
<% plugins.forEach(function (plugin) {
|
||||||
if (plugin.ssr) { %>
|
if (plugin.ssr) { %>
|
||||||
<%= (plugin.injectAs ? 'let ' + plugin.injectAs + ' = ' : '') %>require('<%= plugin.src %>')
|
<%= (plugin.injectAs ? 'let ' + plugin.injectAs + ' = ' : '') %>require('<%= plugin.src %>')
|
||||||
<% if (plugin.injectAs) { %>
|
<% if (plugin.injectAs) { %>
|
||||||
<%= plugin.injectAs + ' = ' + plugin.injectAs + '.default || ' + plugin.injectAs %>
|
<%= plugin.injectAs + ' = ' + plugin.injectAs + '.default || ' + plugin.injectAs %>
|
||||||
app['<%= plugin.injectAs %>'] = <%= plugin.injectAs %>
|
app['<%= plugin.injectAs %>'] = <%= plugin.injectAs %>
|
||||||
<% }
|
<% }
|
||||||
} else { %>
|
} else { %>
|
||||||
if (process.browser) {
|
if (process.browser) {
|
||||||
<%= (plugin.injectAs ? 'let ' + plugin.injectAs + ' = ' : '') %>require('<%= plugin.src %>')
|
<%= (plugin.injectAs ? 'let ' + plugin.injectAs + ' = ' : '') %>require('<%= plugin.src %>')
|
||||||
<% if (plugin.injectAs) { %>
|
<% if (plugin.injectAs) { %>
|
||||||
<%= plugin.injectAs + ' = ' + plugin.injectAs + '.default || ' + plugin.injectAs %>
|
<%= plugin.injectAs + ' = ' + plugin.injectAs + '.default || ' + plugin.injectAs %>
|
||||||
app['<%= plugin.injectAs %>'] = <%= plugin.injectAs %>
|
app['<%= plugin.injectAs %>'] = <%= plugin.injectAs %>
|
||||||
<% } %>
|
<% } %>
|
||||||
}
|
}
|
||||||
<% }
|
<% }
|
||||||
}) %>
|
}) %>
|
||||||
|
|
||||||
export { app, router<%= (store ? ', store' : '') %>, NuxtError }
|
return { app, router<%= (store ? ', store' : '') %> }
|
||||||
|
}
|
||||||
|
@ -53,12 +53,14 @@ const scrollBehavior = (to, from, savedPosition) => {
|
|||||||
}
|
}
|
||||||
<% } %>
|
<% } %>
|
||||||
|
|
||||||
export default new Router({
|
export function createRouter () {
|
||||||
|
return new Router({
|
||||||
mode: '<%= router.mode %>',
|
mode: '<%= router.mode %>',
|
||||||
base: '<%= router.base %>',
|
base: '<%= router.base %>',
|
||||||
linkActiveClass: '<%= router.linkActiveClass %>',
|
linkActiveClass: '<%= router.linkActiveClass %>',
|
||||||
scrollBehavior,
|
scrollBehavior,
|
||||||
routes: [
|
routes: [
|
||||||
<%= _routes %>
|
<%= _routes %>
|
||||||
]
|
]
|
||||||
})
|
})
|
||||||
|
}
|
||||||
|
@ -7,11 +7,10 @@ import Vue from 'vue'
|
|||||||
import { stringify } from 'querystring'
|
import { stringify } from 'querystring'
|
||||||
import { omit } from 'lodash'
|
import { omit } from 'lodash'
|
||||||
import middleware from './middleware'
|
import middleware from './middleware'
|
||||||
import { app, router<%= (store ? ', store' : '') %>, NuxtError } from './index'
|
import { createApp, NuxtError } from './index'
|
||||||
import { applyAsyncData, getMatchedComponents, getContext, promiseSeries, promisify, urlJoin } from './utils'
|
import { applyAsyncData, getMatchedComponents, getContext, promiseSeries, promisify, urlJoin } from './utils'
|
||||||
|
|
||||||
const isDev = <%= isDev %>
|
const isDev = <%= isDev %>
|
||||||
const _app = new Vue(app)
|
|
||||||
|
|
||||||
// This exported function will be called by `bundleRenderer`.
|
// This exported function will be called by `bundleRenderer`.
|
||||||
// This is where we perform data-prefetching to determine the
|
// This is where we perform data-prefetching to determine the
|
||||||
@ -19,6 +18,8 @@ const _app = new Vue(app)
|
|||||||
// Since data fetching is async, this function is expected to
|
// Since data fetching is async, this function is expected to
|
||||||
// return a Promise that resolves to the app instance.
|
// return a Promise that resolves to the app instance.
|
||||||
export default context => {
|
export default context => {
|
||||||
|
const { app, router<%= (store ? ', store' : '') %> } = createApp(context)
|
||||||
|
const _app = new Vue(app)
|
||||||
// Add store to the context
|
// Add store to the context
|
||||||
<%= (store ? 'context.store = store' : '') %>
|
<%= (store ? 'context.store = store' : '') %>
|
||||||
// Nuxt object
|
// Nuxt object
|
||||||
|
@ -30,8 +30,11 @@ let storeData = {}
|
|||||||
if (filenames.indexOf('./index.js') !== -1) {
|
if (filenames.indexOf('./index.js') !== -1) {
|
||||||
let mainModule = getModule('./index.js')
|
let mainModule = getModule('./index.js')
|
||||||
if (mainModule.commit) {
|
if (mainModule.commit) {
|
||||||
store = mainModule
|
console.error('[nuxt.js] store/index.js should export raw store options instead of an instance.')
|
||||||
} else {
|
} else {
|
||||||
|
if (mainModule.state && typeof mainModule.state !== 'function') {
|
||||||
|
console.error('[nuxt.js] store state should be a function.')
|
||||||
|
}
|
||||||
storeData = mainModule
|
storeData = mainModule
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -49,8 +52,13 @@ if (store == null) {
|
|||||||
name = namePath.pop()
|
name = namePath.pop()
|
||||||
module[name] = getModule(filename)
|
module[name] = getModule(filename)
|
||||||
module[name].namespaced = true
|
module[name].namespaced = true
|
||||||
|
|
||||||
|
if (typeof module[name].state !== 'function') {
|
||||||
|
console.error('[nuxt.js] store module state should be a function.')
|
||||||
|
}
|
||||||
}
|
}
|
||||||
store = new Vuex.Store(storeData)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default store
|
export function createStore () {
|
||||||
|
return new Vuex.Store(storeData)
|
||||||
|
}
|
||||||
|
@ -464,7 +464,8 @@ function createRenderer (bundle) {
|
|||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
this.renderer = createBundleRenderer(bundle, {
|
this.renderer = createBundleRenderer(bundle, {
|
||||||
cache: cacheConfig
|
cache: cacheConfig,
|
||||||
|
runInNewContext: false
|
||||||
})
|
})
|
||||||
this.renderToString = pify(this.renderer.renderToString)
|
this.renderToString = pify(this.renderer.renderToString)
|
||||||
this.renderToStream = this.renderer.renderToStream
|
this.renderToStream = this.renderer.renderToStream
|
||||||
|
Loading…
Reference in New Issue
Block a user