From 3a1f0b0d35af305c2ca3a030b05725fa383ad140 Mon Sep 17 00:00:00 2001 From: sdras Date: Sat, 2 Dec 2017 07:03:55 -0800 Subject: [PATCH] remove .nuxt folder --- .nuxt/App.vue | 90 ----- .nuxt/client.js | 580 ------------------------------ .nuxt/components/no-ssr.js | 28 -- .nuxt/components/nuxt-child.js | 72 ---- .nuxt/components/nuxt-error.vue | 112 ------ .nuxt/components/nuxt-link.js | 9 - .nuxt/components/nuxt-loading.vue | 103 ------ .nuxt/components/nuxt.vue | 32 -- .nuxt/empty.js | 1 - .nuxt/index.js | 157 -------- .nuxt/loading.html | 49 --- .nuxt/middleware.js | 1 - .nuxt/router.js | 74 ---- .nuxt/server.js | 228 ------------ .nuxt/store.js | 77 ---- .nuxt/utils.js | 395 -------------------- .nuxt/views/app.template.html | 9 - .nuxt/views/error.html | 23 -- 18 files changed, 2040 deletions(-) delete mode 100644 .nuxt/App.vue delete mode 100644 .nuxt/client.js delete mode 100644 .nuxt/components/no-ssr.js delete mode 100644 .nuxt/components/nuxt-child.js delete mode 100644 .nuxt/components/nuxt-error.vue delete mode 100644 .nuxt/components/nuxt-link.js delete mode 100644 .nuxt/components/nuxt-loading.vue delete mode 100644 .nuxt/components/nuxt.vue delete mode 100644 .nuxt/empty.js delete mode 100644 .nuxt/index.js delete mode 100644 .nuxt/loading.html delete mode 100644 .nuxt/middleware.js delete mode 100644 .nuxt/router.js delete mode 100644 .nuxt/server.js delete mode 100644 .nuxt/store.js delete mode 100644 .nuxt/utils.js delete mode 100644 .nuxt/views/app.template.html delete mode 100644 .nuxt/views/error.html diff --git a/.nuxt/App.vue b/.nuxt/App.vue deleted file mode 100644 index dcdf4b9..0000000 --- a/.nuxt/App.vue +++ /dev/null @@ -1,90 +0,0 @@ - - - - diff --git a/.nuxt/client.js b/.nuxt/client.js deleted file mode 100644 index e8b7cbc..0000000 --- a/.nuxt/client.js +++ /dev/null @@ -1,580 +0,0 @@ -import Vue from 'vue' -import middleware from './middleware' -import { createApp, NuxtError } from './index' -import { - applyAsyncData, - sanitizeComponent, - getMatchedComponents, - getMatchedComponentsInstances, - flatMapComponents, - getContext, - middlewareSeries, - promisify, - getLocation, - compile -} from './utils' - -const noopData = () => { return {} } -const noopFetch = () => {} - -// Global shared references -let _lastPaths = [] -let _lastComponentsFiles = [] -let app -let router -let store - -// Try to rehydrate SSR data from window -const NUXT = window.__NUXT__ || {} -NUXT.components = window.__COMPONENTS__ || null - - -// Setup global Vue error handler -const defaultErrorHandler = Vue.config.errorHandler -Vue.config.errorHandler = function (err, vm, info) { - err.statusCode = err.statusCode || err.name || 'Whoops!' - err.message = err.message || err.toString() - - // Show Nuxt Error Page - if(vm && vm.$root && vm.$root.$nuxt && vm.$root.$nuxt.error && info !== 'render function') { - vm.$root.$nuxt.error(err) - } - - // Call other handler if exist - if (typeof defaultErrorHandler === 'function') { - return defaultErrorHandler(...arguments) - } - - // Log to console - if (process.env.NODE_ENV !== 'production') { - console.error(err) - } else { - console.error(err.message) - } -} - - -// Create and mount App -createApp() -.then(mountApp) -.catch(err => { - console.error('[nuxt] Error while initializing app', err) -}) - -function componentOption(component, key, ...args) { - if (!component || !component.options || !component.options[key]) { - return {} - } - const option = component.options[key] - if (typeof option === 'function') { - return option(...args) - } - return option -} - -function mapTransitions(Components, to, from) { - const componentTransitions = component => { - const transition = componentOption(component, 'transition', to, from) || {} - return (typeof transition === 'string' ? { name: transition } : transition) - } - - return Components.map(Component => { - // Clone original object to prevent overrides - const transitions = Object.assign({}, componentTransitions(Component)) - - // Combine transitions & prefer `leave` transitions of 'from' route - if (from && from.matched.length && from.matched[0].components.default) { - const from_transitions = componentTransitions(from.matched[0].components.default) - Object.keys(from_transitions) - .filter(key => from_transitions[key] && key.toLowerCase().indexOf('leave') !== -1) - .forEach(key => { transitions[key] = from_transitions[key] }) - } - - return transitions - }) -} - -async function loadAsyncComponents (to, from, next) { - // Check if route hash changed - const fromPath = from.fullPath.split('#')[0] - const toPath = to.fullPath.split('#')[0] - this._hashChanged = fromPath === toPath - - - if (!this._hashChanged && this.$loading.start) { - this.$loading.start() - } - - - try { - await Promise.all(flatMapComponents(to, (Component, _, match, key) => { - // If component already resolved - if (typeof Component !== 'function' || Component.options) { - const _Component = sanitizeComponent(Component) - match.components[key] = _Component - return _Component - } - - // Resolve component - return Component().then(Component => { - const _Component = sanitizeComponent(Component) - match.components[key] = _Component - return _Component - }) - })) - - next() - } catch (err) { - if (!err) err = {} - const statusCode = err.statusCode || err.status || (err.response && err.response.status) || 500 - this.error({ statusCode, message: err.message }) - next(false) - } -} - -// Get matched components -function resolveComponents(router) { - const path = getLocation(router.options.base, router.options.mode) - - return flatMapComponents(router.match(path), (Component, _, match, key, index) => { - // If component already resolved - if (typeof Component !== 'function' || Component.options) { - const _Component = sanitizeComponent(Component) - match.components[key] = _Component - return _Component - } - - // Resolve component - return Component().then(Component => { - const _Component = sanitizeComponent(Component) - if (NUXT.serverRendered) { - applyAsyncData(_Component, NUXT.data[index]) - if (NUXT.components) { - Component.options.components = Object.assign(_Component.options.components, NUXT.components[index]) - } - _Component._Ctor = _Component - } - match.components[key] = _Component - return _Component - }) - }) -} - -function callMiddleware (Components, context, layout) { - let midd = [] - let unknownMiddleware = false - - // If layout is undefined, only call global middleware - if (typeof layout !== 'undefined') { - midd = [] // Exclude global middleware if layout defined (already called before) - if (layout.middleware) { - midd = midd.concat(layout.middleware) - } - Components.forEach(Component => { - if (Component.options.middleware) { - midd = midd.concat(Component.options.middleware) - } - }) - } - - midd = midd.map(name => { - if (typeof middleware[name] !== 'function') { - unknownMiddleware = true - this.error({ statusCode: 500, message: 'Unknown middleware ' + name }) - } - return middleware[name] - }) - - if (unknownMiddleware) return - return middlewareSeries(midd, context) -} - -async function render (to, from, next) { - if (this._hashChanged) return next() - - // nextCalled is true when redirected - let nextCalled = false - const _next = path => { - if(this.$loading.finish) this.$loading.finish() - if (nextCalled) return - nextCalled = true - next(path) - } - - // Update context - const context = getContext({ - to, - from, - store, - isClient: true, - next: _next.bind(this), - error: this.error.bind(this) - }, app) - this._context = context - this._dateLastError = this.$options._nuxt.dateErr - this._hadError = !!this.$options._nuxt.err - - // Get route's matched components - const Components = getMatchedComponents(to) - - // If no Components matched, generate 404 - if (!Components.length) { - // Default layout - await callMiddleware.call(this, Components, context) - if (context._redirected) return - - // Load layout for error page - const layout = await this.loadLayout(typeof NuxtError.layout === 'function' ? NuxtError.layout(context) : NuxtError.layout) - await callMiddleware.call(this, Components, context, layout) - if (context._redirected) return - - this.error({ statusCode: 404, message: 'This page could not be found' }) - return next() - } - - // Update ._data and other properties if hot reloaded - Components.forEach(Component => { - if (Component._Ctor && Component._Ctor.options) { - Component.options.asyncData = Component._Ctor.options.asyncData - Component.options.fetch = Component._Ctor.options.fetch - } - }) - - // Apply transitions - this.setTransitions(mapTransitions(Components, to, from)) - - try { - // Call middleware - await callMiddleware.call(this, Components, context) - if (context._redirected) return - - // Set layout - let layout = Components[0].options.layout - if (typeof layout === 'function') { - layout = layout(context) - } - layout = await this.loadLayout(layout) - - // Call middleware for layout - await callMiddleware.call(this, Components, context, layout) - if (context._redirected) return - - // Call .validate() - let isValid = true - Components.forEach(Component => { - if (!isValid) return - if (typeof Component.options.validate !== 'function') return - isValid = Component.options.validate({ - params: to.params || {}, - query : to.query || {}, - store: context.store - }) - }) - // ...If .validate() returned false - if (!isValid) { - this.error({ statusCode: 404, message: 'This page could not be found' }) - return next() - } - - // Call asyncData & fetch hooks on components matched by the route. - await Promise.all(Components.map((Component, i) => { - // Check if only children route changed - Component._path = compile(to.matched[i].path)(to.params) - if (!this._hadError && this._isMounted && Component._path === _lastPaths[i] && (i + 1) !== Components.length) { - return Promise.resolve() - } - - let promises = [] - - const hasAsyncData = Component.options.asyncData && typeof Component.options.asyncData === 'function' - const hasFetch = !!Component.options.fetch - const loadingIncrease = (hasAsyncData && hasFetch) ? 30 : 45 - - // Call asyncData(context) - if (hasAsyncData) { - const promise = promisify(Component.options.asyncData, context) - .then(asyncDataResult => { - applyAsyncData(Component, asyncDataResult) - if(this.$loading.increase) this.$loading.increase(loadingIncrease) - }) - promises.push(promise) - } - - // Call fetch(context) - if (hasFetch) { - let p = Component.options.fetch(context) - if (!p || (!(p instanceof Promise) && (typeof p.then !== 'function'))) { - p = Promise.resolve(p) - } - p.then(fetchResult => { - if(this.$loading.increase) this.$loading.increase(loadingIncrease) - }) - promises.push(p) - } - - return Promise.all(promises) - })) - - _lastPaths = Components.map((Component, i) => compile(to.matched[i].path)(to.params)) - - if(this.$loading.finish) this.$loading.finish() - - // If not redirected - if (!nextCalled) next() - - } catch (error) { - if (!error) error = {} - _lastPaths = [] - error.statusCode = error.statusCode || error.status || (error.response && error.response.status) || 500 - - // Load error layout - let layout = NuxtError.layout - if (typeof layout === 'function') { - layout = layout(context) - } - await this.loadLayout(layout) - - this.error(error) - next(false) - } -} - -// Fix components format in matched, it's due to code-splitting of vue-router -function normalizeComponents (to, ___) { - flatMapComponents(to, (Component, _, match, key) => { - if (typeof Component === 'object' && !Component.options) { - // Updated via vue-router resolveAsyncComponents() - Component = Vue.extend(Component) - Component._Ctor = Component - match.components[key] = Component - } - return Component - }) -} - -// When navigating on a different route but the same component is used, Vue.js -// Will not update the instance data, so we have to update $data ourselves -function fixPrepatch (to, ___) { - if (this._hashChanged) return - - Vue.nextTick(() => { - const instances = getMatchedComponentsInstances(to) - - _lastComponentsFiles = instances.map((instance, i) => { - if (!instance) return ''; - - if (_lastPaths[i] === instance.constructor._path && typeof instance.constructor.options.data === 'function') { - const newData = instance.constructor.options.data.call(instance) - for (let key in newData) { - Vue.set(instance.$data, key, newData[key]) - } - } - - return instance.constructor.options.__file - }) - - // Hide error component if no error - if (this._hadError && this._dateLastError === this.$options._nuxt.dateErr) { - this.error() - } - - // Set layout - let layout = this.$options._nuxt.err ? NuxtError.layout : to.matched[0].components.default.options.layout - if (typeof layout === 'function') { - layout = layout(this._context) - } - this.setLayout(layout) - - - // Hot reloading - setTimeout(() => hotReloadAPI(this), 100) - - }) -} - -function nuxtReady (app) { - window._nuxtReadyCbs.forEach((cb) => { - if (typeof cb === 'function') { - cb(app) - } - }) - // Special JSDOM - if (typeof window._onNuxtLoaded === 'function') { - window._onNuxtLoaded(app) - } - // Add router hooks - router.afterEach(function (to, from) { - app.$nuxt.$emit('routeChanged', to, from) - }) -} - - -// Special hot reload with asyncData(context) -function hotReloadAPI (_app) { - if (!module.hot) return - - let $components = [] - let $nuxt = _app.$nuxt - - while ($nuxt && $nuxt.$children && $nuxt.$children.length) { - $nuxt.$children.forEach((child, i) => { - if (child.$vnode.data.nuxtChild) { - let hasAlready = false - $components.forEach(component => { - if (component.$options.__file === child.$options.__file) { - hasAlready = true - } - }) - if (!hasAlready) { - $components.push(child) - } - } - $nuxt = child - }) - } - - $components.forEach(addHotReload.bind(_app)) -} - -function addHotReload ($component, depth) { - if ($component.$vnode.data._hasHotReload) return - $component.$vnode.data._hasHotReload = true - - var _forceUpdate = $component.$forceUpdate.bind($component.$parent) - - $component.$vnode.context.$forceUpdate = () => { - let Components = getMatchedComponents(router.currentRoute) - let Component = Components[depth] - if (!Component) return _forceUpdate() - if (typeof Component === 'object' && !Component.options) { - // Updated via vue-router resolveAsyncComponents() - Component = Vue.extend(Component) - Component._Ctor = Component - } - this.error() - let promises = [] - const next = function (path) { - this.$loading.finish && this.$loading.finish() - router.push(path) - } - let context = getContext({ route: router.currentRoute, store, isClient: true, isHMR: true, next: next.bind(this), error: this.error }, app) - this.$loading.start && this.$loading.start() - callMiddleware.call(this, Components, context) - .then(() => { - // If layout changed - if (depth !== 0) return Promise.resolve() - let layout = Component.options.layout || 'default' - if (typeof layout === 'function') { - layout = layout(context) - } - if (this.layoutName === layout) return Promise.resolve() - let promise = this.loadLayout(layout) - promise.then(() => { - this.setLayout(layout) - Vue.nextTick(() => hotReloadAPI(this)) - }) - return promise - }) - .then(() => { - return callMiddleware.call(this, Components, context, this.layout) - }) - .then(() => { - // Call asyncData(context) - let pAsyncData = promisify(Component.options.asyncData || noopData, context) - pAsyncData.then((asyncDataResult) => { - applyAsyncData(Component, asyncDataResult) - this.$loading.increase && this.$loading.increase(30) - }) - promises.push(pAsyncData) - // Call fetch() - Component.options.fetch = Component.options.fetch || noopFetch - let pFetch = Component.options.fetch(context) - if (!pFetch || (!(pFetch instanceof Promise) && (typeof pFetch.then !== 'function'))) { pFetch = Promise.resolve(pFetch) } - pFetch.then(() => this.$loading.increase && this.$loading.increase(30)) - promises.push(pFetch) - return Promise.all(promises) - }) - .then(() => { - this.$loading.finish && this.$loading.finish() - _forceUpdate() - setTimeout(() => hotReloadAPI(this), 100) - }) - } -} - - -async function mountApp(__app) { - // Set global variables - app = __app.app - router = __app.router - store = __app.store - - // Resolve route components - const Components = await Promise.all(resolveComponents(router)) - - // Create Vue instance - const _app = new Vue(app) - - // Load layout - const layout = NUXT.layout || 'default' - await _app.loadLayout(layout) - _app.setLayout(layout) - - // Mounts Vue app to DOM element - const mountApp = () => { - _app.$mount('#__nuxt') - - // Listen for first Vue update - Vue.nextTick(() => { - // Call window.onNuxtReady callbacks - nuxtReady(_app) - - // Enable hot reloading - hotReloadAPI(_app) - - }) - } - - // Enable transitions - _app.setTransitions = _app.$options._nuxt.setTransitions.bind(_app) - if (Components.length) { - _app.setTransitions(mapTransitions(Components, router.currentRoute)) - _lastPaths = router.currentRoute.matched.map(route => compile(route.path)(router.currentRoute.params)) - _lastComponentsFiles = Components.map(Component => Component.options.__file) - } - - // Initialize error handler - _app.error = _app.$options._nuxt.error.bind(_app) - _app.$loading = {} // To avoid error while _app.$nuxt does not exist - if (NUXT.error) _app.error(NUXT.error) - - // Add router hooks - router.beforeEach(loadAsyncComponents.bind(_app)) - router.beforeEach(render.bind(_app)) - router.afterEach(normalizeComponents) - router.afterEach(fixPrepatch.bind(_app)) - - // If page already is server rendered - if (NUXT.serverRendered) { - mountApp() - return - } - - render.call(_app, router.currentRoute, router.currentRoute, path => { - if (!path) { - normalizeComponents(router.currentRoute, router.currentRoute) - fixPrepatch.call(_app, router.currentRoute, router.currentRoute) - mountApp() - return - } - - // Push the path and then mount app - let mounted = false - router.afterEach(() => { - if (mounted) return - mounted = true - mountApp() - }) - router.push(path) - }) -} diff --git a/.nuxt/components/no-ssr.js b/.nuxt/components/no-ssr.js deleted file mode 100644 index 9dbc5bc..0000000 --- a/.nuxt/components/no-ssr.js +++ /dev/null @@ -1,28 +0,0 @@ -/* -** From https://github.com/egoist/vue-no-ssr -** With the authorization of @egoist -*/ -export default { - name: 'no-ssr', - props: ['placeholder'], - data () { - return { - canRender: false - } - }, - mounted () { - this.canRender = true - }, - render (h) { - if (this.canRender) { - if ( - process.env.NODE_ENV === 'development' && - this.$slots.default.length > 1 - ) { - throw new Error(' You cannot use multiple child components') - } - return this.$slots.default[0] - } - return h('div', { class: { 'no-ssr-placeholder': true } }, this.placeholder) - } -} diff --git a/.nuxt/components/nuxt-child.js b/.nuxt/components/nuxt-child.js deleted file mode 100644 index 39b8e3c..0000000 --- a/.nuxt/components/nuxt-child.js +++ /dev/null @@ -1,72 +0,0 @@ -import Vue from 'vue' - -const transitionsKeys = [ - 'name', - 'mode', - 'appear', - 'css', - 'type', - 'duration', - 'enterClass', - 'leaveClass', - 'appearClass', - 'enterActiveClass', - 'enterActiveClass', - 'leaveActiveClass', - 'appearActiveClass', - 'enterToClass', - 'leaveToClass', - 'appearToClass' -] -const listenersKeys = [ - 'beforeEnter', - 'enter', - 'afterEnter', - 'enterCancelled', - 'beforeLeave', - 'leave', - 'afterLeave', - 'leaveCancelled', - 'beforeAppear', - 'appear', - 'afterAppear', - 'appearCancelled' -] - -export default { - name: 'nuxt-child', - functional: true, - render (h, { parent, data }) { - data.nuxtChild = true - const _parent = parent - const transitions = parent.$nuxt.nuxt.transitions - const defaultTransition = parent.$nuxt.nuxt.defaultTransition - let depth = 0 - while (parent) { - if (parent.$vnode && parent.$vnode.data.nuxtChild) { - depth++ - } - parent = parent.$parent - } - data.nuxtChildDepth = depth - const transition = transitions[depth] || defaultTransition - let transitionProps = {} - transitionsKeys.forEach((key) => { - if (typeof transition[key] !== 'undefined') { - transitionProps[key] = transition[key] - } - }) - let listeners = {} - listenersKeys.forEach((key) => { - if (typeof transition[key] === 'function') { - listeners[key] = transition[key].bind(_parent) - } - }) - return h('transition', { - props: transitionProps, - on: listeners - }, [ - h('router-view', data) - ]) - } -} diff --git a/.nuxt/components/nuxt-error.vue b/.nuxt/components/nuxt-error.vue deleted file mode 100644 index 6384af3..0000000 --- a/.nuxt/components/nuxt-error.vue +++ /dev/null @@ -1,112 +0,0 @@ - - - - - diff --git a/.nuxt/components/nuxt-link.js b/.nuxt/components/nuxt-link.js deleted file mode 100644 index c23fdd7..0000000 --- a/.nuxt/components/nuxt-link.js +++ /dev/null @@ -1,9 +0,0 @@ -import Vue from 'vue' - -export default { - name: 'nuxt-link', - functional: true, - render (h, { data, children }) { - return h('router-link', data, children) - } -} diff --git a/.nuxt/components/nuxt-loading.vue b/.nuxt/components/nuxt-loading.vue deleted file mode 100644 index b0adb7b..0000000 --- a/.nuxt/components/nuxt-loading.vue +++ /dev/null @@ -1,103 +0,0 @@ - - - - - diff --git a/.nuxt/components/nuxt.vue b/.nuxt/components/nuxt.vue deleted file mode 100644 index 2053e9a..0000000 --- a/.nuxt/components/nuxt.vue +++ /dev/null @@ -1,32 +0,0 @@ - - - diff --git a/.nuxt/empty.js b/.nuxt/empty.js deleted file mode 100644 index a3ac0d8..0000000 --- a/.nuxt/empty.js +++ /dev/null @@ -1 +0,0 @@ -// This file is intentionally left empty for noop aliases diff --git a/.nuxt/index.js b/.nuxt/index.js deleted file mode 100644 index 2934e2f..0000000 --- a/.nuxt/index.js +++ /dev/null @@ -1,157 +0,0 @@ -import 'es6-promise/auto' -import Vue from 'vue' -import Meta from 'vue-meta' -import { createRouter } from './router.js' -import NoSSR from './components/no-ssr.js' -import NuxtChild from './components/nuxt-child.js' -import NuxtLink from './components/nuxt-link.js' -import NuxtError from './components/nuxt-error.vue' -import Nuxt from './components/nuxt.vue' -import App from './App.vue' -import { getContext, getLocation } from './utils' -import { createStore } from './store.js' - - -// Component: -Vue.component(NoSSR.name, NoSSR) - -// Component: -Vue.component(NuxtChild.name, NuxtChild) - -// Component: -Vue.component(NuxtLink.name, NuxtLink) - -// Component: ` -Vue.component(Nuxt.name, Nuxt) - -// vue-meta configuration -Vue.use(Meta, { - keyName: 'head', // the component option name that vue-meta looks for meta info on. - attribute: 'data-n-head', // the attribute name vue-meta adds to the tags it observes - ssrAttribute: 'data-n-head-ssr', // the attribute name that lets vue-meta know that meta info has already been server-rendered - tagIDKeyName: 'hid' // the property name that vue-meta uses to determine whether to overwrite or append a tag -}) - -const defaultTransition = {"name":"page","mode":"out-in","appear":false,"appearClass":"appear","appearActiveClass":"appear-active","appearToClass":"appear-to"} - -async function createApp (ssrContext) { - const router = createRouter() - - const store = createStore() - - // Create Root instance - // here we inject the router and store to all child components, - // making them available everywhere as `this.$router` and `this.$store`. - const app = { - router, - store, - _nuxt: { - defaultTransition, - transitions: [ defaultTransition ], - setTransitions (transitions) { - if (!Array.isArray(transitions)) { - transitions = [ transitions ] - } - transitions = transitions.map((transition) => { - if (!transition) { - transition = defaultTransition - } else if (typeof transition === 'string') { - transition = Object.assign({}, defaultTransition, { name: transition }) - } else { - transition = Object.assign({}, defaultTransition, transition) - } - return transition - }) - this.$options._nuxt.transitions = transitions - return transitions - }, - err: null, - dateErr: null, - error (err) { - err = err || null - if (typeof err === 'string') { - err = { statusCode: 500, message: err } - } - const _nuxt = this._nuxt || this.$options._nuxt - _nuxt.dateErr = Date.now() - _nuxt.err = err - return err - } - }, - ...App - } - - // Make app available in store - store.app = app - - const next = ssrContext ? ssrContext.next : location => app.router.push(location) - let route - if (ssrContext) { - route = router.resolve(ssrContext.url).route - } else { - const path = getLocation(router.options.base) - route = router.resolve(path).route - } - const ctx = getContext({ - isServer: !!ssrContext, - isClient: !ssrContext, - route, - next, - error: app._nuxt.error.bind(app), - store, - req: ssrContext ? ssrContext.req : undefined, - res: ssrContext ? ssrContext.res : undefined, - beforeRenderFns: ssrContext ? ssrContext.beforeRenderFns : undefined - }, app) - - const inject = function (key, value) { - if (!key) throw new Error('inject(key, value) has no key provided') - if (!value) throw new Error('inject(key, value) has no value provided') - key = '$' + key - // Add into app - app[key] = value - // Add into vm - Vue.use(() => { - const installKey = '__nuxt_' + key + '_installed__' - if (Vue[installKey]) return - Vue[installKey] = true - if (!Vue.prototype.hasOwnProperty(key)) { - Object.defineProperty(Vue.prototype, key, { - get () { - return this.$root.$options[key] - } - }) - } - }) - - // Add into store - store[key] = app[key] - - } - - - if (process.browser) { - // Replace store state before plugins execution - if (window.__NUXT__ && window.__NUXT__.state) { - store.replaceState(window.__NUXT__.state) - } - } - - - - - - if (process.server && ssrContext && ssrContext.url) { - await new Promise((resolve, reject) => { - router.push(ssrContext.url, resolve, reject) - }) - } - - return { - app, - router, - store - } -} - -export { createApp, NuxtError } diff --git a/.nuxt/loading.html b/.nuxt/loading.html deleted file mode 100644 index adc51da..0000000 --- a/.nuxt/loading.html +++ /dev/null @@ -1,49 +0,0 @@ - - -
-
-
-
- - diff --git a/.nuxt/middleware.js b/.nuxt/middleware.js deleted file mode 100644 index b1c6ea4..0000000 --- a/.nuxt/middleware.js +++ /dev/null @@ -1 +0,0 @@ -export default {} diff --git a/.nuxt/router.js b/.nuxt/router.js deleted file mode 100644 index 0311372..0000000 --- a/.nuxt/router.js +++ /dev/null @@ -1,74 +0,0 @@ -import Vue from 'vue' -import Router from 'vue-router' - -Vue.use(Router) - -const _2fd71ff0 = () => import('../pages/index.vue' /* webpackChunkName: "pages/index" */).then(m => m.default || m) -const _473ed934 = () => import('../pages/women.vue' /* webpackChunkName: "pages/women" */).then(m => m.default || m) -const _7edf9a8c = () => import('../pages/men.vue' /* webpackChunkName: "pages/men" */).then(m => m.default || m) -const _f587b74c = () => import('../pages/cart.vue' /* webpackChunkName: "pages/cart" */).then(m => m.default || m) -const _0f8303fe = () => import('../pages/sale.vue' /* webpackChunkName: "pages/sale" */).then(m => m.default || m) - - - -const scrollBehavior = (to, from, savedPosition) => { - // SavedPosition is only available for popstate navigations. - if (savedPosition) { - return savedPosition - } else { - let position = {} - // If no children detected - if (to.matched.length < 2) { - // Scroll to the top of the page - position = { x: 0, y: 0 } - } - else if (to.matched.some((r) => r.components.default.options.scrollToTop)) { - // If one of the children has scrollToTop option set to true - position = { x: 0, y: 0 } - } - // If link has anchor, scroll to anchor by returning the selector - if (to.hash) { - position = { selector: to.hash } - } - return position - } -} - - -export function createRouter () { - return new Router({ - mode: 'history', - base: '/', - linkActiveClass: 'nuxt-link-active', - linkExactActiveClass: 'nuxt-link-exact-active', - scrollBehavior, - routes: [ - { - path: "/", - component: _2fd71ff0, - name: "index" - }, - { - path: "/women", - component: _473ed934, - name: "women" - }, - { - path: "/men", - component: _7edf9a8c, - name: "men" - }, - { - path: "/cart", - component: _f587b74c, - name: "cart" - }, - { - path: "/sale", - component: _0f8303fe, - name: "sale" - } - ], - fallback: false - }) -} diff --git a/.nuxt/server.js b/.nuxt/server.js deleted file mode 100644 index 4b33a90..0000000 --- a/.nuxt/server.js +++ /dev/null @@ -1,228 +0,0 @@ -import Vue from 'vue' -import clone from 'clone' -import { stringify } from 'querystring' -import { omit } from 'lodash' -import middleware from './middleware' -import { createApp, NuxtError } from './index' -import { applyAsyncData, sanitizeComponent, getMatchedComponents, getContext, middlewareSeries, promisify, urlJoin } from './utils' - -const debug = require('debug')('nuxt:render') -debug.color = 4 // force blue color - -const isDev = true - -const noopApp = () => new Vue({ render: (h) => h('div') }) - -const createNext = context => opts => { - context.redirected = opts - // If nuxt generate - if (!context.res) { - context.nuxt.serverRendered = false - return - } - opts.query = stringify(opts.query) - opts.path = opts.path + (opts.query ? '?' + opts.query : '') - if (opts.path.indexOf('http') !== 0 && ('/' !== '/' && opts.path.indexOf('/') !== 0)) { - opts.path = urlJoin('/', opts.path) - } - // Avoid loop redirect - if (opts.path === context.url) { - context.redirected = false - return - } - context.res.writeHead(opts.status, { - 'Location': opts.path - }) - context.res.end() -} - -// This exported function will be called by `bundleRenderer`. -// This is where we perform data-prefetching to determine the -// state of our application before actually rendering it. -// Since data fetching is async, this function is expected to -// return a Promise that resolves to the app instance. -export default async context => { - // Create context.next for simulate next() of beforeEach() when wanted to redirect - context.redirected = false - context.next = createNext(context) - context.beforeRenderFns = [] - - const { app, router, store } = await createApp(context) - const _app = new Vue(app) - - - // Add store to the context - context.store = store - - - // Add route to the context - context.route = router.currentRoute - - // Nuxt object - context.nuxt = { layout: 'default', data: [], error: null, state: null, serverRendered: true } - - // Add meta infos - context.meta = _app.$meta() - - // Error function - context.error = _app.$options._nuxt.error.bind(_app) - - // Keep asyncData for each matched component in context - context.asyncData = {} - - // Create shared ctx - const ctx = getContext(context, app) - - const s = isDev && Date.now() - - // Resolve components - let Components = [] - try { - Components = await Promise.all(getMatchedComponents(router.match(context.url)).map(Component => { - if (typeof Component !== 'function' || Component.cid) { - return sanitizeComponent(Component) - } - return Component().then(Component => sanitizeComponent(Component)) - })) - } catch (err) { - // Throw back error to renderRoute() - throw err - } - - - // Dispatch store nuxtServerInit - if (store._actions && store._actions.nuxtServerInit) { - await store.dispatch('nuxtServerInit', ctx) - } - // ...If there is a redirect - if (context.redirected) return noopApp() - - - // Call global middleware (nuxt.config.js) - let midd = [] - midd = midd.map((name) => { - if (typeof middleware[name] !== 'function') { - context.nuxt.error = context.error({ statusCode: 500, message: 'Unknown middleware ' + name }) - } - return middleware[name] - }) - if (!context.nuxt.error) { - await middlewareSeries(midd, ctx) - } - // ...If there is a redirect - if (context.redirected) return noopApp() - - // Set layout - let layout = Components.length ? Components[0].options.layout : NuxtError.layout - if (typeof layout === 'function') layout = layout(ctx) - await _app.loadLayout(layout) - layout = _app.setLayout(layout) - // ...Set layout to __NUXT__ - context.nuxt.layout = _app.layoutName - - // Call middleware (layout + pages) - if (!context.nuxt.error) { - midd = [] - if (layout.middleware) midd = midd.concat(layout.middleware) - Components.forEach((Component) => { - if (Component.options.middleware) { - midd = midd.concat(Component.options.middleware) - } - }) - midd = midd.map((name) => { - if (typeof middleware[name] !== 'function') { - context.nuxt.error = context.error({ statusCode: 500, message: 'Unknown middleware ' + name }) - } - return middleware[name] - }) - - await middlewareSeries(midd, ctx) - - // If there is a redirect - if (context.redirected) return noopApp() - } - - // Call .validate() - let isValid = true - Components.forEach((Component) => { - if (!isValid) return - if (typeof Component.options.validate !== 'function') return - isValid = Component.options.validate({ - params: context.route.params || {}, - query: context.route.query || {}, - store: ctx.store - }) - }) - // ...If .validate() returned false - if (!isValid) { - // Don't server-render the page in generate mode - if (context._generate) { - context.nuxt.serverRendered = false - } - // Call the 404 error by making the Components array empty - Components = [] - } - - // Call asyncData & fetch hooks on components matched by the route. - let asyncDatas = await Promise.all(Components.map(Component => { - let promises = [] - - // Call asyncData(context) - if (Component.options.asyncData && typeof Component.options.asyncData === 'function') { - let promise = promisify(Component.options.asyncData, ctx) - promise.then(asyncDataResult => { - context.asyncData[Component.cid] = asyncDataResult - applyAsyncData(Component) - return asyncDataResult - }) - promises.push(promise) - } else { - promises.push(null) - } - - // Call fetch(context) - if (Component.options.fetch) { - promises.push(Component.options.fetch(ctx)) - } - else { - promises.push(null) - } - - return Promise.all(promises) - })) - - // If no Components found, returns 404 - if (!Components.length) { - context.nuxt.error = context.error({ statusCode: 404, message: 'This page could not be found' }) - } - - if (asyncDatas.length) debug('Data fetching ' + context.url + ': ' + (Date.now() - s) + 'ms') - - // datas are the first row of each - context.nuxt.data = asyncDatas.map(r => r[0] || {}) - - // If an error occured in the execution - if (_app.$options._nuxt.err) { - context.nuxt.error = _app.$options._nuxt.err - } - - - // Add the state from the vuex store - context.nuxt.state = store.state - - - await Promise.all(context.beforeRenderFns.map((fn) => promisify(fn, { Components, nuxtState: context.nuxt }))) - - // If no error, return main app - if (!context.nuxt.error) { - return _app - } - - // Load layout for error page - layout = (typeof NuxtError.layout === 'function' ? NuxtError.layout(ctx) : NuxtError.layout) - context.nuxt.layout = layout || '' - await _app.loadLayout(layout) - _app.setLayout(layout) - - return _app -} diff --git a/.nuxt/store.js b/.nuxt/store.js deleted file mode 100644 index d1e59ef..0000000 --- a/.nuxt/store.js +++ /dev/null @@ -1,77 +0,0 @@ -import Vue from 'vue' -import Vuex from 'vuex' - -Vue.use(Vuex) - -// Recursive find files in {srcDir}/store -const files = require.context('@/store', true, /^\.\/.*\.(js|ts)$/) -const filenames = files.keys() - -// Store -let storeData = {} - -// Check if store/index.js exists -let indexFilename -filenames.forEach((filename) => { - if (filename.indexOf('./index.') !== -1) { - indexFilename = filename - } -}) -if (indexFilename) { - storeData = getModule(indexFilename) -} - -// If store is not an exported method = modules store -if (typeof storeData !== 'function') { - - // Store modules - if (!storeData.modules) { - storeData.modules = {} - } - - for (let filename of filenames) { - let name = filename.replace(/^\.\//, '').replace(/\.(js|ts)$/, '') - if (name === 'index') continue - - let namePath = name.split(/\//) - let module = getModuleNamespace(storeData, namePath) - - name = namePath.pop() - module[name] = getModule(filename) - module[name].namespaced = true - } - -} - -// createStore -export const createStore = storeData instanceof Function ? storeData : () => { - return new Vuex.Store(Object.assign({ - strict: (process.env.NODE_ENV !== 'production'), - }, storeData, { - state: storeData.state instanceof Function ? storeData.state() : {} - })) -} - -// Dynamically require module -function getModule (filename) { - const file = files(filename) - const module = file.default || file - if (module.commit) { - throw new Error('[nuxt] store/' + filename.replace('./', '') + ' should export a method which returns a Vuex instance.') - } - if (module.state && typeof module.state !== 'function') { - throw new Error('[nuxt] state should be a function in store/' + filename.replace('./', '')) - } - return module -} - -function getModuleNamespace (storeData, namePath) { - if (namePath.length === 1) { - return storeData.modules - } - let namespace = namePath.shift() - storeData.modules[namespace] = storeData.modules[namespace] || {} - storeData.modules[namespace].namespaced = true - storeData.modules[namespace].modules = storeData.modules[namespace].modules || {} - return getModuleNamespace(storeData.modules[namespace], namePath) -} diff --git a/.nuxt/utils.js b/.nuxt/utils.js deleted file mode 100644 index db0f5f5..0000000 --- a/.nuxt/utils.js +++ /dev/null @@ -1,395 +0,0 @@ -import Vue from 'vue' - -const noopData = () => ({}) - -// window.onNuxtReady(() => console.log('Ready')) hook -// Useful for jsdom testing or plugins (https://github.com/tmpvar/jsdom#dealing-with-asynchronous-script-loading) -if (process.browser) { - window._nuxtReadyCbs = [] - window.onNuxtReady = function (cb) { - window._nuxtReadyCbs.push(cb) - } -} - -export function applyAsyncData (Component, asyncData) { - const ComponentData = Component.options.data || noopData - // Prevent calling this method for each request on SSR context - if (!asyncData && Component.options.hasAsyncData) { - return - } - Component.options.hasAsyncData = true - Component.options.data = function () { - const data = ComponentData.call(this) - if (this.$ssrContext) { - asyncData = this.$ssrContext.asyncData[Component.cid] - } - return { ...data, ...asyncData } - } - if (Component._Ctor && Component._Ctor.options) { - Component._Ctor.options.data = Component.options.data - } -} - -export function sanitizeComponent (Component) { - if (!Component.options) { - Component = Vue.extend(Component) // fix issue #6 - Component._Ctor = Component - } else { - Component._Ctor = Component - Component.extendOptions = Component.options - } - // For debugging purpose - if (!Component.options.name && Component.options.__file) { - Component.options.name = Component.options.__file - } - return Component -} - -export function getMatchedComponents (route) { - return [].concat.apply([], route.matched.map(function (m) { - return Object.keys(m.components).map(function (key) { - return m.components[key] - }) - })) -} - -export function getMatchedComponentsInstances (route) { - return [].concat.apply([], route.matched.map(function (m) { - return Object.keys(m.instances).map(function (key) { - return m.instances[key] - }) - })) -} - -export function flatMapComponents (route, fn) { - return Array.prototype.concat.apply([], route.matched.map(function (m, index) { - return Object.keys(m.components).map(function (key) { - return fn(m.components[key], m.instances[key], m, key, index) - }) - })) -} - -export function getContext (context, app) { - let ctx = { - isServer: !!context.isServer, - isClient: !!context.isClient, - isStatic: process.static, - isDev: true, - isHMR: context.isHMR || false, - app: app, - store: context.store, - route: (context.to ? context.to : context.route), - payload: context.payload, - error: context.error, - base: '/', - env: {} - } - const next = context.next - ctx.params = ctx.route.params || {} - ctx.query = ctx.route.query || {} - ctx.redirect = function (status, path, query) { - if (!status) return - ctx._redirected = true // Used in middleware - // if only 1 or 2 arguments: redirect('/') or redirect('/', { foo: 'bar' }) - if (typeof status === 'string' && (typeof path === 'undefined' || typeof path === 'object')) { - query = path || {} - path = status - status = 302 - } - next({ - path: path, - query: query, - status: status - }) - } - if (context.req) ctx.req = context.req - if (context.res) ctx.res = context.res - if (context.from) ctx.from = context.from - if (ctx.isServer && context.beforeRenderFns) { - ctx.beforeNuxtRender = (fn) => context.beforeRenderFns.push(fn) - } - if (ctx.isClient && window.__NUXT__) { - ctx.serverState = window.__NUXT__ - } - return ctx -} - -export function middlewareSeries (promises, context) { - if (!promises.length || context._redirected) { - return Promise.resolve() - } - return promisify(promises[0], context) - .then(() => { - return middlewareSeries(promises.slice(1), context) - }) -} - -export function promisify (fn, context) { - let promise - if (fn.length === 2) { - // fn(context, callback) - promise = new Promise((resolve) => { - fn(context, function (err, data) { - if (err) { - context.error(err) - } - data = data || {} - resolve(data) - }) - }) - } else { - promise = fn(context) - } - if (!promise || (!(promise instanceof Promise) && (typeof promise.then !== 'function'))) { - promise = Promise.resolve(promise) - } - return promise -} - -// Imported from vue-router -export function getLocation (base, mode) { - var path = window.location.pathname - if (mode === 'hash') { - return window.location.hash.replace(/^#\//, '') - } - if (base && path.indexOf(base) === 0) { - path = path.slice(base.length) - } - return (path || '/') + window.location.search + window.location.hash -} - -export function urlJoin () { - return [].slice.call(arguments).join('/').replace(/\/+/g, '/') -} - -// Imported from path-to-regexp - -/** - * Compile a string to a template function for the path. - * - * @param {string} str - * @param {Object=} options - * @return {!function(Object=, Object=)} - */ -export function compile (str, options) { - return tokensToFunction(parse(str, options)) -} - -/** - * The main path matching regexp utility. - * - * @type {RegExp} - */ -const PATH_REGEXP = new RegExp([ - // Match escaped characters that would otherwise appear in future matches. - // This allows the user to escape special characters that won't transform. - '(\\\\.)', - // Match Express-style parameters and un-named parameters with a prefix - // and optional suffixes. Matches appear as: - // - // "/:test(\\d+)?" => ["/", "test", "\d+", undefined, "?", undefined] - // "/route(\\d+)" => [undefined, undefined, undefined, "\d+", undefined, undefined] - // "/*" => ["/", undefined, undefined, undefined, undefined, "*"] - '([\\/.])?(?:(?:\\:(\\w+)(?:\\(((?:\\\\.|[^\\\\()])+)\\))?|\\(((?:\\\\.|[^\\\\()])+)\\))([+*?])?|(\\*))' -].join('|'), 'g') - -/** - * Parse a string for the raw tokens. - * - * @param {string} str - * @param {Object=} options - * @return {!Array} - */ -function parse (str, options) { - var tokens = [] - var key = 0 - var index = 0 - var path = '' - var defaultDelimiter = options && options.delimiter || '/' - var res - - while ((res = PATH_REGEXP.exec(str)) != null) { - var m = res[0] - var escaped = res[1] - var offset = res.index - path += str.slice(index, offset) - index = offset + m.length - - // Ignore already escaped sequences. - if (escaped) { - path += escaped[1] - continue - } - - var next = str[index] - var prefix = res[2] - var name = res[3] - var capture = res[4] - var group = res[5] - var modifier = res[6] - var asterisk = res[7] - - // Push the current path onto the tokens. - if (path) { - tokens.push(path) - path = '' - } - - var partial = prefix != null && next != null && next !== prefix - var repeat = modifier === '+' || modifier === '*' - var optional = modifier === '?' || modifier === '*' - var delimiter = res[2] || defaultDelimiter - var pattern = capture || group - - tokens.push({ - name: name || key++, - prefix: prefix || '', - delimiter: delimiter, - optional: optional, - repeat: repeat, - partial: partial, - asterisk: !!asterisk, - pattern: pattern ? escapeGroup(pattern) : (asterisk ? '.*' : '[^' + escapeString(delimiter) + ']+?') - }) - } - - // Match any characters still remaining. - if (index < str.length) { - path += str.substr(index) - } - - // If the path exists, push it onto the end. - if (path) { - tokens.push(path) - } - - return tokens -} - -/** - * Prettier encoding of URI path segments. - * - * @param {string} - * @return {string} - */ -function encodeURIComponentPretty (str) { - return encodeURI(str).replace(/[\/?#]/g, function (c) { - return '%' + c.charCodeAt(0).toString(16).toUpperCase() - }) -} - -/** - * Encode the asterisk parameter. Similar to `pretty`, but allows slashes. - * - * @param {string} - * @return {string} - */ -function encodeAsterisk (str) { - return encodeURI(str).replace(/[?#]/g, function (c) { - return '%' + c.charCodeAt(0).toString(16).toUpperCase() - }) -} - -/** - * Expose a method for transforming tokens into the path function. - */ -function tokensToFunction (tokens) { - // Compile all the tokens into regexps. - var matches = new Array(tokens.length) - - // Compile all the patterns before compilation. - for (var i = 0; i < tokens.length; i++) { - if (typeof tokens[i] === 'object') { - matches[i] = new RegExp('^(?:' + tokens[i].pattern + ')$') - } - } - - return function (obj, opts) { - var path = '' - var data = obj || {} - var options = opts || {} - var encode = options.pretty ? encodeURIComponentPretty : encodeURIComponent - - for (var i = 0; i < tokens.length; i++) { - var token = tokens[i] - - if (typeof token === 'string') { - path += token - - continue - } - - var value = data[token.name] - var segment - - if (value == null) { - if (token.optional) { - // Prepend partial segment prefixes. - if (token.partial) { - path += token.prefix - } - - continue - } else { - throw new TypeError('Expected "' + token.name + '" to be defined') - } - } - - if (Array.isArray(value)) { - if (!token.repeat) { - throw new TypeError('Expected "' + token.name + '" to not repeat, but received `' + JSON.stringify(value) + '`') - } - - if (value.length === 0) { - if (token.optional) { - continue - } else { - throw new TypeError('Expected "' + token.name + '" to not be empty') - } - } - - for (var j = 0; j < value.length; j++) { - segment = encode(value[j]) - - if (!matches[i].test(segment)) { - throw new TypeError('Expected all "' + token.name + '" to match "' + token.pattern + '", but received `' + JSON.stringify(segment) + '`') - } - - path += (j === 0 ? token.prefix : token.delimiter) + segment - } - - continue - } - - segment = token.asterisk ? encodeAsterisk(value) : encode(value) - - if (!matches[i].test(segment)) { - throw new TypeError('Expected "' + token.name + '" to match "' + token.pattern + '", but received "' + segment + '"') - } - - path += token.prefix + segment - } - - return path - } -} - -/** - * Escape a regular expression string. - * - * @param {string} str - * @return {string} - */ -function escapeString (str) { - return str.replace(/([.+*?=^!:()[\]|\/\\])/g, '\\$1') -} - -/** - * Escape the capturing group by escaping special characters and meaning. - * - * @param {string} group - * @return {string} - */ -function escapeGroup (group) { - return group.replace(/([=!:$\/()])/g, '\\$1') -} diff --git a/.nuxt/views/app.template.html b/.nuxt/views/app.template.html deleted file mode 100644 index 3ef8d3b..0000000 --- a/.nuxt/views/app.template.html +++ /dev/null @@ -1,9 +0,0 @@ - - - - {{ HEAD }} - - - {{ APP }} - - diff --git a/.nuxt/views/error.html b/.nuxt/views/error.html deleted file mode 100644 index c7354d5..0000000 --- a/.nuxt/views/error.html +++ /dev/null @@ -1,23 +0,0 @@ - - - -Server error - - - - - -
-
- -
Server error
-
{{ message }}
-
- -
- -