项目作者: Hellowor1d

项目描述 :
Project: Vue2, Vuex, Typescript, Stylus, Eslint, Tslint, axios
高级语言: JavaScript
项目地址: git://github.com/Hellowor1d/vue-typescript.git
创建时间: 2017-12-14T03:16:34Z
项目社区:https://github.com/Hellowor1d/vue-typescript

开源协议:

下载


vue-typescript

A Vue.js + TypeScript project

Build Setup

  1. # install dependencies
  2. npm install
  3. # serve with hot reload at localhost:8080
  4. npm run dev
  5. # build for production with minification
  6. npm run build
  7. # build for production and view the bundle analyzer report
  8. npm run build --report
  9. # run unit tests
  10. npm run unit
  11. # run e2e tests
  12. npm run e2e
  13. # run all tests
  14. npm test

For a detailed explanation on how things work, check out the guide and docs for vue-loader.

初始化阶段

  1. vue init webpack vue-typescript
  2. sudo yarn (chromedriver: Command failed.)

有一个安装错误,不影响项目启动,后续再深入解决

开始打造 Typescript 所需环境

如果需要权限,添加 sudo 再执行以下命令

  1. 添加 vue-class-component vue-property-decorator
    1. yarn add vue-class-component vue-property-decorator
  2. 添加 ts-loader typescript tslint tslint-loader 等 tyepescript 解析工具
    1. yarn add ts-loader typescript tslint tslint-loader tslint-config-airbnb-base -D
  3. 配置 webpack main.js ==> main.ts

找到entry.app 将main.js 改成 main.ts, 顺便把项目文件中的main.js也改成main.ts, 里面内容保持不变

  1. resolve.extensions 里面加上.ts 后缀 (是为了之后引入.ts的时候不写后缀)

  2. 找到module.rules 添加webpack对.ts的解析

  3. 添加 tsconfig.json, tslint.json (使用 tslint-config-airbnb-base 插件)

  4. 添加 vue-shim.d.ts 文件

告诉 TypeScript *.vue 后缀的文件可以交给 vue 模块来处理

  1. 改造 .vue 文件 script 标签上加上 lang=”ts” 并且改造 vue 组件构造方式