From 1401434594b36b7292e11ca54a24cdc3f028bd99 Mon Sep 17 00:00:00 2001 From: Hana Shiro Date: Sat, 22 Jul 2017 07:40:38 +0800 Subject: [PATCH 01/42] Resolve non-js package importing --- lib/app/App.vue | 2 +- lib/builder/builder.js | 1 + lib/core/nuxt.js | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/app/App.vue b/lib/app/App.vue index a47e53bce9..d2e9f8a163 100644 --- a/lib/app/App.vue +++ b/lib/app/App.vue @@ -8,7 +8,7 @@ + + diff --git a/examples/vue-apollo/pages/index.vue b/examples/vue-apollo/pages/index.vue index bdb630f4ff..41b4b8bf9f 100644 --- a/examples/vue-apollo/pages/index.vue +++ b/examples/vue-apollo/pages/index.vue @@ -12,21 +12,14 @@ diff --git a/examples/vue-apollo/plugins/apollo.js b/examples/vue-apollo/plugins/apollo.js deleted file mode 100644 index cf888008c9..0000000000 --- a/examples/vue-apollo/plugins/apollo.js +++ /dev/null @@ -1,21 +0,0 @@ -import 'babel-polyfill' -import Vue from 'vue' -import VueApollo from 'vue-apollo' -import { ApolloClient, createNetworkInterface } from 'apollo-client' - -Vue.use(VueApollo) - -const API_ENDPOINT = 'https://api.graph.cool/simple/v1/cj1dqiyvqqnmj0113yuqamkuu' - -const apolloClient = new ApolloClient({ - networkInterface: createNetworkInterface({ - uri: API_ENDPOINT, - transportBatching: true - }) -}) - -const apolloProvider = new VueApollo({ - defaultClient: apolloClient -}) - -export default apolloProvider diff --git a/examples/vue-apollo/queries/allCars.gql b/examples/vue-apollo/queries/allCars.gql new file mode 100644 index 0000000000..81c1448c14 --- /dev/null +++ b/examples/vue-apollo/queries/allCars.gql @@ -0,0 +1,8 @@ +{ + allCars { + id + make + model + year + } +} diff --git a/examples/vue-apollo/queries/car.gql b/examples/vue-apollo/queries/car.gql new file mode 100644 index 0000000000..c380d25884 --- /dev/null +++ b/examples/vue-apollo/queries/car.gql @@ -0,0 +1,8 @@ +query Car($id: ID!) { + Car(id: $id) { + make + model + photoURL + price + } +} diff --git a/examples/vue-apollo/server.js b/examples/vue-apollo/server.js deleted file mode 100644 index 32364be29a..0000000000 --- a/examples/vue-apollo/server.js +++ /dev/null @@ -1,27 +0,0 @@ -const Nuxt = require('../../') -const app = require('express')() -const host = process.env.HOST || '127.0.0.1' -const port = process.env.PORT || 3000 - -global.fetch = require('node-fetch') - -// Import and Set Nuxt.js options -let config = require('./nuxt.config.js') -config.dev = !(process.env.NODE_ENV === 'production') - -// Init Nuxt.js -const nuxt = new Nuxt(config) -app.use(nuxt.render) - -// Build only in dev mode -if (config.dev) { - nuxt.build() - .catch((error) => { - console.error(error) // eslint-disable-line no-console - process.exit(1) - }) -} - -// Listen the server -app.listen(port, host) -console.log('Server listening on ' + host + ':' + port) // eslint-disable-line no-console From 6c6e6e55aaeae136348f953d293a02d8a8b22d7b Mon Sep 17 00:00:00 2001 From: Sebastien Chopin Date: Thu, 27 Jul 2017 16:26:36 +0200 Subject: [PATCH 23/42] Fix layout not declared --- lib/app/client.js | 62 +++++++++++++++++++++++------------------------ 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/lib/app/client.js b/lib/app/client.js index a769426efd..5c130ad6fe 100644 --- a/lib/app/client.js +++ b/lib/app/client.js @@ -1,13 +1,13 @@ import Vue from 'vue' import middleware from './middleware' import { createApp, NuxtError } from './index' -import { +import { applyAsyncData, sanitizeComponent, - getMatchedComponents, + getMatchedComponents, getMatchedComponentsInstances, - flatMapComponents, - getContext, + flatMapComponents, + getContext, middlewareSeries, promisify, getLocation, @@ -51,11 +51,11 @@ function mapTransitions(Components, to, from) { 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) @@ -63,7 +63,7 @@ function mapTransitions(Components, to, from) { .filter(key => from_transitions[key] && key.toLowerCase().indexOf('leave') !== -1) .forEach(key => { transitions[key] = from_transitions[key] }) } - + return transitions }) } @@ -73,7 +73,7 @@ async function loadAsyncComponents (to, from, next) { const fromPath = from.fullPath.split('#')[0] const toPath = to.fullPath.split('#')[0] this._hashChanged = fromPath === toPath - + <% if (loading) { %> if (!this._hashChanged && this.$loading.start) { this.$loading.start() @@ -109,9 +109,9 @@ async function loadAsyncComponents (to, from, next) { // Get matched components function resolveComponents(router) { const path = getLocation(router.options.base) - + return flatMapComponents(router.match(path), (Component, _, match, key, index) => { - // If component already resolved + // If component already resolved if (typeof Component !== 'function' || Component.options) { const _Component = sanitizeComponent(Component) match.components[key] = _Component @@ -137,7 +137,7 @@ function resolveComponents(router) { function callMiddleware (Components, context, layout) { let midd = <%= serialize(router.middleware, { isJSON: true }) %> 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) @@ -158,8 +158,8 @@ function callMiddleware (Components, context, layout) { } return middleware[name] }) - - if (unknownMiddleware) return + + if (unknownMiddleware) return return middlewareSeries(midd, context) } @@ -174,9 +174,9 @@ async function render (to, from, next) { nextCalled = true next(path) } - + // Update context - const context = getContext({ + const context = getContext({ to, from, <% if (store) { %>store,<% } %> @@ -197,16 +197,16 @@ async function render (to, from, next) { // Default layout await callMiddleware.call(this, Components, context) if (context._redirected) return - + // Load layout for error page - layout = await this.loadLayout(typeof NuxtError.layout === 'function' ? NuxtError.layout(context) : NuxtError.layout) + 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) { @@ -233,7 +233,7 @@ async function render (to, from, next) { // Call middleware for layout await callMiddleware.call(this, Components, context, layout) if (context._redirected) return - + // Call .validate() let isValid = true Components.forEach(Component => { @@ -250,7 +250,7 @@ async function render (to, from, next) { 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 @@ -263,7 +263,7 @@ async function render (to, from, next) { const hasAsyncData = Component.options.asyncData && typeof Component.options.asyncData === 'function' const hasFetch = !!Component.options.fetch - <% if(loading) { %>const loadingIncrease = (hasAsyncData && hasFetch) ? 30 : 45<% } %> + <% if(loading) { %>const loadingIncrease = (hasAsyncData && hasFetch) ? 30 : 45<% } %> // Call asyncData(context) if (hasAsyncData) { @@ -279,7 +279,7 @@ async function render (to, from, next) { if (hasFetch) { let p = Component.options.fetch(context) if (!p || (!(p instanceof Promise) && (typeof p.then !== 'function'))) { - p = Promise.resolve(p) + p = Promise.resolve(p) } p.then(fetchResult => { <% if(loading) { %>if(this.$loading.increase) this.$loading.increase(loadingIncrease)<% } %> @@ -289,7 +289,7 @@ async function render (to, from, next) { return Promise.all(promises) })) - + _lastPaths = Components.map((Component, i) => compile(to.matched[i].path)(to.params)) <% if(loading) { %>if(this.$loading.finish) this.$loading.finish()<% } %> @@ -308,7 +308,7 @@ async function render (to, from, next) { layout = layout(context) } await this.loadLayout(layout) - + this.error(error) next(false) } @@ -387,10 +387,10 @@ function nuxtReady (app) { // 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) { @@ -407,7 +407,7 @@ function hotReloadAPI (_app) { $nuxt = child }) } - + $components.forEach(addHotReload.bind(_app)) } @@ -517,7 +517,7 @@ async function mountApp(__app) { _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 @@ -528,7 +528,7 @@ async function mountApp(__app) { router.beforeEach(render.bind(_app)) router.afterEach(normalizeComponents) router.afterEach(fixPrepatch.bind(_app)) - + // If page already is server rendered if (NUXT.serverRendered) { mountApp() @@ -552,4 +552,4 @@ async function mountApp(__app) { }) router.push(path) }) -} \ No newline at end of file +} From 4a6b651d56f001df9dd6b92cb78609c4d22d470a Mon Sep 17 00:00:00 2001 From: Sebastien Chopin Date: Thu, 27 Jul 2017 16:26:59 +0200 Subject: [PATCH 24/42] Add beforeNuxtRender hook --- lib/app/index.js | 1 + lib/app/server.js | 35 +++++++++++++++++++---------------- lib/app/utils.js | 3 +++ 3 files changed, 23 insertions(+), 16 deletions(-) diff --git a/lib/app/index.js b/lib/app/index.js index 2e7fe7eab0..44375eeb88 100644 --- a/lib/app/index.js +++ b/lib/app/index.js @@ -113,6 +113,7 @@ async function createApp (ssrContext) { <% if(store) { %>store,<% } %> req: ssrContext ? ssrContext.req : undefined, res: ssrContext ? ssrContext.res : undefined, + beforeRenderFns: ssrContext ? ssrContext.beforeRenderFns : undefined }, app) <% plugins.filter(p => p.ssr).forEach(plugin => { %> diff --git a/lib/app/server.js b/lib/app/server.js index 30854eb407..11f011ea0b 100644 --- a/lib/app/server.js +++ b/lib/app/server.js @@ -45,27 +45,28 @@ 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 ? ', store' : '') %> } = await createApp(context) const _app = new Vue(app) - + <% if (store) { %> // 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<%= (store ? ', 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 = {} @@ -73,8 +74,8 @@ export default async context => { const ctx = getContext(context, app) <% if (isDev) { %>const s = isDev && Date.now()<% } %> - - // Resolve components + + // Resolve components let Components = [] try { Components = await Promise.all(getMatchedComponents(router.match(context.url)).map(Component => { @@ -118,7 +119,7 @@ export default async context => { layout = _app.setLayout(layout) // ...Set layout to __NUXT__ context.nuxt.layout = _app.layoutName - + // Call middleware (layout + pages) if (!context.nuxt.error) { midd = [] @@ -134,9 +135,9 @@ export default async context => { } return middleware[name] }) - + await middlewareSeries(midd, ctx) - + // If there is a redirect if (context.redirected) return noopApp() } @@ -161,11 +162,11 @@ export default async context => { // 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) @@ -189,7 +190,7 @@ export default async context => { 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.' }) @@ -210,6 +211,8 @@ export default async context => { 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 @@ -220,6 +223,6 @@ export default async context => { context.nuxt.layout = layout || '' await _app.loadLayout(layout) _app.setLayout(layout) - + return _app } diff --git a/lib/app/utils.js b/lib/app/utils.js index 547f46b86a..1cbe23b0d9 100644 --- a/lib/app/utils.js +++ b/lib/app/utils.js @@ -104,6 +104,9 @@ export function getContext (context, app) { 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) + } return ctx } From 8e79e7ce4295d9b7037b43a1cbf34788428de056 Mon Sep 17 00:00:00 2001 From: Sebastien Chopin Date: Thu, 27 Jul 2017 16:35:17 +0200 Subject: [PATCH 25/42] Use nuxt module and rc2 --- examples/vue-apollo/package.json | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/examples/vue-apollo/package.json b/examples/vue-apollo/package.json index b676a8fbc6..985935ab76 100644 --- a/examples/vue-apollo/package.json +++ b/examples/vue-apollo/package.json @@ -1,9 +1,8 @@ { "name": "nuxt-vue-apollo", "dependencies": { - "apollo-client": "^1.9.0-1", - "nuxt": "latest", - "vue-apollo": "^2.1.0-beta.19" + "@nuxtjs/apollo": "^0.1.0", + "nuxt": "^1.0.0-rc2" }, "scripts": { "dev": "nuxt", From 15400e1828c2152a559bcf906c21892df520ffd3 Mon Sep 17 00:00:00 2001 From: Sebastien Chopin Date: Thu, 27 Jul 2017 16:50:24 +0200 Subject: [PATCH 26/42] Add test for custom state --- test/basic.test.js | 5 +++++ test/fixtures/basic/pages/special-state.vue | 15 +++++++++++++++ test/fixtures/with-config/nuxt.config.js | 2 +- 3 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 test/fixtures/basic/pages/special-state.vue diff --git a/test/basic.test.js b/test/basic.test.js index 93a0e07c5b..42063c9219 100755 --- a/test/basic.test.js +++ b/test/basic.test.js @@ -101,6 +101,11 @@ test('/redirect -> check redirected source', async t => { t.true(html.includes('

Index page

')) }) +test.only('/special-state -> check window.__NUXT__.test = true', async t => { + const window = await nuxt.renderAndGetWindow(url('/special-state')) + t.is(window.__NUXT__.test, true) +}) + test('/error', async t => { try { await nuxt.renderRoute('/error', { req: {}, res: {} }) diff --git a/test/fixtures/basic/pages/special-state.vue b/test/fixtures/basic/pages/special-state.vue new file mode 100644 index 0000000000..5e4fc7a989 --- /dev/null +++ b/test/fixtures/basic/pages/special-state.vue @@ -0,0 +1,15 @@ + + + diff --git a/test/fixtures/with-config/nuxt.config.js b/test/fixtures/with-config/nuxt.config.js index 339e770469..f13748f4e1 100644 --- a/test/fixtures/with-config/nuxt.config.js +++ b/test/fixtures/with-config/nuxt.config.js @@ -14,7 +14,7 @@ module.exports = { transition: 'test', offline: true, plugins: [ - '~/plugins/test.js', // Use ~ for deprication warning coverage + '~/plugins/test.js', { src: '~/plugins/only-client.js', ssr: false } ], loading: '~/components/loading', From 45933f58c0172075c5ccfbcf67dbb25429fd22b4 Mon Sep 17 00:00:00 2001 From: Sebastien Chopin Date: Thu, 27 Jul 2017 16:51:17 +0200 Subject: [PATCH 27/42] Remove only test --- test/basic.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/basic.test.js b/test/basic.test.js index 42063c9219..624916b74d 100755 --- a/test/basic.test.js +++ b/test/basic.test.js @@ -101,7 +101,7 @@ test('/redirect -> check redirected source', async t => { t.true(html.includes('

Index page

')) }) -test.only('/special-state -> check window.__NUXT__.test = true', async t => { +test('/special-state -> check window.__NUXT__.test = true', async t => { const window = await nuxt.renderAndGetWindow(url('/special-state')) t.is(window.__NUXT__.test, true) }) From cf6b0df45f678c5ac35535d49710c606ab34787d Mon Sep 17 00:00:00 2001 From: Sebastien Chopin Date: Thu, 27 Jul 2017 16:51:24 +0200 Subject: [PATCH 28/42] Bump version rc2 --- package.json | 2 +- start/package.json | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index af7aa22b49..1644a873d6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "nuxt", - "version": "1.0.0-rc1", + "version": "1.0.0-rc2", "description": "A minimalistic framework for server-rendered Vue.js applications (inspired by Next.js)", "contributors": [ { diff --git a/start/package.json b/start/package.json index 2ae14fe15b..fe90240aee 100644 --- a/start/package.json +++ b/start/package.json @@ -1,6 +1,6 @@ { "name": "nuxt-start", - "version": "1.0.0-rc1", + "version": "1.0.0-rc2", "description": "runtime-only build for nuxt", "contributors": [ { @@ -62,7 +62,8 @@ "compression": "^1.7.0", "fs-extra": "^4.0.0", "vue-server-renderer": "~2.4.2", - "connect": "^3.6.2" + "connect": "^3.6.2", + "server-destroy": "^1.0.1" }, "collective": { "type": "opencollective", From 8c354c085c5ef2fae043a027796802640e5c516f Mon Sep 17 00:00:00 2001 From: Sebastien Chopin Date: Thu, 27 Jul 2017 16:56:07 +0200 Subject: [PATCH 29/42] Remove with-apollo example, see vue-apollo now --- examples/with-apollo/README.md | 29 ------------ examples/with-apollo/layouts/default.vue | 19 -------- examples/with-apollo/layouts/error.vue | 13 ------ examples/with-apollo/package.json | 24 ---------- examples/with-apollo/pages/car/_id.vue | 54 ---------------------- examples/with-apollo/pages/index.vue | 59 ------------------------ examples/with-apollo/plugins/apollo.js | 15 ------ 7 files changed, 213 deletions(-) delete mode 100644 examples/with-apollo/README.md delete mode 100644 examples/with-apollo/layouts/default.vue delete mode 100644 examples/with-apollo/layouts/error.vue delete mode 100644 examples/with-apollo/package.json delete mode 100644 examples/with-apollo/pages/car/_id.vue delete mode 100644 examples/with-apollo/pages/index.vue delete mode 100644 examples/with-apollo/plugins/apollo.js diff --git a/examples/with-apollo/README.md b/examples/with-apollo/README.md deleted file mode 100644 index d4600552fb..0000000000 --- a/examples/with-apollo/README.md +++ /dev/null @@ -1,29 +0,0 @@ -# nuxt-with-apollo - -> Nuxt.js with Apollo (GraphQL client) - -[DEMO](https://nuxt-apollo.now.sh/) - -## About - -This project uses [Apollo](http://www.apollodata.com/) as a GraphQL client and [Graphcool](https://www.graph.cool/) as a hosted GraphQL backend. - -## Getting Started - -Download this example [or clone the repo](https://github.com/nuxt/nuxt.js): - -```bash -curl https://codeload.github.com/nuxt/nuxt.js/tar.gz/master | tar -xz --strip=2 nuxt.js-master/examples/with-apollo -cd with-apollo -``` - -Install and run: - -```bash -npm install -npm run dev - -# or with Yarn -yarn -yarn dev -``` diff --git a/examples/with-apollo/layouts/default.vue b/examples/with-apollo/layouts/default.vue deleted file mode 100644 index 62147ffc78..0000000000 --- a/examples/with-apollo/layouts/default.vue +++ /dev/null @@ -1,19 +0,0 @@ - - - diff --git a/examples/with-apollo/layouts/error.vue b/examples/with-apollo/layouts/error.vue deleted file mode 100644 index 192163dd31..0000000000 --- a/examples/with-apollo/layouts/error.vue +++ /dev/null @@ -1,13 +0,0 @@ - - - diff --git a/examples/with-apollo/package.json b/examples/with-apollo/package.json deleted file mode 100644 index c3bb76f0f4..0000000000 --- a/examples/with-apollo/package.json +++ /dev/null @@ -1,24 +0,0 @@ -{ - "name": "nuxt-apollo", - "version": "1.0.0", - "description": "Nuxt.js with Apollo", - "author": "Charlie Hield", - "license": "MIT", - "scripts": { - "dev": "nuxt", - "build": "nuxt build", - "start": "nuxt start" - }, - "keywords": [ - "nuxt", - "vue", - "apollo", - "graphql" - ], - "dependencies": { - "apollo-client": "^1.0.2", - "graphql-tag": "^2.0.0", - "isomorphic-fetch": "^2.2.1", - "nuxt": "^0.10.5" - } -} diff --git a/examples/with-apollo/pages/car/_id.vue b/examples/with-apollo/pages/car/_id.vue deleted file mode 100644 index 955b9475ec..0000000000 --- a/examples/with-apollo/pages/car/_id.vue +++ /dev/null @@ -1,54 +0,0 @@ - - - - - diff --git a/examples/with-apollo/pages/index.vue b/examples/with-apollo/pages/index.vue deleted file mode 100644 index b8c6a7d7df..0000000000 --- a/examples/with-apollo/pages/index.vue +++ /dev/null @@ -1,59 +0,0 @@ - - - - - diff --git a/examples/with-apollo/plugins/apollo.js b/examples/with-apollo/plugins/apollo.js deleted file mode 100644 index f328ff1fc7..0000000000 --- a/examples/with-apollo/plugins/apollo.js +++ /dev/null @@ -1,15 +0,0 @@ -import Vue from 'vue' -import { ApolloClient, createNetworkInterface } from 'apollo-client' -import 'isomorphic-fetch' - -// Created with Graphcool - https://www.graph.cool/ -const API_ENDPOINT = 'https://api.graph.cool/simple/v1/cj1dqiyvqqnmj0113yuqamkuu' - -const apolloClient = new ApolloClient({ - networkInterface: createNetworkInterface({ - uri: API_ENDPOINT, - transportBatching: true - }) -}) - -export default apolloClient From d4ff65604e17fe22470afdcd52ce1bbc7b8b3118 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Chopin?= Date: Thu, 27 Jul 2017 17:02:54 +0200 Subject: [PATCH 30/42] Update README.md --- examples/vue-apollo/README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/examples/vue-apollo/README.md b/examples/vue-apollo/README.md index c7cc8f795f..92ef54ec86 100644 --- a/examples/vue-apollo/README.md +++ b/examples/vue-apollo/README.md @@ -1,5 +1,7 @@ # Vue-Apollo with Nuxt.js +Demo: https://nuxt-vue-apollo.now.sh/ + https://github.com/nuxt-community/apollo-module https://github.com/Akryum/vue-apollo From 93199da1587ba11887360333ee9c1ae7287c1a14 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Chopin?= Date: Thu, 27 Jul 2017 17:10:20 +0200 Subject: [PATCH 31/42] Update README.md --- README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index dfbb6de3b8..be1adfcc6c 100644 --- a/README.md +++ b/README.md @@ -158,11 +158,11 @@ Learn more at [nuxtjs.org](https://nuxtjs.org). ## Templates You can start by using one of our starter templates: -- [starter](https://github.com/nuxt/starter): Basic Nuxt.js project template -- [express](https://github.com/nuxt/express): Nuxt.js + Express -- [koa](https://github.com/nuxt/koa): Nuxt.js + Koa -- [adonuxt](https://github.com/nuxt/adonuxt): Nuxt.js + AdonisJS -- [nuxtent](https://github.com/nuxt-community/nuxtent): Nuxt.js + Nuxtent for content heavy sites +- [starter](https://github.com/nuxt-community/starter-template): Basic Nuxt.js project template +- [express](https://github.com/nuxt-community/express-template): Nuxt.js + Express +- [koa](https://github.com/nuxt-community/koa-template): Nuxt.js + Koa +- [adonuxt](https://github.com/nuxt-community/adonuxt-template): Nuxt.js + AdonisJS +- [nuxtent](https://github.com/nuxt-community/nuxtent-template): Nuxt.js + Nuxtent module for content heavy sites ## Using nuxt.js programmatically From dcb4ab514ee57b9a2b464e293c67dc3befa3b1be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Chopin?= Date: Thu, 27 Jul 2017 17:13:05 +0200 Subject: [PATCH 32/42] Add micro template --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index be1adfcc6c..44d7074586 100644 --- a/README.md +++ b/README.md @@ -162,6 +162,7 @@ You can start by using one of our starter templates: - [express](https://github.com/nuxt-community/express-template): Nuxt.js + Express - [koa](https://github.com/nuxt-community/koa-template): Nuxt.js + Koa - [adonuxt](https://github.com/nuxt-community/adonuxt-template): Nuxt.js + AdonisJS +- [micro](https://github.com/nuxt-community/micro-template): Nuxt.js + Micro - [nuxtent](https://github.com/nuxt-community/nuxtent-template): Nuxt.js + Nuxtent module for content heavy sites ## Using nuxt.js programmatically From e29f439ff0ea9457518316f51b5c91591c008659 Mon Sep 17 00:00:00 2001 From: Pooya Parsa Date: Thu, 27 Jul 2017 21:37:24 +0430 Subject: [PATCH 33/42] load SSR bundle on warns too partial fix for #1179 --- lib/builder/builder.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/builder/builder.js b/lib/builder/builder.js index db6575e5bb..25c347ceeb 100644 --- a/lib/builder/builder.js +++ b/lib/builder/builder.js @@ -329,7 +329,7 @@ export default class Builder extends Tapable { this.compiler.plugin('done', async stats => { // Don't reload failed builds /* istanbul ignore if */ - if (stats.hasErrors() || stats.hasWarnings()) { + if (stats.hasErrors()) { return } // Reload renderer if available From 080453586f47530b92e22181703fdf967fb38804 Mon Sep 17 00:00:00 2001 From: Pooya Parsa Date: Thu, 27 Jul 2017 22:16:11 +0430 Subject: [PATCH 34/42] hide warns about plugins without a default export partial fix for #1179 --- lib/builder/webpack/base.config.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/lib/builder/webpack/base.config.js b/lib/builder/webpack/base.config.js index bc3b4b7390..b0db0ddade 100644 --- a/lib/builder/webpack/base.config.js +++ b/lib/builder/webpack/base.config.js @@ -116,6 +116,20 @@ export default function webpackBaseConfig ({ isClient, isServer }) { ) } + // Workaround for hiding Warnings about plugins without a default export (#1179) + config.plugins.push({ + apply (compiler) { + compiler.plugin('done', stats => { + stats.compilation.warnings = stats.compilation.warnings.filter(warn => { + if (warn.name === 'ModuleDependencyWarning' && warn.message.includes(`export 'default'`) && warn.message.includes('plugin')) { + return false + } + return true + }) + }) + } + }) + // -------------------------------------- // Dev specific config // -------------------------------------- From 28d0e726416319fb8ed522c3ce80f124b74c2622 Mon Sep 17 00:00:00 2001 From: Sebastien Chopin Date: Fri, 28 Jul 2017 10:21:58 +0200 Subject: [PATCH 35/42] Fix context.app in client-side --- lib/app/client.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/app/client.js b/lib/app/client.js index 5c130ad6fe..30bcd02690 100644 --- a/lib/app/client.js +++ b/lib/app/client.js @@ -182,9 +182,8 @@ async function render (to, from, next) { <% if (store) { %>store,<% } %> isClient: true, next: _next.bind(this), - error: this.error.bind(this), - app - }) + error: this.error.bind(this) + }, app) this._context = context this._dateLastError = this.$options._nuxt.dateErr this._hadError = !!this.$options._nuxt.err From 5423a9b05e50117e612ed2904d537fe1294fcadb Mon Sep 17 00:00:00 2001 From: Sebastien Chopin Date: Fri, 28 Jul 2017 10:40:21 +0200 Subject: [PATCH 36/42] Bump to rc3 --- package.json | 2 +- start/package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 1644a873d6..6e03b17298 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "nuxt", - "version": "1.0.0-rc2", + "version": "1.0.0-rc3", "description": "A minimalistic framework for server-rendered Vue.js applications (inspired by Next.js)", "contributors": [ { diff --git a/start/package.json b/start/package.json index fe90240aee..49a6f394f6 100644 --- a/start/package.json +++ b/start/package.json @@ -1,6 +1,6 @@ { "name": "nuxt-start", - "version": "1.0.0-rc2", + "version": "1.0.0-rc3", "description": "runtime-only build for nuxt", "contributors": [ { From 8563c0f05fca617eb296544ac1f84f96cf470c5f Mon Sep 17 00:00:00 2001 From: Sebastien Chopin Date: Fri, 28 Jul 2017 10:40:25 +0200 Subject: [PATCH 37/42] Update to rc3 --- examples/custom-server/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/custom-server/package.json b/examples/custom-server/package.json index 9fbc00b272..fb6d0d7247 100644 --- a/examples/custom-server/package.json +++ b/examples/custom-server/package.json @@ -2,7 +2,7 @@ "name": "nuxt-custom-server", "dependencies": { "express": "^4.15.3", - "nuxt": "^1.0.0-rc1" + "nuxt": "^1.0.0-rc3" }, "scripts": { "dev": "node server.js", From 1417dae99b6fb350dff455f4ba4c0c14b09e9952 Mon Sep 17 00:00:00 2001 From: Pooya Parsa Date: Sun, 30 Jul 2017 16:17:50 +0430 Subject: [PATCH 38/42] update tapable plugins --- lib/core/module.js | 2 +- lib/core/nuxt.js | 2 +- lib/core/renderer.js | 15 +++++++-------- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/lib/core/module.js b/lib/core/module.js index 63f835fc6c..726227b8c7 100755 --- a/lib/core/module.js +++ b/lib/core/module.js @@ -18,7 +18,7 @@ export default class ModuleContainer extends Tapable { async _ready () { await sequence(this.options.modules, this.addModule.bind(this)) - await this.nuxt.applyPluginsAsync('module', this) + await this.applyPluginsAsync('ready', this) } addVendor (vendor) { diff --git a/lib/core/nuxt.js b/lib/core/nuxt.js index 92d103e997..156edcfeeb 100644 --- a/lib/core/nuxt.js +++ b/lib/core/nuxt.js @@ -74,7 +74,7 @@ export default class Nuxt extends Tapable { }) })) - resolve() + resolve(this.applyPluginsAsync('listen', { server, port, host })) }) // Add server.destroy(cb) method diff --git a/lib/core/renderer.js b/lib/core/renderer.js index f9cd1353bf..a35fc8adf3 100644 --- a/lib/core/renderer.js +++ b/lib/core/renderer.js @@ -46,14 +46,12 @@ export default class Renderer extends Tapable { spaTemplate: null, errorTemplate: parseTemplate('
{{ stack }}
') // Will be loaded on ready } - - // Bind middleware to this context - this.nuxtMiddleware = this.nuxtMiddleware.bind(this) - this.errorMiddleware = this.errorMiddleware.bind(this) } async _ready () { - // Setup all middleWare + await this.nuxt.applyPluginsAsync('renderer', this) + + // Setup nuxt middleware await this.setupMiddleware() // Load error template @@ -67,7 +65,8 @@ export default class Renderer extends Tapable { await this.loadResources() } - await this.nuxt.applyPluginsAsync('renderer', this) + // Call ready plugin + await this.applyPluginsAsync('ready', this) } async loadResources (_fs = fs) { @@ -211,10 +210,10 @@ export default class Renderer extends Tapable { }) // Finally use nuxtMiddleware - this.useMiddleware(this.nuxtMiddleware) + this.useMiddleware(this.nuxtMiddleware.bind(this)) // Error middleware for errors that occurred in middleware that declared above - this.useMiddleware(this.errorMiddleware) + this.useMiddleware(this.errorMiddleware.bind(this)) } async nuxtMiddleware (req, res, next) { From bdca7630a465591539dbcb9690da629d3c8ae787 Mon Sep 17 00:00:00 2001 From: Pooya Parsa Date: Sun, 30 Jul 2017 16:26:27 +0430 Subject: [PATCH 39/42] update module tests --- test/fixtures/module/modules/tapable/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/fixtures/module/modules/tapable/index.js b/test/fixtures/module/modules/tapable/index.js index 48fc69466f..fa5bd572ef 100644 --- a/test/fixtures/module/modules/tapable/index.js +++ b/test/fixtures/module/modules/tapable/index.js @@ -2,7 +2,7 @@ module.exports = function () { let ctr = 1 // Add hook for module - this.nuxt.plugin('module', moduleContainer => { + this.plugin('ready', moduleContainer => { this.nuxt.__module_hook = moduleContainer && ctr++ }) From be4d8c5e134b50e5f9655c7276b1e84550e5e911 Mon Sep 17 00:00:00 2001 From: Pooya Parsa Date: Sun, 30 Jul 2017 16:50:58 +0430 Subject: [PATCH 40/42] internal refactors --- lib/builder/index.js | 5 +++++ lib/common/index.js | 9 ++++++++- lib/{core => common}/options.js | 10 +++++----- lib/core/index.js | 17 ++++++++++++----- lib/core/nuxt.js | 2 +- lib/core/renderer.js | 4 ++-- 6 files changed, 33 insertions(+), 14 deletions(-) rename lib/{core => common}/options.js (96%) diff --git a/lib/builder/index.js b/lib/builder/index.js index 34547d0c2a..2f96f7f4e8 100755 --- a/lib/builder/index.js +++ b/lib/builder/index.js @@ -5,3 +5,8 @@ export default { Builder, Generator } + +export { + Builder, + Generator +} diff --git a/lib/common/index.js b/lib/common/index.js index 46498a8c10..26a5ba474a 100755 --- a/lib/common/index.js +++ b/lib/common/index.js @@ -1,5 +1,12 @@ import * as Utils from './utils' +import Options from './options' export default { - Utils + Utils, + Options +} + +export { + Utils, + Options } diff --git a/lib/core/options.js b/lib/common/options.js similarity index 96% rename from lib/core/options.js rename to lib/common/options.js index 2d58aabd3a..71b55dabcc 100755 --- a/lib/core/options.js +++ b/lib/common/options.js @@ -22,7 +22,7 @@ export default function Options (_options) { } // Apply defaults - _.defaultsDeep(options, defaultOptions) + _.defaultsDeep(options, Options.defaults) // Resolve dirs options.rootDir = (typeof options.rootDir === 'string' && options.rootDir ? options.rootDir : process.cwd()) @@ -38,7 +38,7 @@ export default function Options (_options) { // Ignore publicPath on dev /* istanbul ignore if */ if (options.dev && isUrl(options.build.publicPath)) { - options.build.publicPath = defaultOptions.build.publicPath + options.build.publicPath = Options.defaults.build.publicPath } // If store defined, update store options to true unless explicitly disabled @@ -52,7 +52,7 @@ export default function Options (_options) { mode = mode() } if (typeof mode === 'string') { - mode = Modes[mode] + mode = Options.modes[mode] } // Apply mode @@ -61,7 +61,7 @@ export default function Options (_options) { return options } -const Modes = { +Options.modes = { universal: { build: { ssr: true @@ -88,7 +88,7 @@ const Modes = { } } -export const defaultOptions = { +Options.defaults = { mode: 'universal', dev: process.env.NODE_ENV !== 'production', buildDir: '.nuxt', diff --git a/lib/core/index.js b/lib/core/index.js index 4bf8a61bf0..2af3372c2d 100755 --- a/lib/core/index.js +++ b/lib/core/index.js @@ -1,13 +1,20 @@ -import Options from './options' -import ModuleContainer from './module' +import { Options, Utils } from 'common' +import Module from './module' import Nuxt from './nuxt' import Renderer from './renderer' -import * as Utils from 'utils' export default { - Options, - ModuleContainer, Nuxt, + Module, Renderer, + Options, + Utils +} + +export { + Nuxt, + Module, + Renderer, + Options, Utils } diff --git a/lib/core/nuxt.js b/lib/core/nuxt.js index 156edcfeeb..7ef1bd4482 100644 --- a/lib/core/nuxt.js +++ b/lib/core/nuxt.js @@ -1,8 +1,8 @@ import Tapable from 'tappable' import chalk from 'chalk' +import { Options } from 'common' import ModuleContainer from './module' import Renderer from './renderer' -import Options from './options' import Debug from 'debug' import enableDestroy from 'server-destroy' import Module from 'module' diff --git a/lib/core/renderer.js b/lib/core/renderer.js index a35fc8adf3..874b2339da 100644 --- a/lib/core/renderer.js +++ b/lib/core/renderer.js @@ -11,9 +11,9 @@ import { join, resolve } from 'path' import fs from 'fs-extra' import { createBundleRenderer } from 'vue-server-renderer' import { encodeHtml, getContext, setAnsiColors, isUrl } from 'utils' -import { defaultOptions } from './options' import Debug from 'debug' import connect from 'connect' +import { Options } from 'common' const debug = Debug('nuxt:render') debug.color = 4 // Force blue color @@ -196,7 +196,7 @@ export default class Renderer extends Tapable { if (!this.options.dev) { const distDir = resolve(this.options.buildDir, 'dist') this.useMiddleware({ - path: isUrl(this.options.build.publicPath) ? defaultOptions.build.publicPath : this.options.build.publicPath, + path: isUrl(this.options.build.publicPath) ? Options.defaults.build.publicPath : this.options.build.publicPath, handler: serveStatic(distDir, { index: false, // Don't serve index.html template maxAge: (this.options.dev ? 0 : '1y') // 1 year in production From ab5b64ea67f8838721d1948b602e686aef5a8054 Mon Sep 17 00:00:00 2001 From: Pooya Parsa Date: Sun, 30 Jul 2017 16:52:39 +0430 Subject: [PATCH 41/42] enable async components tests (vue 2.4) --- test/ssr.test.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/test/ssr.test.js b/test/ssr.test.js index c3be1a519f..e45201fb04 100755 --- a/test/ssr.test.js +++ b/test/ssr.test.js @@ -62,10 +62,9 @@ test('unique responses with component', async t => { await uniqueTest(t, '/component') }) -test.todo('unique responses with async components (wait Vue 2.4)') -// test('unique responses with async components', async t => { -// await uniqueTest(t, '/asyncComponent') -// }) +test('unique responses with async components', async t => { + await uniqueTest(t, '/asyncComponent') +}) test('unique responses with asyncData()', async t => { await uniqueTest(t, '/asyncData') From 85e7f25326710f3eff293395ac1dff28950cec6a Mon Sep 17 00:00:00 2001 From: Pooya Parsa Date: Sun, 30 Jul 2017 18:42:08 +0430 Subject: [PATCH 42/42] generate -> generator --- lib/builder/generator.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/builder/generator.js b/lib/builder/generator.js index ed58526cea..8333e06cac 100644 --- a/lib/builder/generator.js +++ b/lib/builder/generator.js @@ -35,7 +35,7 @@ export default class Generator extends Tapable { await this.builder.build() } - await this.nuxt.applyPluginsAsync('generate', this) + await this.nuxt.applyPluginsAsync('generator', this) // Initialize dist directory if (init) {