1. initialize project

create a folder project

Now we’ll turn this folder into an npm package.

npm init -y

This creates a package.json file with default values.

2. Install react typescript dependencies

First ensure Webpack is installed.

npm i webpack webpack-cli webpack-merge html-webpack-plugin webpack-dev-server -D

Webpack is a tool that will bundle your code and optionally all of its dependencies into a single .js file.

Let’s now add React and React-DOM, along with their declaration files, as dependencies to your package.json file:

npm i react react-dom
npm i @types/react @types/react-dom -D

That @types/ prefix means that we also want to get the declaration files for React and React-DOM. Usually when you import a path like "react", it will look inside of the react package itself; however, not all packages include declaration files, so TypeScript also looks in the @types/react package as well. You’ll see that we won’t even have to think about this later on.

Next, we’ll add development-time dependencies on the ts-loader and source-map-loader.

npm i typescript ts-loader source-map-loader -D
or
npm i awesome-typescript-loader source-map-loader -D

Both of these dependencies will let TypeScript and webpack play well together. ts-loader helps Webpack compile your TypeScript code using the TypeScript’s standard configuration file named tsconfig.json. source-map-loader uses any sourcemap outputs from TypeScript to inform webpack when generating its own sourcemaps. This will allow you to debug your final output file as if you were debugging your original TypeScript source code.

Please note that ts-loader is not the only loader for typescript. You could instead use awesome-typescript-loader

Read about the differences between them:

https://github.com/s-panferov/awesome-typescript-loader#differences-between-ts-loader

Notice that we installed TypeScript as a development dependency. We could also have linked TypeScript to a global copy with npm link typescript, but this is a less common scenario.

3. Install jest enzyme dependencies

1、install jest dependencies

npm i jest @types/jest ts-jest -D

2、 install enzyme dependencies

npm i enzyme enzyme-adapter-react-16 jest-enzyme  enzyme-to-json -D
npm i @types/enzyme @types/enzyme-adapter-react-16 -D

4. install another compiler for typescript use babel dependencies

install babel loader

npm i @babel/core @babel/preset-env @babel/preset-react @babel/preset-typescript -D

npm i babel-loader babel-plugin-import -D

config babel

module.exports={
presets: [
"env",
"react",
"typascript"
],
plugins: [
["lodash"],
["import", {libraryName: "antd", style: true}]
]
}

use babel loader instaed of ts-loader

最新文章

  1. 12306官方火车票Api接口
  2. jquery遍历不同色彩的li
  3. <<摩托车修理技术与禅>>读书笔记
  4. hdu A strange lift
  5. 算法:C++排列组合
  6. (菜鸟要飞系列)一,基于Asp.Net MVC5的后台管理系统(前言)
  7. ftk学习记(icon篇)
  8. JS获取字符串长度(区分中英文)
  9. 3.Lucene3.x API分析,Director 索引操作目录,Document,分词器
  10. python 正则验证 IP地址与MAC地址
  11. 2.Servlet 请求、响应及重定向
  12. 第4章 Selenium2-java WebDriver API (二)
  13. 51单片机开发板(W25Q16学习)
  14. Shiro笔记(一)基本概念
  15. vue 关于npm run build 的小问题
  16. js DomContentLoaded 和 load 的区别
  17. 《linux内核分析》第六周:分析fork函数对应的系统调用处理过程
  18. 前端安全系列之二:如何防止CSRF攻击
  19. Eclipse点不出方法了
  20. web开发中的安全问题

热门文章

  1. 《闲扯Redis三》Redis五种数据类型之List型
  2. RecyclerView实现拖动排序和滑动删除功能
  3. A 密码锁
  4. H - 遥远的糖果 HihoCoder - 1478
  5. CF633(div.2)B. Sorted Adjacent Differences
  6. 阿里云服务器扩展分区和文件系统_Linux数据盘
  7. uni-app的初识(01)
  8. python 函数--匿名函数
  9. 基础类封装-Requests库封装
  10. CH5501 环路运输(单调栈)