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

react+vite+ts 组件模板

1.创建项目

npm create vite@latest my-app --template react-ts

2.配置项目 tsconfig.json

{"compilerOptions": {"target": "ES2020","useDefineForClassFields": true,"lib": ["ES2020", "DOM", "DOM.Iterable"],"module": "ESNext","skipLibCheck": true,"moduleResolution": "bundler","allowImportingTsExtensions": true,"resolveJsonModule": true,"isolatedModules": true,"noEmit": true,"jsx": "react-jsx","strict": true,"noUnusedLocals": true,"noUnusedParameters": true,"noFallthroughCasesInSwitch": true,"baseUrl": ".","paths": {"@/*": ["./src/*"]}},"include": ["src"],"references": [{ "path": "./tsconfig.node.json" }]
}

3.配置vite.config.ts

import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
import path from 'path';export default defineConfig({plugins: [react()],resolve: {alias: {'@': path.resolve(__dirname, './src'),},},
});

4.package.json中添加构建脚本

--report-unused-disable-directives 的作用

在 ESLint 中,eslint-disable 指令用于临时禁用某些规则,通常用于特殊情况,比如当你知道某个规则在某个地方不适用时。这些指令可以放在文件顶部或行内。

// eslint-disable-next-line no-unused-vars
const unusedVariable = 42;

"scripts": {"dev": "vite","build": "tsc && vite build","lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0","preview": "vite preview"
}

5.准备发布

{"name": "my-component-library","version": "1.0.0","description": "A collection of reusable React components","main": "dist/index.js","module": "dist/index.js","types": "dist/index.d.ts","files": ["dist"],"peerDependencies": {"react": "^18.0.0","react-dom": "^18.0.0"},"devDependencies": {"@types/react": "^18.0.0","@types/react-dom": "^18.0.0","typescript": "^5.0.0","vite-plugin-dts": "^1.0.0"}
}

http://www.xdnf.cn/news/19041.html

相关文章:

  • DAY-16-数组的常见操作和形状-2025.8.28
  • FISCO-BCOS-Python 模板
  • RAG概念被误用:AI应用落地需回归上下文工程本质
  • 解锁AI“黑匣”:监督、无监督与强化学习探秘
  • 切入高潜市场,抢占行业先机!ES SHOW 2025展位预订火爆,10月28-30日共启增长新蓝海
  • flutter Function和自定义的Callback有什么区别?
  • 自动化三维测量仪工业零件自动外观三维测量-中科米堆CASAIM
  • Linux系统资源分配算法在VPS云服务器调优-性能优化全指南
  • 【DAB收音机】DAB 信号发生器介绍
  • C++源代码批量转码utf8
  • SystemVerilog学习【六】功能覆盖率详解
  • 【动态规划】简单多状态 dp 问题
  • 【lucene】advanceShallow (int target) 与advance(int target)
  • Kea DHCP高危漏洞CVE-2025-40779:单个数据包即可导致服务器崩溃
  • workflow/http_parser源码解密:HTTP解析器的双倍扩容与零拷贝策略
  • R 语言 eulerr 包绘制韦恩图:比例精准
  • 机器学习(讲解)
  • 使用MySQL计算斐波那契数列
  • 开源工具新玩法:cpolar提升Penpot协作流畅度
  • Spark入门:从零到能跑的实战教程
  • 基于Spring Session + Redis + JWT的单点登录实现
  • 在Ubuntu中安装配置MySql Server
  • [p2p-Magnet] docs | HTTP API与Web界面 | 搜索查询引擎
  • PyTorch 张量核心知识点
  • 引入资源即针对于不同的屏幕尺寸,调用不同的css文件
  • KubeBlocks For MySQL 云原生设计分享
  • 三大压测工具对比:Siege/ab/Wrk实战指南
  • SpringBoot系列之实现高效批量写入数据
  • 基础IO详解
  • 【前缀和】