From 247b53c3c3485e5711b48a069d7b2fefa93cfb9d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20Chopin?=
Date: Sun, 25 Dec 2016 19:08:30 +0100
Subject: [PATCH 01/27] Update README.md
---
README.md | 33 +++++++--------------------------
1 file changed, 7 insertions(+), 26 deletions(-)
diff --git a/README.md b/README.md
index b64f6dcd1c..59ea3b8dc2 100644
--- a/README.md
+++ b/README.md
@@ -60,32 +60,20 @@ So far, we get:
- Automatic transpilation and bundling (with webpack and babel)
- Hot code reloading
-- Server rendering and indexing of `./pages`
+- Server rendering and indexing of `pages/`
- Static file serving. `./static/` is mapped to `/`
-- Config file `nuxt.config.js`
+- Configurable with a `nuxt.config.js` file
+- Custom layouts with the `layouts/` directory
- Code splitting via webpack
## Using nuxt.js programmatically
-Nuxt is built on the top of ES2015, which makes the code more enjoyable and cleaner to read. It doesn't make use of any transpilers and depends upon Core V8 implemented features.
-For these reasons, nuxt.js targets Node.js `4.0` or higher (you might want to launch node with the `--harmony-proxies` flag if you running `node <= 6.5.0` )
-
```js
const Nuxt = require('nuxt')
-const options = {
- routes: [], // see examples/custom-routes
- css: ['/dist/bootstrap.css'] // see examples/global-css
- store: true // see examples/vuex-store
- plugins: ['public/plugin.js'], // see examples/plugins-vendor
- loading: false or { color: 'blue', failedColor: 'red' } or 'components/my-spinner' // see examples/custom-loading
- build: {
- vendor: ['axios'] // see examples/plugins-vendor
- }
-}
-
// Launch nuxt build with given options
-let nuxt = new Nuxt(options)
+let config = require('./nuxt.config.js')
+let nuxt = new Nuxt(config)
nuxt.build()
.then(() => {
// You can use nuxt.render(req, res) or nuxt.renderRoute(route, context)
@@ -106,7 +94,7 @@ app.use(nuxt.render)
## Render a specific route
-This is mostly used for tests purpose but who knows!
+This is mostly used for `nuxt generate` and tests purposes but you might found another utility!
```js
nuxt.renderRoute('/about', context)
@@ -125,14 +113,7 @@ nuxt.renderRoute('/about', context)
## Examples
-Please take a look at the examples/ folder.
-If you want to launch one example to see it live:
-
-```bash
-cd node_modules/nuxt/
-bin/nuxt examples/hello-world
-# Go to http://localhost:3000
-```
+Please take a look at the [examples/](https://github.com/nuxt/nuxt.js/tree/master/examples) directory.
## Production deployment
From eb5f7b87db3b9d415be2779298a1ff4f29fd0b95 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20Chopin?=
Date: Sun, 25 Dec 2016 19:15:50 +0100
Subject: [PATCH 02/27] Update README.md
---
README.md | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/README.md b/README.md
index 59ea3b8dc2..6b44724f09 100644
--- a/README.md
+++ b/README.md
@@ -9,13 +9,15 @@
> Nuxt.js is a minimalistic framework for server-rendered Vue applications (inspired by [Next.js](https://github.com/zeit/next.js))
-## 🚧 Under development, 1.0 will be released soon :fire:
+## 🚧 Under active development, 1.0 will be released soon :fire:
-## 🎬 Video: [1 minute demo](https://www.youtube.com/watch?v=kmf-p-pTi40)
+## Links
-## 🐦 Twitter: [@nuxt_js](https://twitter.com/nuxt_js)
+- 📘 Documentation: [https://nuxtjs.org](https://nuxtjs.org)
+- 🎬 Video: [1 minute demo]()
+- 🐦 Twitter: [@nuxt_js](https://twitter.com/nuxt_js)
-## 📓 How to use
+## Getting started
```
$ npm install nuxt --save
From 5e6703484ff6d6537a987098241d70c1c772a923 Mon Sep 17 00:00:00 2001
From: pi0
Date: Sun, 25 Dec 2016 23:20:55 +0330
Subject: [PATCH 03/27] handle dash in layout filenames. Fixes #78
---
lib/app/App.vue | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lib/app/App.vue b/lib/app/App.vue
index da80cc8910..d58cd6d58d 100644
--- a/lib/app/App.vue
+++ b/lib/app/App.vue
@@ -9,7 +9,7 @@ let layouts = {
<%
var layoutsKeys = Object.keys(layouts);
layoutsKeys.forEach(function (key, i) { %>
- _<%= key %>: process.BROWSER_BUILD ? () => System.import('<%= layouts[key] %>') : require('<%= layouts[key] %>')<%= (i + 1) < layoutsKeys.length ? ',' : '' %>
+ "_<%= key %>": process.BROWSER_BUILD ? () => System.import('<%= layouts[key] %>') : require('<%= layouts[key] %>')<%= (i + 1) < layoutsKeys.length ? ',' : '' %>
<% }) %>
}
From 86fba7ae777bb603f2c280a227104d538db79a64 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20Chopin?=
Date: Sun, 25 Dec 2016 21:09:14 +0100
Subject: [PATCH 04/27] Add test for layout with dash
---
test/fixtures/with-config/layouts/custom-env.vue | 6 ++++++
test/fixtures/with-config/pages/env.vue | 1 +
test/with-config.test.js | 1 +
3 files changed, 8 insertions(+)
create mode 100644 test/fixtures/with-config/layouts/custom-env.vue
diff --git a/test/fixtures/with-config/layouts/custom-env.vue b/test/fixtures/with-config/layouts/custom-env.vue
new file mode 100644
index 0000000000..7f82cac1ca
--- /dev/null
+++ b/test/fixtures/with-config/layouts/custom-env.vue
@@ -0,0 +1,6 @@
+
+
+
Custom env layout
+
+
+
diff --git a/test/fixtures/with-config/pages/env.vue b/test/fixtures/with-config/pages/env.vue
index 08ab5daca5..9785f3ab19 100644
--- a/test/fixtures/with-config/pages/env.vue
+++ b/test/fixtures/with-config/pages/env.vue
@@ -4,6 +4,7 @@
diff --git a/test/fixtures/basic/pages/callback-async-data.vue b/test/fixtures/basic/pages/callback-async-data.vue
new file mode 100644
index 0000000000..03194c28fd
--- /dev/null
+++ b/test/fixtures/basic/pages/callback-async-data.vue
@@ -0,0 +1,13 @@
+
+ {{ name }}
+
+
+
From 05a66e0cbac07de0adef56efa8ecdb32ff620ac7 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20Chopin?=
Date: Tue, 27 Dec 2016 16:57:50 +0100
Subject: [PATCH 17/27] Update async-data example
---
examples/async-data/README.md | 15 ++++++-
examples/async-data/pages/index.vue | 17 +++++---
examples/async-data/pages/post.vue | 35 ---------------
examples/async-data/pages/posts/_id.vue | 52 ++++++++++++++++++++++
examples/async-data/pages/posts/index.vue | 53 +++++++++++++++++++++++
5 files changed, 130 insertions(+), 42 deletions(-)
delete mode 100644 examples/async-data/pages/post.vue
create mode 100644 examples/async-data/pages/posts/_id.vue
create mode 100644 examples/async-data/pages/posts/index.vue
diff --git a/examples/async-data/README.md b/examples/async-data/README.md
index f76d4b3d51..4dcfa52a19 100644
--- a/examples/async-data/README.md
+++ b/examples/async-data/README.md
@@ -6,10 +6,11 @@
`data` is called every time before loading the component (*only if attached to a route*). It can be called from the server-side or before navigating to the corresponding route.
-The `data` method receives the context as the first argument, you can use it to fetch some data and return the component data. To make the data method asynchronous, Nuxt.js offers you 2 ways, choose the one you're the most familiar with:
+The `data` method receives the context as the first argument, you can use it to fetch some data and return the component data. To make the data method asynchronous, Nuxt.js offers you different ways, choose the one you're the most familiar with:
1. returning a `Promise`, Nuxt.js will wait for the promise to be resolved before rendering the Component
-2. Define a second argument which is a callback method to be called like this: `callback(err, data)`
+2. Using the async/await ES7 feature
+3. Define a second argument which is a callback method to be called like this: `callback(err, data)`
Example with returning a `Promise`:
```js
@@ -23,6 +24,16 @@ export default {
}
```
+Example with using `async/await`:
+```js
+export default {
+ async data ({ params }) {
+ let { data } = axios.get(`https://my-api/posts/${params.id}`)
+ return { title: data.title }
+ }
+}
+```
+
Example with using the `callback` argument:
```js
export default {
diff --git a/examples/async-data/pages/index.vue b/examples/async-data/pages/index.vue
index ab51ddce0b..387a5725e5 100644
--- a/examples/async-data/pages/index.vue
+++ b/examples/async-data/pages/index.vue
@@ -1,8 +1,9 @@
-
+
+
User Agent
{{ userAgent }}
-
See a post (http request / Ajax)
+
Blog
@@ -20,10 +21,16 @@ export default {
diff --git a/examples/async-data/pages/post.vue b/examples/async-data/pages/post.vue
deleted file mode 100644
index 1c5a11ad45..0000000000
--- a/examples/async-data/pages/post.vue
+++ /dev/null
@@ -1,35 +0,0 @@
-
-
-
-
{{ post.title }}!
-
Back home
-
-
-
-
-
-
diff --git a/examples/async-data/pages/posts/_id.vue b/examples/async-data/pages/posts/_id.vue
new file mode 100644
index 0000000000..b8c2713e20
--- /dev/null
+++ b/examples/async-data/pages/posts/_id.vue
@@ -0,0 +1,52 @@
+
+
+
+
{{ post.title }}
+
{{ post.body }}
+
Back to the list
+
+
+
+
+
+
diff --git a/examples/async-data/pages/posts/index.vue b/examples/async-data/pages/posts/index.vue
new file mode 100644
index 0000000000..c11a3de8d3
--- /dev/null
+++ b/examples/async-data/pages/posts/index.vue
@@ -0,0 +1,53 @@
+
+
+
+
Blog
+
+
Back to home page
+
+
+
+
+
+
From 0a3577b4c05012da6a817259bfed35f3a7050a47 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20Chopin?=
Date: Tue, 27 Dec 2016 16:58:07 +0100
Subject: [PATCH 18/27] Use async/await in vue files
---
lib/build/webpack/vue-loader.config.js | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/lib/build/webpack/vue-loader.config.js b/lib/build/webpack/vue-loader.config.js
index 53d42bdcac..6cb550f9c6 100644
--- a/lib/build/webpack/vue-loader.config.js
+++ b/lib/build/webpack/vue-loader.config.js
@@ -4,6 +4,10 @@ const { defaults } = require('lodash')
module.exports = function () {
let babelOptions = JSON.stringify(defaults(this.options.build.babel, {
+ plugins: [
+ 'transform-async-to-generator',
+ 'transform-runtime'
+ ],
presets: [
['es2015', { modules: false }],
'stage-2'
From 0e1f0af3b9d6fb04a0be0f76c5b91194db8e6850 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20Chopin?=
Date: Tue, 27 Dec 2016 17:02:03 +0100
Subject: [PATCH 19/27] Fix hot-reload on data
---
lib/app/client.js | 1 +
1 file changed, 1 insertion(+)
diff --git a/lib/app/client.js b/lib/app/client.js
index 13409b560c..5d57ca8ae3 100644
--- a/lib/app/client.js
+++ b/lib/app/client.js
@@ -216,6 +216,7 @@ function hotReloadAPI (_app) {
})
promises.push(p)
} else if (Component._cData) {
+ Component._data = Component.options.data
Component.options.data = Component._cData
Component._Ctor.options.data = Component.options.data
}
From 5d82cf3d681e506633bba4299c60b2b0a3a90683 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20Chopin?=
Date: Tue, 27 Dec 2016 17:04:13 +0100
Subject: [PATCH 20/27] Update README.md
---
examples/async-data/README.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/examples/async-data/README.md b/examples/async-data/README.md
index 4dcfa52a19..73cc267fd9 100644
--- a/examples/async-data/README.md
+++ b/examples/async-data/README.md
@@ -28,7 +28,7 @@ Example with using `async/await`:
```js
export default {
async data ({ params }) {
- let { data } = axios.get(`https://my-api/posts/${params.id}`)
+ let { data } = await axios.get(`https://my-api/posts/${params.id}`)
return { title: data.title }
}
}
From 6cda84ed494afe348d9b2a9769abb28498161cc8 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20Chopin?=
Date: Tue, 27 Dec 2016 17:06:15 +0100
Subject: [PATCH 21/27] Update README.md
---
examples/async-data/README.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/examples/async-data/README.md b/examples/async-data/README.md
index 73cc267fd9..d6e372660f 100644
--- a/examples/async-data/README.md
+++ b/examples/async-data/README.md
@@ -9,7 +9,7 @@
The `data` method receives the context as the first argument, you can use it to fetch some data and return the component data. To make the data method asynchronous, Nuxt.js offers you different ways, choose the one you're the most familiar with:
1. returning a `Promise`, Nuxt.js will wait for the promise to be resolved before rendering the Component
-2. Using the async/await ES7 feature
+2. Using the ES7 `async` method with `await`
3. Define a second argument which is a callback method to be called like this: `callback(err, data)`
Example with returning a `Promise`:
From 42a3b007514eea3e87a4bd0c083dad6524ecfead Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20Chopin?=
Date: Tue, 27 Dec 2016 17:07:50 +0100
Subject: [PATCH 22/27] Bump version to 0.9.5
---
package.json | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/package.json b/package.json
index 771ecc8b96..bed0bbe4c1 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "nuxt",
- "version": "0.9.4",
+ "version": "0.9.5",
"description": "A minimalistic framework for server-rendered Vue.js applications (inspired by Next.js)",
"contributors": [
{
From 4adddd9cf65c11fb2f36c79ce05717bc64b21094 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20Chopin?=
Date: Tue, 27 Dec 2016 17:16:05 +0100
Subject: [PATCH 23/27] Add video
---
README.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/README.md b/README.md
index 6b44724f09..55600d23dd 100644
--- a/README.md
+++ b/README.md
@@ -14,7 +14,7 @@
## Links
- 📘 Documentation: [https://nuxtjs.org](https://nuxtjs.org)
-- 🎬 Video: [1 minute demo]()
+- 🎬 Video: [1 minute demo](https://www.youtube.com/watch?v=kmf-p-pTi40)
- 🐦 Twitter: [@nuxt_js](https://twitter.com/nuxt_js)
## Getting started
From aa1df39142ca238801f6d46768a0807847f5b6f0 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20Chopin?=
Date: Tue, 27 Dec 2016 17:39:08 +0100
Subject: [PATCH 24/27] remove ES7
---
examples/async-data/README.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/examples/async-data/README.md b/examples/async-data/README.md
index d6e372660f..da146f2c9a 100644
--- a/examples/async-data/README.md
+++ b/examples/async-data/README.md
@@ -9,7 +9,7 @@
The `data` method receives the context as the first argument, you can use it to fetch some data and return the component data. To make the data method asynchronous, Nuxt.js offers you different ways, choose the one you're the most familiar with:
1. returning a `Promise`, Nuxt.js will wait for the promise to be resolved before rendering the Component
-2. Using the ES7 `async` method with `await`
+2. Using the [async/await proposal](https://github.com/lukehoban/ecmascript-asyncawait)
3. Define a second argument which is a callback method to be called like this: `callback(err, data)`
Example with returning a `Promise`:
From f4ca19ee73f30566c6a284cba7dbda96ca6a56bb Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20Chopin?=
Date: Wed, 28 Dec 2016 12:37:50 +0100
Subject: [PATCH 25/27] Add post link for async/await
---
examples/async-data/README.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/examples/async-data/README.md b/examples/async-data/README.md
index da146f2c9a..04772360f8 100644
--- a/examples/async-data/README.md
+++ b/examples/async-data/README.md
@@ -9,7 +9,7 @@
The `data` method receives the context as the first argument, you can use it to fetch some data and return the component data. To make the data method asynchronous, Nuxt.js offers you different ways, choose the one you're the most familiar with:
1. returning a `Promise`, Nuxt.js will wait for the promise to be resolved before rendering the Component
-2. Using the [async/await proposal](https://github.com/lukehoban/ecmascript-asyncawait)
+2. Using the [async/await proposal](https://github.com/lukehoban/ecmascript-asyncawait) ([learn more about it]([learn more about it](https://zeit.co/blog/async-and-await))
3. Define a second argument which is a callback method to be called like this: `callback(err, data)`
Example with returning a `Promise`:
From f808892b6862d6776383276fc368dc46fb3e2499 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20Chopin?=
Date: Wed, 28 Dec 2016 12:38:09 +0100
Subject: [PATCH 26/27] Use isJSON: true for better perf and security
---
lib/views/app.html | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lib/views/app.html b/lib/views/app.html
index 9f09d0c9e6..68dd228aa4 100644
--- a/lib/views/app.html
+++ b/lib/views/app.html
@@ -12,7 +12,7 @@
>
<%= APP %>
-
+
From c4c3e74e4e06c2a45e4f249cb74cab45a969696e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20Chopin?=
Date: Fri, 30 Dec 2016 12:17:52 +0100
Subject: [PATCH 27/27] Update tests with ava
---
examples/with-ava/package.json | 7 +++-
examples/with-ava/pages/index.vue | 6 ++--
examples/with-ava/test/index.test.js | 49 ++++++++++++----------------
3 files changed, 28 insertions(+), 34 deletions(-)
diff --git a/examples/with-ava/package.json b/examples/with-ava/package.json
index 248e6b34eb..e05b6c01f1 100755
--- a/examples/with-ava/package.json
+++ b/examples/with-ava/package.json
@@ -1,11 +1,16 @@
{
"name": "nuxt-with-ava",
"scripts": {
- "start": "../../bin/nuxt .",
+ "dev": "nuxt",
+ "build": "nuxt build",
+ "start": "nuxt start",
"test": "ava"
},
"devDependencies": {
"ava": "^0.16.0",
"jsdom": "^9.8.3"
+ },
+ "dependencies": {
+ "nuxt": "^0.9.5"
}
}
diff --git a/examples/with-ava/pages/index.vue b/examples/with-ava/pages/index.vue
index cac2fde6a3..a3d80ae170 100755
--- a/examples/with-ava/pages/index.vue
+++ b/examples/with-ava/pages/index.vue
@@ -1,7 +1,5 @@
-
+ Hello {{ name }}!
diff --git a/examples/with-ava/test/index.test.js b/examples/with-ava/test/index.test.js
index c19d0a692c..21c25e9320 100755
--- a/examples/with-ava/test/index.test.js
+++ b/examples/with-ava/test/index.test.js
@@ -1,48 +1,39 @@
-/*
-** Test with Ava can be written in ES6 \o/
-*/
import test from 'ava'
-import { createServer } from 'http'
+import Nuxt from 'nuxt'
import { resolve } from 'path'
+// We keep the nuxt and server instance
+// So we can close them at the end of the test
let nuxt = null
let server = null
-// Init nuxt.js and create server listening on localhost:4000
-test.before('Init Nuxt.js', (t) => {
- const Nuxt = require('../../../')
- const options = {
- rootDir: resolve(__dirname, '..'),
- dev: false
- }
- nuxt = new Nuxt(options)
- return nuxt.build()
- .then(function () {
- server = createServer((req, res) => nuxt.render(req, res))
- server.listen(4000, 'localhost')
- })
+// Init Nuxt.js and create a server listening on localhost:4000
+test.before('Init Nuxt.js', async t => {
+ const rootDir = resolve(__dirname, '..')
+ let config = {}
+ try { config = require(resolve(rootDir, 'nuxt.config.js')) } catch (e) {}
+ config.rootDir = rootDir // project folder
+ config.dev = false // production build
+ nuxt = new Nuxt(config)
+ await nuxt.build()
+ server = new nuxt.Server(nuxt)
+ server.listen(4000, 'localhost')
})
-/*
-** Example of testing only the html
-*/
+// Example of testing only generated html
test('Route / exits and render HTML', async t => {
let context = {}
const { html } = await nuxt.renderRoute('/', context)
- t.true(html.includes('Hello world!
'))
- t.is(context.nuxt.error, null)
- t.is(context.nuxt.data[0].name, 'world')
+ t.true(html.includes('Hello world!
'))
})
-/*
-** Example of testing via dom checking
-*/
-test('Route / exits and render HTML', async t => {
+// Example of testing via dom checking
+test('Route / exits and render HTML with CSS applied', async t => {
const window = await nuxt.renderAndGetWindow('http://localhost:4000/')
- const element = window.document.querySelector('.red-color')
+ const element = window.document.querySelector('.red')
t.not(element, null)
t.is(element.textContent, 'Hello world!')
- t.is(element.className, 'red-color')
+ t.is(element.className, 'red')
t.is(window.getComputedStyle(element).color, 'red')
})