react typescript jest config (一)
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
react typescript jest config (一)的更多相关文章
- react: typescript jest && enzyme
Install Jest 1.install jest dependencies jest @types/jest ts-jest -D 2.jest.config.js module.exports ...
- react 单元测试 (jest+enzyme)
为什么要做单元测试 作为一个前端工程师,我是很想去谢单元测试的,因为每天的需求很多,还要去编写测试代码,感觉时间都不够用了. 不过最近开发了一个比较复杂的项目,让我感觉一旦项目大了.复杂了,而且还是多 ...
- 【每天学一点-04】使用脚手架搭建 React+TypeScript+umi.js+Antd 项目
一.使用脚手架搭建项目框架 1.首先使用脚手架搭建React项目(React+TypeScript+Umi.js) 在控制台输入命令:yarn create @umijs/umi-app 2.引入An ...
- react + typescript 学习
react,前端三大框架之一,也是非常受开发者追捧的一门技术.而 typescript 是 javascript 的超集,主要特点是对 类型 的检查.二者的结合必然是趋势,不,已经是趋势了.react ...
- React + Typescript领域初学者的常见问题和技巧
React + Typescript领域初学者的常见问题和技巧 创建一个联合类型的常量 Key const NAME = { HOGE: "hoge", FUGA: "f ...
- 前端自动化测试 —— TDD环境配置(React+TypeScript)
欢迎讨论与指导:) 前言 TDD -- Test-Drive Development是测试驱动开发的意思,是敏捷开发中的一项核心实践和技术,也是一种测试方法论.TDD的原理是在开发功能代码之前,先编写 ...
- React & TypeScript
之前看了一下 TypeScript 的知识,但是一直没有上手,最近开始结合 React 和 TypeScript 一起尝试了一下,感受还是很好的,所以写一下笔记. 环境配置没有参考其他东西,就是看了下 ...
- react: typescript project initialize
Initialize the project create a folder project Now we’ll turn this folder into an npm package. npm i ...
- 使用react搭建组件库:react+typescript+storybook
前期准备 1. 初始化项目 npx create-react-app react-components --template typescript 2. 安装依赖 使用哪种打包方案:webpack/r ...
随机推荐
- 终极指南:构建用于检测汽车损坏的Mask R-CNN模型(附Python演练)
介绍 计算机视觉领域的应用继续令人惊叹着.从检测视频中的目标到计算人群中的人数,计算机视觉似乎没有无法克服的挑战. 这篇文章的目的是建立一个自定义Mask R-CNN模型,可以检测汽车上的损坏区域(参 ...
- VBScript - 动态 Array 实现方法大全!
记录一些方法,关于 VBScript 中,动态 Array 的实现 ,也适用于 VBA, 很久以前,写 VBA 的时候,就觉得使用 Array 很不方便,因为大小固定, 当时想的是,要是 Array ...
- 倒计时器CountDownLatch
1.背景: countDownLatch是在java1.5被引入,跟它一起被引入的工具类还有CyclicBarrier.Semaphore.concurrentHashMap和BlockingQueu ...
- [bzoj]1053反质数<暴搜>
题目:http://www.lydsy.com/JudgeOnline/problem.php?id=1053 感想:这道题拿到以后还是想去知道一个数的约数个数要怎么求,去网上搜了公式,但是还是没有思 ...
- Matlab GUI设计(2)
11. (1)界面设计 (2)添加按钮的回调函数 function pushbutton1_Callback(hObject, eventdata, handles) % hObject handle ...
- FZU - 2204 简单环形dp
FZU - 2204 简单环形dp 题目链接 n个有标号的球围成一个圈.每个球有两种颜色可以选择黑或白染色.问有多少种方案使得没有出现连续白球7个或连续黑球7个. 输入 第一行有多组数据.第一行T表示 ...
- CyclicBarrier是如何成为一个"栅栏"的
CyclicBarrier是一种类似于栅栏的存在,意思就是在栅栏开放之前你都只能被挡在栅栏的一侧,当栅栏移除之后,之前被挡在一侧的多个对象则同时开始动起来. 1. 如何使用CyclicBarrier ...
- Oracle数据库表和表列讲解
如果将数据库比作一个存储东西的储物柜,表就像是储物柜上的各个抽屉,每个抽屉分门别类地存放了各种数据,在设计和规划数据库时,表的定义和规划往往相当重要,良好的表设计决定了程序人员编写程序的便利性与数据库 ...
- Yum 软件仓库配置
Yum 软件仓库的作用是为了进一步简化 RPM 管理软件的难度以及自动分析 所需软件包及其依赖关系的技术. 可以把 Yum 想象成是一个硕大的软件仓库,里面保存有几乎所 有常用的工具 . 第1步:进入 ...
- 电商平台--Mysql主从搭建(2)
Master上授权从库: ```grant replication slave on *.* to slave1@ip identified by 'password';``` 基于数据库hotcop ...