几种语言原生开发环境构建之--Typescript语言
2016-08-04 18:11
387 查看
安装nodejs和npm
安装nvm版本工具export NVM_DIR="$HOME/.nvm" && ( git clone https://github.com/creationix/nvm.git "$NVM_DIR" cd "$NVM_DIR" git checkout `git describe --abbrev=0 --tags --match "v[0-9]*" origin` ) && . "$NVM_DIR/nvm.sh"
将以上代码加入~/.profile文件
安装node和npm
$ nvm install node #node新版已经集成npm工具 $ node -v $ npm -v #常用install -g ,install --save |--save-dev , uninstall ,link, test
自定义npm配置
vim ~/.npmrc
prefix=/home/someuser/node_global/ #自定义npm模块安装目录 registry=http://registry.npm.taobao.org/ #npm镜像源
安装typescript语言支持
安装typescript编译器$ npm install typescript -g $ tsc --help
安装repl命令行
$ npm install ts-node -g $ ts-node
安装Typings:一个包管理器用来获取声明文件
$ npm install typings -g $ typings -h
项目构建
初始化$ mkdir helloworld && cd helloworld && mkdir src && mkdir src/test $ npm init #生成package.json配置文件 $ typings init #生成typings.json配置文件
新建一个针对于typescript的tsconfig.json的配置文件内容:
{ "filesGlob" :[ "src/**/*.ts" ] , "files": [ "src/index.ts" ,"src/bin/tool.ts" ], "compileOnSave": false, "compilerOptions": { "outDir": "dist/", "moduleResolution": "node", "noImplicitAny": true, "target": "es5" ,"sourceMap": true ,"module": "commonjs" ,"newLine": "LF" } ,"exclude": [ "node_modules" ] }
安装typescript支持
$ npm link typescript
开始编译
$ tsc #在dist目录产生js代码
集成测试
安装测试工具$ npm install mocha -g $ npm link mocha $ npm install chai --save $ typings install dt~chai --save #安装chai声明文件 $ typings install dt~mocha --save --global#安装mocha声明文件
配置文件package.json配置:
"scripts": { "pretest":"tsc typings/index.d.ts src/test/*.ts --outDir dist" , "test": " mocha dist/test" }
添加vim src/test/codeTest.ts 测试代码
import chai = require('chai'); var expect = chai.expect; describe('User Model Unit Tests:', () => { describe('2 + 4', () => { it('should be 6', (done) => { expect(2+4).to.equals(6); done(); }); it('should not be 7', (done) => { expect(2+4).to.not.equals(7); done(); }); }); });
测试
$ npm test
###结尾
项目代码
官方融合typescript2.x+node例子
(https://github.com/Microsoft/TypeScript-Node-Starter)
相关文章推荐
- 几种语言原生开发环境构建之--Lua语言
- 几种语言原生开发环境构建之--Elm语言
- 几种语言原生开发环境构建之--Haskell语言
- 几种语言原生开发环境构建之--Go语言
- 几种语言原生开发环境构建之--Python语言
- 在ubuntu下构建go语言开发环境的方法
- Idea基于scala语言构建spark开发环境搭建
- 配置EditPlus与NAnt构建轻型的.NET开发环境
- 让PHP支持大型项目-构建JSP、PHP与JAVA融为一体的开发环境[转载]
- 几种主流网页开发语言的思考(下)
- 开发国际化程序,在不同语言环境中显示对应的语言
- 在Windows下构建Qt4开发环境(Qt4+Vim)
- [经验]实际构建Symbian开发环境
- 配置EditPlus与NAnt构建轻型的.NET开发环境
- 构建自己的.NET Framework3.0开发环境
- 在多语言环境中构建基于MOSS2007的解决方案
- Asp,PHP,JSP,.Net几种网站开发语言比较
- [转载]让PHP支持大型项目-构建JSP、PHP与JAVA融为一体的开发环境
- 敏捷软件开发基础: 持续集成环境的构建
- 构建Python的桌面开发环境 于2005年07月26日