Merge pull request #1923 from clarkdo/ts_config

feat: fix typescript example
This commit is contained in:
Sébastien Chopin 2017-10-23 10:41:43 +02:00 committed by GitHub
commit a3b0d3ec33
6 changed files with 94 additions and 81 deletions

View File

@ -1,16 +1,26 @@
module.exports = function(options) { module.exports = function(options) {
// Extend build // Extend build
this.extendBuild((config) => { this.extendBuild(config => {
const tsLoader = {
loader: "ts-loader",
options: {
appendTsSuffixTo: [/\.vue$/]
}
};
// Add TypeScript loader // Add TypeScript loader
config.module.rules.push({ config.module.rules.push(
test: /\.ts$/, Object.assign(
loader: 'ts-loader' {
}) test: /((client|server)\.js)|(\.tsx?)$/
},
tsLoader
)
);
// Add TypeScript loader for vue files // Add TypeScript loader for vue files
for (let rule of config.module.rules) { for (let rule of config.module.rules) {
if (rule.loader === 'vue-loader') { if (rule.loader === "vue-loader") {
rule.query.loaders.ts = 'ts-loader?{"appendTsSuffixTo":["\\\\.vue$"]}' rule.options.loaders.ts = tsLoader;
} }
} }
}) });
} };

View File

@ -22,5 +22,5 @@ module.exports = {
build: { build: {
vendor: ['axios', 'gsap', 'vuex-class', 'nuxt-class-component'] vendor: ['axios', 'gsap', 'vuex-class', 'nuxt-class-component']
}, },
modules: ['~modules/typescript'] modules: ['~/modules/typescript']
} }

View File

@ -4,12 +4,15 @@
"dependencies": { "dependencies": {
"axios": "^0.16.1", "axios": "^0.16.1",
"gsap": "^1.19.1", "gsap": "^1.19.1",
"nuxt": "^1.0.0-alpha2", "nuxt": "latest",
"nuxt-class-component": "^1.0.1", "nuxt-class-component": "^1.0.3",
"tachyons": "^4.7.0", "tachyons": "^4.7.0",
"vue-class-component": "^5.0.1", "vue": "~2.5.1",
"vue-property-decorator": "^5.0.1", "vue-server-renderer": "~2.5.1",
"vuex-class": "^0.2.0" "vue-template-compiler": "~2.5.1",
"vue-class-component": "^6.0.0",
"vue-property-decorator": "^6.0.0",
"vuex-class": "^0.3.0"
}, },
"scripts": { "scripts": {
"dev": "nuxt", "dev": "nuxt",
@ -18,7 +21,7 @@
"generate": "nuxt generate" "generate": "nuxt generate"
}, },
"devDependencies": { "devDependencies": {
"ts-loader": "^2.0.3", "ts-loader": "^3.0.0",
"typescript": "^2.2.2" "typescript": "^2.2.2"
} }
} }

View File

@ -16,7 +16,7 @@
<script lang="ts"> <script lang="ts">
import Vue from "vue"; import Vue from "vue";
import Component from "nuxt-class-component" import Component from "nuxt-class-component"
import Card from "~components/Card" import Card from "~/components/Card"
import { State, Getter } from "vuex-class" import { State, Getter } from "vuex-class"
@Component({ @Component({

View File

@ -1,4 +1,4 @@
import axios from "~plugins/axios"; import axios from "~/plugins/axios";
export const state = () => ({ export const state = () => ({
selected: 1, selected: 1,

View File

@ -8,7 +8,6 @@
"module": "es2015", "module": "es2015",
"moduleResolution": "node", "moduleResolution": "node",
"experimentalDecorators": true, "experimentalDecorators": true,
"declaration": true,
"noImplicitAny": false, "noImplicitAny": false,
"noImplicitThis": false, "noImplicitThis": false,
"strictNullChecks": true, "strictNullChecks": true,
@ -16,14 +15,15 @@
"suppressImplicitAnyIndexErrors": true, "suppressImplicitAnyIndexErrors": true,
"allowSyntheticDefaultImports": true, "allowSyntheticDefaultImports": true,
"baseUrl": ".", "baseUrl": ".",
"allowJs": true,
"paths": { "paths": {
"~": ["./"], "~/": ["./"],
"~assets/*": ["./assets/*"], "~/assets/*": ["./assets/*"],
"~components/*": ["./components/*"], "~/components/*": ["./components/*"],
"~middleware/*": ["./middleware/*"], "~/middleware/*": ["./middleware/*"],
"~pages/*": ["./pages/*"], "~/pages/*": ["./pages/*"],
"~plugins/*": ["./plugins/*"], "~/plugins/*": ["./plugins/*"],
"~static/*": ["./static/*"] "~/static/*": ["./static/*"]
} }
} }
} }