Selaa lähdekoodia

修改server配置位置

zweizhao 7 vuotta sitten
vanhempi
commit
609ce315ac
10 muutettua tiedostoa jossa 125 lisäystä ja 12 poistoa
  1. 2 0
      .nuxt/App.js
  2. 2 2
      .nuxt/axios.js
  3. 102 1
      .nuxt/client.js
  4. 2 0
      .nuxt/components/nuxt-error.vue
  5. 2 0
      .nuxt/loading.html
  6. 5 1
      .nuxt/server.js
  7. 4 1
      .nuxt/utils.js
  8. 1 1
      .nuxt/views/error.html
  9. 5 0
      nuxt.config.js
  10. 0 6
      package.json

+ 2 - 0
.nuxt/App.js

@@ -80,6 +80,8 @@ export default {
     },
 
     setLayout(layout) {
+      if(layout && typeof layout !== 'string') throw new Error('[nuxt] Avoid using non-string value as layout property.')
+
       if (!layout || !layouts['_' + layout]) {
         layout = 'default'
       }

+ 2 - 2
.nuxt/axios.js

@@ -106,8 +106,8 @@ const setupProgress = (axios, ctx) => {
 export default (ctx, inject) => {
   // baseURL
   const baseURL = process.browser
-      ? 'http://local-rooter.proginn.com:20201/'
-      : (process.env._AXIOS_BASE_URL_ || 'http://local-rooter.proginn.com:20201/')
+      ? 'http://localhost:3000/'
+      : (process.env._AXIOS_BASE_URL_ || 'http://localhost:3000/')
 
   // Create fresh objects for all default header scopes
   // Axios creates only one which is shared across SSR requests!

+ 102 - 1
.nuxt/client.js

@@ -28,7 +28,7 @@ let router
 // Try to rehydrate SSR data from window
 const NUXT = window.__NUXT__ || {}
 
-Object.assign(Vue.config, {"silent":true,"performance":false})
+Object.assign(Vue.config, {"silent":false,"performance":true})
 
 // Setup global Vue error handler
 if (!Vue.config.$nuxt) {
@@ -468,6 +468,9 @@ function fixPrepatch(to, ___) {
       }
     })
     showNextPage.call(this, to)
+
+    // Hot reloading
+    setTimeout(() => hotReloadAPI(this), 100)
   })
 }
 
@@ -488,6 +491,101 @@ function nuxtReady(_app) {
   })
 }
 
+// Special hot reload with asyncData(context)
+function getNuxtChildComponents($parent, $components = []) {
+  $parent.$children.forEach(($child) => {
+    if ($child.$vnode.data.nuxtChild && !$components.find(c =>(c.$options.__file === $child.$options.__file))) {
+      $components.push($child)
+    }
+    if ($child.$children && $child.$children.length) {
+      getNuxtChildComponents($child, $components)
+    }
+  })
+
+  return $components
+}
+
+function hotReloadAPI(_app) {
+  if (!module.hot) return
+
+  let $components = getNuxtChildComponents(_app.$nuxt, [])
+
+  $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 = async () => {
+    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)
+    }
+    await setContext(app, {
+      route: router.currentRoute,
+      isHMR: true,
+      next: next.bind(this)
+    })
+    const context = app.context
+
+    if (this.$loading.start && !this.$loading.manual) 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
@@ -507,6 +605,9 @@ async function mountApp(__app) {
     Vue.nextTick(() => {
       // Call window.{{globals.readyCallback}} callbacks
       nuxtReady(_app)
+
+      // Enable hot reloading
+      hotReloadAPI(_app)
     })
   }
 

+ 2 - 0
.nuxt/components/nuxt-error.vue

@@ -8,6 +8,8 @@
         <nuxt-link class="error-link" to="/">Back to the home page</nuxt-link>
       </p>
 
+      <p class="description" v-else>An error occurred while rendering the page. Check developer tools console for details.</p>
+
       <div class="logo">
         <a href="https://nuxtjs.org" target="_blank" rel="noopener">Nuxt.js</a>
       </div>

+ 2 - 0
.nuxt/loading.html

@@ -103,3 +103,5 @@ window.addEventListener('error', function () {
 </script>
 
 <div id="nuxt-loading" aria-live="polite" role="status"><div>Loading...</div></div>
+
+<!-- https://projects.lukehaas.me/css-loaders -->

+ 5 - 1
.nuxt/server.js

@@ -8,7 +8,7 @@ import { createApp, NuxtError } from './index'
 const debug = require('debug')('nuxt:render')
 debug.color = 4 // force blue color
 
-const isDev = false
+const isDev = true
 
 const noopApp = () => new Vue({ render: h => h('div') })
 
@@ -76,6 +76,8 @@ export default async (ssrContext) => {
     return renderErrorPage()
   }
 
+  const s = isDev && Date.now()
+
   // Components are already resolved by setContext -> getRouteData (app/utils.js)
   const Components = getMatchedComponents(router.match(ssrContext.url))
 
@@ -190,6 +192,8 @@ export default async (ssrContext) => {
     return Promise.all(promises)
   }))
 
+  if (asyncDatas.length) debug('Data fetching ' + ssrContext.url + ': ' + (Date.now() - s) + 'ms')
+
   // datas are the first row of each
   ssrContext.nuxt.data = asyncDatas.map(r => r[0] || {})
 

+ 4 - 1
.nuxt/utils.js

@@ -122,7 +122,7 @@ export async function setContext(app, context) {
   if (!app.context) {
     app.context = {
       isStatic: process.static,
-      isDev: false,
+      isDev: true,
       isHMR: false,
       app,
 
@@ -209,6 +209,9 @@ export function middlewareSeries(promises, appContext) {
 export function promisify(fn, context) {
   let promise
   if (fn.length === 2) {
+      console.warn('Callback-based asyncData, fetch or middleware calls are deprecated. ' +
+        'Please switch to promises or async/await syntax')
+
     // fn(context, callback)
     promise = new Promise((resolve) => {
       fn(context, function (err, data) {

+ 1 - 1
.nuxt/views/error.html

@@ -13,7 +13,7 @@
     <div class="error">
         <svg xmlns="http://www.w3.org/2000/svg" width="90" height="90" fill="#DBE1EC" viewBox="0 0 48 48"><path d="M22 30h4v4h-4zm0-16h4v12h-4zm1.99-10C12.94 4 4 12.95 4 24s8.94 20 19.99 20S44 35.05 44 24 35.04 4 23.99 4zM24 40c-8.84 0-16-7.16-16-16S15.16 8 24 8s16 7.16 16 16-7.16 16-16 16z"/></svg>
         <div class="title">Server error</div>
-        <div class="description">An error occurred in the application and your page could not be served. If you are the application owner, check your logs for details.</div>
+        <div class="description">{{ message }}</div>
     </div>
     <div class="logo">
       <a href="https://nuxtjs.org" target="_blank" rel="noopener">Nuxt.js</a>

+ 5 - 0
nuxt.config.js

@@ -3,6 +3,11 @@ const pkg = require('./package')
 module.exports = {
   mode: 'spa',
 
+  server: {
+    "host": "local-rooter.proginn.com",
+    "port": "20201"
+  },
+
   /**
    * 打包文件
    */

+ 0 - 6
package.json

@@ -4,12 +4,6 @@
   "description": "boss ssr ver",
   "author": "zweizhao",
   "private": true,
-  "config": {
-    "nuxt": {
-      "host": "local-rooter.proginn.com",
-      "port": "20201"
-    }
-  },
   "scripts": {
     "dev": "npx nuxt",
     "build": "nuxt build",