Skip to content

Commit 68702b4

Browse files
committed
Functional starter code
1 parent ab1a3d6 commit 68702b4

File tree

13 files changed

+4005
-122
lines changed

13 files changed

+4005
-122
lines changed

Diff for: README.md

+4
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,7 @@ yarn run lint
2727

2828
### Customize configuration
2929
See [Configuration Reference](https://cli.vuejs.org/config/).
30+
31+
### Built with
32+
[vue-cli-plugin-netlify-lambda](https://github.com/netlify/vue-cli-plugin-netlify-lambda)
33+
[prerender-spa-plugin](https://github.com/chrisvfritz/prerender-spa-plugin)

Diff for: lambda/hello.js

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: netlify.toml

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[build]
2+
command = "yarn build"
3+
functions = "lambda"
4+
publish = "dist"

Diff for: package.json

+6-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@
88
"lint": "vue-cli-service lint"
99
},
1010
"dependencies": {
11-
"vue": "^2.6.6"
11+
"axios": "^0.18.0",
12+
"vue": "^2.6.6",
13+
"vue-router": "^3.0.1",
14+
"vuex": "^3.0.1"
1215
},
1316
"devDependencies": {
1417
"@vue/cli-plugin-babel": "^3.4.0",
@@ -17,6 +20,8 @@
1720
"babel-eslint": "^10.0.1",
1821
"eslint": "^5.8.0",
1922
"eslint-plugin-vue": "^5.0.0",
23+
"prerender-spa-plugin": "^3.4.0",
24+
"vue-cli-plugin-netlify-lambda": "^0.1.1",
2025
"vue-template-compiler": "^2.5.21"
2126
},
2227
"eslintConfig": {

Diff for: src/App.vue

+5-13
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,13 @@
11
<template>
22
<div id="app">
3-
<img alt="Vue logo" src="./assets/logo.png">
4-
<HelloWorld msg="Welcome to Your Vue.js App"/>
3+
<div id="nav">
4+
<router-link to="/">Home</router-link> |
5+
<router-link to="/about">About</router-link>
6+
</div>
7+
<router-view/>
58
</div>
69
</template>
710

8-
<script>
9-
import HelloWorld from './components/HelloWorld.vue'
10-
11-
export default {
12-
name: 'app',
13-
components: {
14-
HelloWorld
15-
}
16-
}
17-
</script>
18-
1911
<style>
2012
#app {
2113
font-family: 'Avenir', Helvetica, Arial, sans-serif;

Diff for: src/lambda/hello.js

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export function handler(event, context, callback) {
2+
console.log(event)
3+
callback(null, {
4+
statusCode: 200,
5+
body: JSON.stringify({ msg: "Hello from Netlify Lambda!" })
6+
})
7+
}

Diff for: src/main.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
import Vue from 'vue'
22
import App from './App.vue'
3+
import router from './router'
4+
import store from './store'
35

46
Vue.config.productionTip = false
57

68
new Vue({
7-
render: h => h(App),
9+
router,
10+
store,
11+
render: h => h(App)
812
}).$mount('#app')

Diff for: src/router.js

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import Vue from 'vue'
2+
import Router from 'vue-router'
3+
import Home from './views/Home.vue'
4+
5+
Vue.use(Router)
6+
7+
export default new Router({
8+
routes: [
9+
{
10+
path: '/',
11+
name: 'home',
12+
component: Home
13+
},
14+
{
15+
path: '/about',
16+
name: 'about',
17+
// route level code-splitting
18+
// this generates a separate chunk (about.[hash].js) for this route
19+
// which is lazy-loaded when the route is visited.
20+
component: () => import(/* webpackChunkName: "about" */ './views/About.vue')
21+
}
22+
],
23+
mode: 'history'
24+
})

Diff for: src/store.js

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import Vue from 'vue'
2+
import Vuex from 'vuex'
3+
import axios from 'axios'
4+
5+
Vue.use(Vuex)
6+
7+
export default new Vuex.Store({
8+
state: {
9+
msg: '',
10+
loading: false
11+
},
12+
mutations: {
13+
msg (state, msg) { state.msg = msg },
14+
loading (state, loading) { state.loading = loading }
15+
},
16+
actions: {
17+
fetchMessage ({ commit }) {
18+
commit('loading', true)
19+
axios.get('/.netlify/functions/hello')
20+
.then(({ data }) => {
21+
// Adds a 1 second delay to illustrate asyc behavior
22+
// setTimeout can/should be removed
23+
setTimeout(() => {
24+
commit('msg', data.msg)
25+
commit('loading', false)
26+
}, 1000)
27+
})
28+
.catch(() => {
29+
commit('loading', false)
30+
})
31+
}
32+
}
33+
})

Diff for: src/views/About.vue

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<template>
2+
<div class="about">
3+
<h1>This is an about page</h1>
4+
<h4>This page will be rendered statically after running <code>yarn build</code></h4>
5+
</div>
6+
</template>

Diff for: src/views/Home.vue

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<template>
2+
<div class="home">
3+
<img alt="Vue logo" src="../assets/logo.png">
4+
5+
<p>The following message was fetched from the <code>hello</code> lambda function located in <code>/src/lambda/hello.js</code></p>
6+
7+
<hr>
8+
9+
<pre v-if="loading">LOADING...</pre>
10+
<pre v-else>{{msg}}</pre>
11+
12+
</div>
13+
</template>
14+
15+
<script>
16+
// @ is an alias to /src
17+
import HelloWorld from '@/components/HelloWorld.vue'
18+
19+
export default {
20+
name: 'home',
21+
components: {
22+
HelloWorld
23+
},
24+
mounted () {
25+
this.$store.dispatch('fetchMessage')
26+
},
27+
computed: {
28+
msg () {
29+
return this.$store.state.msg
30+
},
31+
loading () {
32+
return this.$store.state.loading
33+
}
34+
}
35+
}
36+
</script>

Diff for: vue.config.js

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
const path = require('path');
2+
const PrerenderSPAPlugin = require('prerender-spa-plugin');
3+
4+
module.exports = {
5+
configureWebpack: {
6+
plugins: [
7+
new PrerenderSPAPlugin({
8+
staticDir: path.join(__dirname, 'dist'),
9+
routes: [
10+
'/',
11+
'/about',
12+
],
13+
}),
14+
],
15+
},
16+
};

0 commit comments

Comments
 (0)