当前位置: 首页 > news >正文

TypeScript React(下)

目录

TypeScript & React

TS开发环境的搭建

tsconfig.json

webpack.config.js

babel.config.js

.eslintrc.js


TypeScript & React

TS开发环境的搭建

  • 软件版本:TypeScript:3.9.5;React:16.13.1 Node:8.17.0
  • 环境搭建:正确搭建一个通用的TypeScript开发环境

差异:

  • tsconfig->babel->eslint

tsconfig.json

{"compilerOptions": {"outDir": "./","target": "esnext","allowJs": true,"noEmit": true,"skipLibCheck": true,"esModuleInterop": true,"allowSyntheticDefaultImports": true,"strict": true,"forceConsistentCasingInFileNames": true,"module": "esnext","moduleResolution": "node","resolveJsonModule": true,"experimentalDecorators": true,"noUnusedParameters": true,"noUnusedLocals": true,"jsx": "react","sourceMap": true,"pretty": true,"baseUrl": ".","paths": {"@/*": ["./src/*"]},},  "typeRoots": ["node_modules/@types","src/types"],"include": ["src/**/*"],"exclude": ["node_modules","dist","**/*.spec.ts"],
}

webpack.config.js

const path = require('path');
const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const devPort = parseInt(process.env.port, 10) || 8065;
module.exports = (env) => {const publicPath = '';const buildPath = './build';const config = {mode: env.prod ? 'production' : 'development',entry: {app: path.join(__dirname, './src/index.tsx'),},devServer: {historyApiFallback: true,contentBase: path.join(__dirname, buildPath),port: devPort,hot: true,disableHostCheck: true,},output: {path: path.join(__dirname, buildPath),pathinfo: true,filename: env.prod || env.test ? '[name].[hash].js' : '[name].js',publicPath: `${publicPath}/`,},resolve: {alias: {'@': path.resolve(__dirname, './src'),},extensions: ['.ts', '.tsx', '.js', '.jsx', '.json'],},module: {rules: [{test: /(\.ts|\.tsx)$/,exclude: /(node_modules)/,use: [{// 新增支持ts编译loader: 'babel-loader',},],},{test: /\.css$/,exclude: /node_modules/,use: [{loader: 'style-loader',},{loader: 'css-loader',options: {importLoaders: 1,},},{loader: 'postcss-loader',},],},],},plugins: [new webpack.DefinePlugin({'process.env.ENV': env.dev,}),new webpack.LoaderOptionsPlugin({ options: {} }),new HtmlWebpackPlugin({title: 'React & TypeScript',template: path.join(__dirname, './src/view/index.html'),inject: true,hash: false,filename: 'index.html',publicPath: '',}),],devtool: 'source-map',watch: true,};return config;
};

babel.config.js

module.exports = (api) => {api.cache(true);const plugins = [require('@babel/plugin-transform-runtime'),[require('@babel/plugin-proposal-decorators'), { legacy: true }],[require('@babel/plugin-proposal-class-properties'), { loose: true }],require('@babel/plugin-proposal-export-default-from'),// require("react-hot-loader/babel"),];const presets = [[require('@babel/preset-env'),{modules: false,useBuiltIns: 'usage',corejs: { version: 3, proposals: true },},],[require('@babel/preset-react')],// 插件将ts、tsx转译为js[require('@babel/preset-typescript')],];return {plugins,presets,};
};

.eslintrc.js

const path = require('path');
module.exports = {root: true,// 新增ts的编译parser: '@typescript-eslint/parser',extends: ['airbnb-typescript','airbnb/hooks',// 新增tslint推荐'plugin:@typescript-eslint/recommended','plugin:@typescript-eslint/recommended-requiring-type-checking',],// 新增@typescript-eslint配置项plugins: ['@typescript-eslint', 'jsx-a11y', 'import', 'react-hooks'],parserOptions: {ecmaVersion: 2019,sourceType: 'module',// 关联ts配置文境project: './tsconfig.json',},settings: {'import/resolver': {webpack: {config: {resolve: {alias: {'@': path.resolve(__dirname, './src'),},extensions: ['.ts', '.tsx', '.js', '.jsx', '.json'],},},},},},env: {browser: true,},globals: {window: true,ENV: true,},rules: {indent: ['error', 2],quotes: ['error', 'single'],semi: ['error', 'always'],'no-console': 1,'arrow-parens': 0,'no-shadow': 'off','react/jsx-filename-extension': 'off','react/jsx-props-no-spreading': 0,// 自定义规则'@typescript-eslint/consistent-type-definitions': ['error', 'interface'],'@typescript-eslint/explicit-function-return-type': 'off','@typescript-eslint/no-explicit-any': 0,'import/extensions': ['error','ignorePackages',{ts: 'never',tsx: 'never',js: 'never',jsx: 'never',json: 'never',},],'import/no-unresolved': [2, { commonjs: true, amd: true }],},
};

相关文章:

TypeScript React(下)

目录 TypeScript & React TS开发环境的搭建 tsconfig.json webpack.config.js babel.config.js .eslintrc.js TypeScript & React TS开发环境的搭建 软件版本:TypeScript:3.9.5;React:16.13.1 Node:8.17.0环境搭建:正确搭建一…...

『Linux小程序』进度条

文章目录 缓冲区问题回车与换行的区别进度条小程序 缓冲区问题 假设有一段代码为: #include<iostream> #include<unistd.h> int main() …...

【手写数字识别】GPU训练版本

SVM Adaboost Bagging 完整代码 I import torch import torch.nn.functional as F from torch.utils.data import DataLoader, TensorDataset from torchvision import transforms, datasets import matplotlib.pyplot as plt# 超参数 batch_size 64 num_epochs 10# 数据…...

c#-特殊的集合

位数组 可观察的集合 private ObservableCollection<string> strList new ObservableCollection<string>();// Start is called before the first frame updatevoid Start(){strList.CollectionChanged Change;strList.Add("ssss");strList.Add("…...

Android 使用 eChart 设置标线

echart使用标线 Android部分&#xff1a; import android.webkit.WebView; import com.jianqu.plasmasterilizer.R; import com.jianqu.plasmasterilizer.utils.DisplayUtils; import com.jianqu.plasmasterilizer.utils.TimerUtil; import java.util.ArrayList; import java.…...

红队专题-Cobalt strike 4.x - Beacon重构

红队专题 招募六边形战士队员重构后 Beacon 适配的功能windows平台linux和mac平台C2profile 重构思路跨平台功能免杀代码部分sysinfo包packet包config.go命令的执行shell、run、executepowershell powerpick命令powershell-importexecute-assembly 堆内存加密字符集 招募六边形…...

一文掌握 Go 文件的写入操作

前言 通过案例展示如何读取文件里的内容。本文接着上篇文章的内容&#xff0c;介绍文件的写入操作。 File.Write、File.WriteString、File.WriteAt File.Write(b []byte) (n int, err error) 直接操作磁盘往文件里写入数据&#xff0c;写入单位为字节。 b 参数&#xff1a;…...

小程序入门及案例展示

目录 一、小程序简介 1.1 为什么要使用小程序 1.2 小程序可以干什么 二、前期准备 2.1 申请账号 2.2 开发工具下载与安装 三、电商案例演示 四、入门案例 4.1 项目结构解析 4.2 基础操作及语法 4.3 模拟器 4.4 案例演示 4.4.1 新建页面 4.4.2 头部样式设置 4.4.…...

linux 安装python django pip 遇到的问题

Python解决SSL不可用问题 解决方案&#xff1a; 首先要明白python版本需要和openssl的版本需要相对匹配的&#xff0c;在Python3.7之后的版本&#xff0c;依赖的openssl&#xff0c;必须要是1.1或者1.0.2之后的版本&#xff0c;或者安装了2.6.4之后的libressl&#xff0c;linux…...

【问题解决】【爬虫】抓包工具charles与pycharm发送https请求冲突问题

问题&#xff1a; 开启charles抓包&#xff0c;运行pycharm发送https请求报以下错误 解决&#xff1a; 修改python代码&#xff0c;发送请求时添加verify false&#xff0c;此时charles也能抓取到pycharm发送的请求 2. 关闭charles抓包&#xff0c;取消勾选window proxy...

Hadoop3教程(二):HDFS的定义及概述

文章目录 &#xff08;40&#xff09;HDFS产生的背景和定义&#xff08;41&#xff09;HDFS的优缺点&#xff08;42&#xff09;HDFS组成架构&#xff08;43&#xff09;HDFS文件块大小&#xff08;面试重点&#xff09;参考文献 &#xff08;40&#xff09;HDFS产生的背景和定…...

【物联网+JAVA 】智慧工地源码

一、什么是智慧工地&#xff1f; 工地本身不拥有智慧&#xff0c;工地的运作是依赖于人的智慧。工地信息化技术&#xff0c;能够减少对人的依赖&#xff0c;使工地拥有智慧。 智慧工地&#xff0c;就是立足于“智慧城市”和“互联网”&#xff0c;采用云计算、大数据和物联网…...

001数据安全传输-多端协议传输平台:Openssl安装和配置 - EVP代码测试

001数据安全传输-多端协议传输平台&#xff1a;Openssl安装和配置 - EVP代码测试 文章目录 001数据安全传输-多端协议传输平台&#xff1a;Openssl安装和配置 - EVP代码测试1. 安装1.1 windows下安装openssl1.2 Linux下安装OpenSSL 2. VS中使用openssl3. 测试 1. 安装 1.1 win…...

关于小编入坑第512天

​机缘 最初成为创作者的初心&#xff1a;总结记录整个学习前端的历程 日常学习过程中的记录&#xff1a; 先思考&#xff0c;整个程序逻辑流程是否出现问题 再文档&#xff0c;根据相关文档了解源头&#xff0c;学会看懂文档&#xff0c;是一个锻炼自学前端能力的关键一步 …...

VS2015编译Qt工程发生MSB4018错误完整解决过程

一、错误产生环境 操作系统&#xff1a;Windows10 开发工具&#xff1a;VS2015企业版 Qt版本&#xff1a;Qt5.7.1 64位 二、错误内容 MSB4018 “VCMessage”任务意外失败。 System.FormatException: 索引(从零开始)必须大于或等于零&#xff0c;且小于参数列表的大小。 …...

如何使用JMeter测试导入接口/导出接口

今天一上班&#xff0c;被开发问了一个问题&#xff1a;JMeter调试接口&#xff0c;文件导入接口怎么老是不通&#xff1f;还有导出文件接口&#xff0c;不知道文件导到哪里去了&#xff1f; 我一听&#xff0c;这不是JMeter做接口测试经常遇到的嘛&#xff0c;但是一时半会又…...

[入门一]C# webApi创建、与发布、部署、api调用

一.创建web api项目 1.1、项目创建 MVC架构的话&#xff0c;它会有view-model-control三层&#xff0c;在web api中它的前端和后端是分离的&#xff0c;所以只在项目中存在model-control两层 1.2、修改路由 打开App_Start文件夹下&#xff0c;WebApiConfig.cs ,修改路由&…...

关于Vue+webpack使用unocss编写CSS,打包后CSS没加前缀

关于Vuewebpack使用unocss编写CSS&#xff0c;打包后CSS没加前缀&#xff0c;封装了一个插件去解决了这个问题 unocss-postcss-webpack-plugin unocss在vite中使用配置&#xff0c;关于unocss在vite中使用&#xff0c;自行查阅官网 https://unocss.dev/integrations/vite ,vi…...

软件工程与计算总结(十一)人机交互设计

目录 ​编辑 一.引例 二.目标 三.人类因素 1.精神模型 2.差异性 四.计算机因素 1.可视化设计 2.常见界面类型 五.人机交互设计的交互性 1.导航 2.反馈 3.设计原则 六.设计过程 1.基本过程 2.界面原型化 一.引例 无论软件功能多么出色&#xff0c;亦或内部的构造…...

Jmeter组件执行顺序与作用域

一、Jmeter重要组件&#xff1a; 1&#xff09;配置元件---Config Element&#xff1a; 用于初始化默认值和变量&#xff0c;以便后续采样器使用。配置元件大其作用域的初始阶段处理&#xff0c;配置元件仅对其所在的测试树分支有效&#xff0c;如&#xff0c;在同一个作用域的…...

FFmpeg 低延迟同屏方案

引言 在实时互动需求激增的当下&#xff0c;无论是在线教育中的师生同屏演示、远程办公的屏幕共享协作&#xff0c;还是游戏直播的画面实时传输&#xff0c;低延迟同屏已成为保障用户体验的核心指标。FFmpeg 作为一款功能强大的多媒体框架&#xff0c;凭借其灵活的编解码、数据…...

【Java学习笔记】Arrays类

Arrays 类 1. 导入包&#xff1a;import java.util.Arrays 2. 常用方法一览表 方法描述Arrays.toString()返回数组的字符串形式Arrays.sort()排序&#xff08;自然排序和定制排序&#xff09;Arrays.binarySearch()通过二分搜索法进行查找&#xff08;前提&#xff1a;数组是…...

ssc377d修改flash分区大小

1、flash的分区默认分配16M、 / # df -h Filesystem Size Used Available Use% Mounted on /dev/root 1.9M 1.9M 0 100% / /dev/mtdblock4 3.0M...

Leetcode 3577. Count the Number of Computer Unlocking Permutations

Leetcode 3577. Count the Number of Computer Unlocking Permutations 1. 解题思路2. 代码实现 题目链接&#xff1a;3577. Count the Number of Computer Unlocking Permutations 1. 解题思路 这一题其实就是一个脑筋急转弯&#xff0c;要想要能够将所有的电脑解锁&#x…...

什么是库存周转?如何用进销存系统提高库存周转率?

你可能听说过这样一句话&#xff1a; “利润不是赚出来的&#xff0c;是管出来的。” 尤其是在制造业、批发零售、电商这类“货堆成山”的行业&#xff0c;很多企业看着销售不错&#xff0c;账上却没钱、利润也不见了&#xff0c;一翻库存才发现&#xff1a; 一堆卖不动的旧货…...

SpringBoot+uniapp 的 Champion 俱乐部微信小程序设计与实现,论文初版实现

摘要 本论文旨在设计并实现基于 SpringBoot 和 uniapp 的 Champion 俱乐部微信小程序&#xff0c;以满足俱乐部线上活动推广、会员管理、社交互动等需求。通过 SpringBoot 搭建后端服务&#xff0c;提供稳定高效的数据处理与业务逻辑支持&#xff1b;利用 uniapp 实现跨平台前…...

C++.OpenGL (10/64)基础光照(Basic Lighting)

基础光照(Basic Lighting) 冯氏光照模型(Phong Lighting Model) #mermaid-svg-GLdskXwWINxNGHso {font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;fill:#333;}#mermaid-svg-GLdskXwWINxNGHso .error-icon{fill:#552222;}#mermaid-svg-GLd…...

Device Mapper 机制

Device Mapper 机制详解 Device Mapper&#xff08;简称 DM&#xff09;是 Linux 内核中的一套通用块设备映射框架&#xff0c;为 LVM、加密磁盘、RAID 等提供底层支持。本文将详细介绍 Device Mapper 的原理、实现、内核配置、常用工具、操作测试流程&#xff0c;并配以详细的…...

python报错No module named ‘tensorflow.keras‘

是由于不同版本的tensorflow下的keras所在的路径不同&#xff0c;结合所安装的tensorflow的目录结构修改from语句即可。 原语句&#xff1a; from tensorflow.keras.layers import Conv1D, MaxPooling1D, LSTM, Dense 修改后&#xff1a; from tensorflow.python.keras.lay…...

【7色560页】职场可视化逻辑图高级数据分析PPT模版

7种色调职场工作汇报PPT&#xff0c;橙蓝、黑红、红蓝、蓝橙灰、浅蓝、浅绿、深蓝七种色调模版 【7色560页】职场可视化逻辑图高级数据分析PPT模版&#xff1a;职场可视化逻辑图分析PPT模版https://pan.quark.cn/s/78aeabbd92d1...