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 ...
随机推荐
- OpenCV-Python 轮廓分层 | 二十五
目标 这次我们学习轮廓的层次,即轮廓中的父子关系. 理论 在前几篇关于轮廓的文章中,我们已经讨论了与OpenCV提供的轮廓相关的几个函数.但是当我们使用cv.findcontour()函数在图像中找到 ...
- 一文上手TensorFlow2.0(一)
目录: Tensorflow2.0 介绍 Tensorflow 常见基本概念 从1.x 到2.0 的变化 Tensorflow2.0 的架构 Tensorflow2.0 的安装(CPU和GPU) Te ...
- Flume数据采集结合etcd作为配置中心在爬虫数据采集处理中的架构实践。
Apache Flume是一个分布式的.可靠的.可用的系统,用于有效地收集. 聚合和将大量日志数据从许多不同的源移动到一个集中的数据存储,但是其本身是以本地properties作为配置的,配置无法做到 ...
- Python基础 | pandas中dataframe的整合与形变(merge & reshape)
目录 行的union pd.concat df.append 列的join pd.concat pd.merge df.join 行列转置 pivot stack & unstack melt ...
- 左手VS PK 右手IDEA
近日愈发觉得编程是一件有趣的事. 三年前退伍时,还没有确定要继续干这行.去了北京之后,决定写代码吧.Why? 我是一个唯物主义者. 过去两年,一直抱有的念头是,怎么着也要至少干个三年,再寻求不写代码的 ...
- 迁移桌面程序到MS Store(15)——通过注册表开启Developer Mode
没想到该系列不仅没有太监,还打算更新一个小短篇.在各种大厂小厂工作的各位想必都知道Windows域的概念.入域的机器很多的设置就由不得当前登入所使用的域账号了,Windows的更新和安全等众多的设置均 ...
- Python函数之面向过程编程
一.解释 面向过程:核心是过程二字,过程即解决问题的步骤,基于面向过程去设计程序就像是在设计,流水线式的编程思想,在设计程序时,需要把整个流程设计出来, 一条工业流水线,是一种机械式的思维方式 二.优 ...
- 为什么要学习Oracle技术?
为什么要学习Oracle技术? 众所周知,Oracle占据着企业数据库领域超过48.1%的市场份额,成为高端企业数据库软件的绝对领导者.随着时间的推移,企业数据库的规模不断扩大,富有经验的资深Orac ...
- 1098 Insertion or Heap Sort (25分)
According to Wikipedia: Insertion sort iterates, consuming one input element each repetition, and gr ...
- 项目踩坑实记 :2019年(SSM 架构)
1.Bootstarp 相关 JS 结合 Bootstarp 初始化表格后,如果是 Ajax 请求获得返回数据,重新渲染数据到表格的话,用下面的函数. ChanInfTable 是表格的 id. 2. ...