Skip to content

Commit 2560bfb

Browse files
authored
Merge branch 'master' into offline-plugin-integration
2 parents ddbb4b9 + a33e94d commit 2560bfb

File tree

95 files changed

+7234
-558
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

95 files changed

+7234
-558
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# dependencies
2-
yarn.lock
32
node_modules
3+
examples/**/*/yarn.lock
44

55
# logs
66
*.log

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,17 @@
1010
<a href="https://donorbox.org/nuxt"><img src="https://img.shields.io/badge/Support%20us-donate-41B883.svg" alt="Support us"></a>
1111

1212
</p>
13+
1314
> Nuxt.js is a framework for server-rendered Vue applications (inspired by [Next.js](https://github.com/zeit/next.js))
1415
15-
## 🚧 Under active development, 1.0 will be released soon :fire:
16+
## 🚧 Under active development, [1.0](https://github.com/nuxt/nuxt.js/projects/1) will be released soon :fire:
1617

1718
## Links
1819

1920
- 📘 Documentation: [https://nuxtjs.org](https://nuxtjs.org)
2021
- 🎬 Video: [1 minute demo](https://www.youtube.com/watch?v=kmf-p-pTi40)
2122
- 🐦 Twitter: [@nuxt_js](https://twitter.com/nuxt_js)
23+
- 👉 [Play with Nuxt.js online](https://glitch.com/edit/#!/nuxt-hello-world)
2224

2325
## Getting started
2426

@@ -119,7 +121,7 @@ This is mostly used for `nuxt generate` and test purposes but you might find ano
119121
nuxt.renderRoute('/about', context)
120122
.then(function ({ html, error }) {
121123
// You can check error to know if your app displayed the error page for this route
122-
// Useful to set the correct status status code if an error appended:
124+
// Useful to set the correct status code if an error appended:
123125
if (error) {
124126
return res.status(error.statusCode || 500).send(html)
125127
}

bin/nuxt-build

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,32 @@ if (process.argv.indexOf('--analyze') !== -1 || process.argv.indexOf('-a') !== -
1515
process.argv = without(process.argv, '--analyze', '-a')
1616
}
1717

18+
var nuxtConfigFileName = 'nuxt.config.js'
19+
20+
// --config-file option
21+
var indexOfConfig = false
22+
if (process.argv.indexOf('--config-file') !== -1) {
23+
indexOfConfig = process.argv.indexOf('--config-file')
24+
} else if (process.argv.indexOf('-c') !== -1) {
25+
indexOfConfig = process.argv.indexOf('-c')
26+
}
27+
28+
if (indexOfConfig !== false) {
29+
nuxtConfigFileName = process.argv.slice(indexOfConfig)[1]
30+
process.argv = without(process.argv, '--config-file', '-c', nuxtConfigFileName)
31+
}
32+
33+
// Root directory parameter
1834
var rootDir = resolve(process.argv.slice(2)[0] || '.')
19-
var nuxtConfigFile = resolve(rootDir, 'nuxt.config.js')
35+
var nuxtConfigFilePath = resolve(rootDir, nuxtConfigFileName)
2036

2137
var options = {}
22-
if (fs.existsSync(nuxtConfigFile)) {
23-
options = require(nuxtConfigFile)
38+
if (fs.existsSync(nuxtConfigFilePath)) {
39+
options = require(nuxtConfigFilePath)
40+
} else {
41+
console.log(`Could not locate ${nuxtConfigFilePath}`) // eslint-disable-line no-console
2442
}
43+
2544
if (typeof options.rootDir !== 'string') {
2645
options.rootDir = rootDir
2746
}

bin/nuxt-dev

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,6 @@ function listenOnConfigChanges (nuxt, server) {
6363
})
6464
}, 200)
6565
var nuxtConfigFile = resolve(rootDir, 'nuxt.config.js')
66-
chokidar.watch(nuxtConfigFile, { ignoreInitial: true })
66+
chokidar.watch(nuxtConfigFile, Object.assign({}, nuxt.options.watchers.chokidar, { ignoreInitial: true }))
6767
.on('all', build)
6868
}

examples/async-data/pages/index.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
<script>
1111
export default {
12-
data ({ req }, callback) {
12+
asyncData ({ req }, callback) {
1313
setTimeout(function () {
1414
// callback(err, data)
1515
callback(null, {

examples/async-data/pages/posts/_id.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import axios from 'axios'
1212
1313
export default {
14-
async data ({ params }) {
14+
async asyncData ({ params }) {
1515
// We can use async/await ES6 feature
1616
let { data } = await axios.get(`https://jsonplaceholder.typicode.com/posts/${params.id}`)
1717
return { post: data }

examples/async-data/pages/posts/index.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
import axios from 'axios'
1616
1717
export default {
18-
data ({ req, params }) {
18+
asyncData ({ req, params }) {
1919
// We can return a Promise instead of calling the callback
2020
return axios.get('https://jsonplaceholder.typicode.com/posts')
2121
.then((res) => {

examples/custom-layouts/pages/about.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<script>
99
export default {
1010
layout: 'dark',
11-
data ({ req }) {
11+
asyncData ({ req }) {
1212
return {
1313
name: req ? 'server' : 'client'
1414
}

examples/custom-loading/pages/about.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
<script>
99
export default {
10-
data () {
10+
asyncData () {
1111
return new Promise((resolve) => {
1212
setTimeout(function () {
1313
resolve({})

examples/custom-loading/pages/index.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
<script>
99
export default {
10-
data () {
10+
asyncData () {
1111
return new Promise((resolve) => {
1212
setTimeout(function () {
1313
resolve({ name: 'world' })

examples/custom-routes/pages/index.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import axios from 'axios'
1414
1515
export default {
16-
data () {
16+
asyncData () {
1717
return axios.get('https://jsonplaceholder.typicode.com/users')
1818
.then((res) => {
1919
return { users: res.data }

examples/custom-routes/pages/users/_id.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export default {
1414
validate ({ params }) {
1515
return !isNaN(+params.id)
1616
},
17-
data ({ params, error }) {
17+
asyncData ({ params, error }) {
1818
return axios.get(`https://jsonplaceholder.typicode.com/users/${+params.id}`)
1919
.then((res) => res.data)
2020
.catch(() => {

examples/dynamic-layouts/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Dynamic Layouts
2+
3+
https://nuxtjs.org/examples/layouts
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<template>
2+
<div class="container">
3+
<h1 v-if="error.statusCode === 404">Page not found</h1>
4+
<h1 v-else>An error occured</h1>
5+
<nuxt-link to="/">Home page</nuxt-link>
6+
</div>
7+
</template>
8+
9+
<script>
10+
export default {
11+
layout: ({ isMobile }) => isMobile ? 'mobile' : 'default',
12+
props: ['error']
13+
}
14+
</script>
15+
16+
<style scoped>
17+
.container {
18+
font-family: sans-serif;
19+
padding-top: 10%;
20+
text-align: center;
21+
}
22+
h1 {
23+
font-size: 20px;
24+
}
25+
</style>
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<template>
2+
<div class="dark">
3+
<div class="mobile-banner">Mobile website</div>
4+
<nuxt/>
5+
</div>
6+
</template>
7+
8+
<style>
9+
* {
10+
box-sizing: border-box;
11+
}
12+
.dark {
13+
position: absolute;
14+
top: 0;
15+
left: 0;
16+
width: 100%;
17+
min-height: 100%;
18+
background: black;
19+
color: white;
20+
padding: 10px;
21+
padding-top: 40px;
22+
}
23+
.dark a {
24+
color: white;
25+
}
26+
.mobile-banner {
27+
position: absolute;
28+
top: 0;
29+
left: 0;
30+
width: 100%;
31+
text-align: center;
32+
padding: 10px;
33+
background: #333;
34+
font-family: sans-serif;
35+
font-size: 13px;
36+
}
37+
</style>
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export default function (ctx) {
2+
let userAgent = ctx.req ? ctx.req.headers['user-agent'] : navigator.userAgent
3+
ctx.isMobile = /mobile/i.test(userAgent)
4+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
module.exports = {
2+
head: {
3+
meta: [
4+
{ content: 'width=device-width,initial-scale=1', name: 'viewport' }
5+
]
6+
},
7+
router: {
8+
middleware: ['mobile']
9+
}
10+
}

examples/dynamic-layouts/package.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"name": "nuxt-dynamic-layouts",
3+
"dependencies": {
4+
"nuxt": "latest"
5+
},
6+
"scripts": {
7+
"dev": "nuxt",
8+
"build": "nuxt build",
9+
"start": "nuxt start"
10+
}
11+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<template>
2+
<div>
3+
<p>Hi from {{ name }}</p>
4+
<nuxt-link to="/">Home page</nuxt-link>
5+
</div>
6+
</template>
7+
8+
<script>
9+
export default {
10+
layout: ({ isMobile }) => isMobile ? 'mobile' : 'default',
11+
asyncData ({ req }) {
12+
return {
13+
name: req ? 'server' : 'client'
14+
}
15+
}
16+
}
17+
</script>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<template>
2+
<div class="container">
3+
<h1>Welcome!</h1>
4+
<nuxt-link to="/about">About page</nuxt-link>
5+
</div>
6+
</template>
7+
8+
<script>
9+
export default {
10+
layout: ({ isMobile }) => isMobile ? 'mobile' : 'default',
11+
}
12+
</script>
4.15 KB
Loading

examples/global-css/package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
{
22
"name": "nuxt-global-css",
33
"dependencies": {
4-
"bulma": "^0.2.3",
5-
"hover.css": "^2.0.2",
6-
"node-sass": "^3.11.2",
7-
"nuxt": "latest",
8-
"sass-loader": "^4.0.2"
4+
"bulma": "^0.4.0",
5+
"hover.css": "^2.2.0",
6+
"node-sass": "^4.5.1",
7+
"nuxt": "^0.10.0",
8+
"sass-loader": "^6.0.3"
99
},
1010
"scripts": {
1111
"dev": "nuxt",

examples/head-elements/components/twitter-head-card.vue

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,3 @@ export default {
2020
}
2121
}
2222
</script>
23-
24-
<style lang="css">
25-
</style>

examples/hello-world-jsx/package.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"name": "hello-nuxt-jsx",
3+
"dependencies": {
4+
"nuxt": "latest"
5+
},
6+
"scripts": {
7+
"dev": "nuxt",
8+
"build": "nuxt build",
9+
"start": "nuxt start"
10+
}
11+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<script>
2+
export default {
3+
asyncData ({ req }) {
4+
return {
5+
name: req ? 'server' : 'client'
6+
}
7+
},
8+
render (h) {
9+
return <div>
10+
<p>Hi from {this.name}</p>
11+
<nuxt-link to="/">Home page</nuxt-link>
12+
</div>
13+
}
14+
}
15+
</script>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<script>
2+
export default {
3+
render (h) {
4+
return <div>
5+
<h1>Welcome!</h1>
6+
<nuxt-link to="/about">About page</nuxt-link>
7+
</div>
8+
}
9+
}
10+
</script>

examples/hello-world/pages/about.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
<script>
99
export default {
10-
data ({ req }) {
10+
asyncData ({ req }) {
1111
return {
1212
name: req ? 'server' : 'client'
1313
}

examples/middleware/pages/_slug.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
<script>
1313
export default {
14-
data ({ store, route, userAgent }) {
14+
asyncData ({ store, route, userAgent }) {
1515
return {
1616
userAgent,
1717
slugs: [

examples/nested-routes/pages/index.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
<script>
1818
export default {
19-
data ({ env }) {
19+
asyncData ({ env }) {
2020
return { users: env.users }
2121
}
2222
}

examples/nested-routes/pages/index/_id.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export default {
1010
validate ({ params }) {
1111
return !isNaN(+params.id)
1212
},
13-
data ({ params, env, error }) {
13+
asyncData ({ params, env, error }) {
1414
const user = env.users.find((user) => String(user.id) === params.id)
1515
if (!user) {
1616
return error({ message: 'User not found', statusCode: 404 })

examples/plugins-vendor/nuxt.config.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ module.exports = {
33
vendor: ['axios', 'mini-toastr', 'vue-notifications']
44
},
55
plugins: [
6-
'~plugins/vue-notifications.js'
6+
// ssr: false to only include it on client-side
7+
{ src: '~plugins/vue-notifications.js', ssr: false }
78
]
89
}

examples/plugins-vendor/pages/about.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import axios from 'axios'
1010
1111
export default {
12-
data () {
12+
asyncData () {
1313
return axios.get('https://jsonplaceholder.typicode.com/photos/4').then(res => res.data)
1414
}
1515
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy