当前位置:   article > 正文

前端开发react+js/ts 环境搭建及发包_npm搭建react+ts前端开发框架

npm搭建react+ts前端开发框架

1. 安装:node

nodejs 安装笔记_bulucc的博客-CSDN博客

2.安装create-react-app

  1. # npm方式:
  2. npm install -g create-react-app
  3. # cnpm方式:
  4. cnpm install -g create-react-app
  5. # yarn方式:
  6. yarn global add create-react-app
  7. # yarn安装:
  8. npm install -g yarn
  9. # 查看版本:yarn -v
  10. # cnpm安装:
  11. npm install -g cnpm -registry=https://registry.npm.taobao.org
  12. # 查看版本:cnpm -v (备注:不要用npm install cnpm -g安装)
  13. # 验证是否安装成功
  14. create-react-app -V

3.创建项目

  1. # 【 react + js 】
  2. # projectname 项目名字,勿大写
  3. create-react-app projectname
  4. # yarn 创建
  5. yarn create react-app projectname
  6. # react+ts(tsx)
  7. create-react-app projectname --template typescript
  8. # yarn 创建
  9. yarn create react-app projectname --template typescript
  10. yarn create react-app projectname --template=typescript
  11. # 使用最新版非全局安装
  12. npx create-react-app projectname

4.安装new-component

  1. # npm 安装
  2. npm i -g new-component
  3. # yarn 安装
  4. yarn global add new-component
  5. # new-component 创建新组件,项目根目录下执行
  6. yarn new-component name
  7. # 会在 packages/components/src 目录下新建一个新组件的文件夹,里边的内容是根据模板创建的
  8. # 执行前 在 packages/components/index.tsx 中导出新组件
  9. # yarn start 启动后,点击右上角的 组件 进入到组件列表,可以看到新建的组件
  10. 根据开发规范 开发组件

5.运行项目

  1. # 进入项目
  2. cd projectname
  3. # npm方式
  4. npm start
  5. # cnpm方式
  6. cnpm start
  7. # yarn方式
  8. yarn start
  9. # 如果启动失败,建议操作
  10. # 1、尝试切换镜像
  11. # 2、删除node_modules及package-lock.json,重新yarn或者npm i
  12. # 3、删除上述文件同时清除npm缓存,重新安装依赖包
  13. npm cache clean --force

6、各UI组件安装

antd(ant design)安装:https://ant.design/index-cn

  1. # npm 安装
  2. npm install antd --save
  3. # cnpm安装
  4. cnpm install antd --save
  5. # yarn安装
  6. yarn add antd

antd-mobile(ant design mobile)V2 安装:https://antd-mobile-v2.surge.sh/index-cn

  1. # npm 安装
  2. npm install antd-mobile --save
  3. # cnpm安装
  4. cnpm install antd-mobile --save
  5. # yarn安装
  6. yarn add antd-mobile

其他组件均可按照上述方式安装

7.发布

  1. # 只发布 packages/components/ 组件包,其他不进行发布的包在package.json中增加"private": true字段
  2. # 开发完毕后,修改版本
  3. lerna publish from-package --registry=http://registry.npm.baidu-int.com

lerna 安装避坑指南: npm start 避坑笔记_bulucc的博客-CSDN博客

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/笔触狂放9/article/detail/449144
推荐阅读
相关标签
  

闽ICP备14008679号