Skip to content

Commit

Permalink
Init with official example
Browse files Browse the repository at this point in the history
  • Loading branch information
CKGrafico committed Nov 29, 2017
1 parent ac5a852 commit 738f08a
Show file tree
Hide file tree
Showing 13 changed files with 1,212 additions and 0 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Using typescript within nuxt.js

https://github.com/johnlindquist/nuxt-typescript-starter/
4 changes: 4 additions & 0 deletions assets/css/main.css

Large diffs are not rendered by default.

22 changes: 22 additions & 0 deletions components/Card.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<template>
<div class="ba b--black-20 mw5 ma2">
<img :src="'https://robots.johnlindquist.com/' + person.first_name + '_' + person.last_name" />
<div class="flex flex-column items-center pa2 b--black-20">
<div class="f4">{{person.first_name}} {{person.last_name}}</div>
<button @click="select(person.id)" class="w-100 bg-blue dim mv2 pv2 bn pointer">Select</button>
</div>
</div>
</template>
// **PLEASE NOTE** All "Nuxt Class Components" require at minimum a script tag that exports a default object
<script lang="ts">
import Vue from 'vue'
import Component from 'nuxt-class-component'
import { Prop } from 'vue-property-decorator'
import { Action } from 'vuex-class'
@Component({})
export default class Card extends Vue {
@Prop() person
@Action select
}
</script>
5 changes: 5 additions & 0 deletions layouts/default.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<template>
<div class="container">
<nuxt/>
</div>
</template>
26 changes: 26 additions & 0 deletions modules/typescript.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
module.exports = function (options) {
// Extend build
this.extendBuild(config => {
const tsLoader = {
loader: 'ts-loader',
options: {
appendTsSuffixTo: [/\.vue$/]
}
}
// Add TypeScript loader
config.module.rules.push(
Object.assign(
{
test: /((client|server)\.js)|(\.tsx?)$/
},
tsLoader
)
)
// Add TypeScript loader for vue files
for (let rule of config.module.rules) {
if (rule.loader === 'vue-loader') {
rule.options.loaders.ts = tsLoader
}
}
})
}
26 changes: 26 additions & 0 deletions nuxt.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
module.exports = {
env: {
baseUrl: process.env.BASE_URL || 'http://localhost:3000'
},
head: {
title: 'starter',
meta: [
{ charset: 'utf-8' },
{ name: 'viewport', content: 'width=device-width, initial-scale=1' },
{ hid: 'description', name: 'description', content: 'Nuxt.js project' }
],
link: [{ rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' }]
},
/*
** Customize the progress-bar color
*/
loading: { color: '#3B8070' },
/*
** Build configuration
*/
css: ['tachyons/css/tachyons.min.css', '~/assets/css/main.css'],
build: {
vendor: ['axios', 'gsap', 'vuex-class', 'nuxt-class-component']
},
modules: ['~/modules/typescript']
}
27 changes: 27 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"version": "1.0.1",
"private": true,
"dependencies": {
"axios": "^0.16.1",
"gsap": "^1.19.1",
"nuxt": "latest",
"nuxt-class-component": "^1.0.3",
"tachyons": "^4.7.0",
"vue": "~2.5.1",
"vue-server-renderer": "~2.5.1",
"vue-template-compiler": "~2.5.1",
"vue-class-component": "^6.0.0",
"vue-property-decorator": "^6.0.0",
"vuex-class": "^0.3.0"
},
"scripts": {
"dev": "nuxt",
"build": "nuxt build",
"start": "nuxt start",
"generate": "nuxt generate"
},
"devDependencies": {
"ts-loader": "^3.0.0",
"typescript": "^2.2.2"
}
}
32 changes: 32 additions & 0 deletions pages/index.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<template>
<section class="pa4">
<div class="bg-white-90 pa4">
<div class="f1">Nuxt TypeScript Starter</div>
<div class="f3">Selected Person: {{selectedPerson.first_name}} {{selectedPerson.last_name}}</div>
{{selected}}
</div>
<div class="flex flex-wrap ph2 justify-between bg-white-80">
<div v-for="person in people" :key="person.id">
<Card :person="person"></Card>
</div>
</div>
</section>
</template>

<script lang="ts">
import Vue from 'vue'
import Component from 'nuxt-class-component'
import Card from '~/components/Card'
import { State, Getter } from 'vuex-class'
@Component({
components: {
Card
}
})
export default class extends Vue {
@State selected
@State people
@Getter selectedPerson
}
</script>
5 changes: 5 additions & 0 deletions plugins/axios.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import axios from 'axios'

export default axios.create({
baseURL: process.env.baseUrl
})
Binary file added static/favicon.ico
Binary file not shown.
1,000 changes: 1,000 additions & 0 deletions static/random-data.json

Large diffs are not rendered by default.

33 changes: 33 additions & 0 deletions store/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import axios from "~/plugins/axios";

export const state = () => ({
selected: 1,
people: []
});

export const mutations = {
select(state, id) {
state.selected = id;
},
setPeople(state, people) {
state.people = people;
}
};

export const getters = {
selectedPerson: state => {
const p = state.people.find(person => person.id === state.selected);
return p ? p : { first_name: "Please,", last_name: "select someone" };
}
};

export const actions = {
async nuxtServerInit({ commit }) {
const response = await axios.get("/random-data.json");
const people = response.data.slice(0, 10);
commit("setPeople", people);
},
select({ commit }, id) {
commit("select", id);
}
};
29 changes: 29 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"compilerOptions": {
"target": "es5",
"lib": [
"dom",
"es2015"
],
"module": "es2015",
"moduleResolution": "node",
"experimentalDecorators": true,
"noImplicitAny": false,
"noImplicitThis": false,
"strictNullChecks": true,
"removeComments": true,
"suppressImplicitAnyIndexErrors": true,
"allowSyntheticDefaultImports": true,
"baseUrl": ".",
"allowJs": true,
"paths": {
"~/": ["./"],
"~/assets/*": ["./assets/*"],
"~/components/*": ["./components/*"],
"~/middleware/*": ["./middleware/*"],
"~/pages/*": ["./pages/*"],
"~/plugins/*": ["./plugins/*"],
"~/static/*": ["./static/*"]
}
}
}

0 comments on commit 738f08a

Please sign in to comment.