在本地运行React集成TypeScript的项目

87 阅读1分钟

首先问ChatGPT,贴一段TypeScript代码,问ChatGPT:要运行以上代码,该怎么操作?

ChatGPT给出了详细步骤,下面是实际操作:

创建一个react项目:

npx create-react-app yuanyu-timeline

cd yuanyu-timeline

安装tailwindcss:

npm install -D tailwindcss postcss autoprefixer

npx tailwindcss init -p

配置tailwind.config.js文件:

// tailwind.config.js

module.exports = {

content: [

"./src/**/*.{js,jsx,ts,tsx}",

],

theme: {

extend: {},

},

plugins: [],

}

配置src/index.css文件,加入代码:

/* src/index.css */

@tailwind base;

@tailwind components;

@tailwind utilities;

创建src/YuanyuTimeline.js,把之前生成的代码复制进入:

import React from 'react';

import { Card, CardContent } from '@/components/ui/card';

import { Calendar } from 'lucide-react';

const timelineData = [

{ date: '2022-10-01', event: 'PromptCLUE1.0模型' },

{ date: '2022-11-01', event: 'PromptCLUE1.5模型' },

{ date: '2022-12-20', event: 'ChatYuan发布' },

{ date: '2023-01-12', event: 'ChatYuan大模型开源' },

{ date: '2023-02-03', event: 'API发布' },

{ date: '2023-02-09', event: '小程序打不开' },

{ date: '2023-02-22', event: 'ChatYuan升级' },

{ date: '2023-03-24', event: '支持手机' },

{ date: '2023-03-30', event: '入选AIGC50' },

{ date: '2023-04-03', event: '与外研在线合作' },

{ date: '2023-04-18', event: '升级版本发布' },

{ date: '2023-04-21', event: 'KnowX1.0发布' },

{ date: '2023-04-27', event: '入选AI创新企业TOP20' },

{ date: '2023-08-28', event: '公众号最后更新' },

];

const TimelineItem = ({ date, event, isLast }) => (

{!isLast &&

}

{date}

{event}

);

const VerticalTimeline = () => (

Timeline

{timelineData.map((item, index) => (

<TimelineItem

key={item.date}

date={item.date}

event={item.event}

isLast={index === timelineData.length - 1}

/>

))}

);

export default VerticalTimeline;

修改src/App.js文件:

// src/App.js

import React from 'react';

import YuanyuTimeline from './YuanyuTimeline';

function App() {

return (

);

}

export default App;

最后,运行命令:npm start