react工程搭建系列之---基于create-react-app创建初始项目

一、使用create-react-app创建可执行的初始项目

1.npx创建(npm版本5.2+)

npx create-react-app my-react-app

2.npm创建(npm版本6+)

npm init react-app my-react-app

3.yarn创建

yarn create react-app my-react-app

二、工程结构

my-react-app/
  node_modules/
  package.json
  public/
    index.html   页面模板
    favicon.ico
  src/
    App.css
    App.js
    App.test.js
    index.css
    index.js   入口文件
    logo.svg
  • 其中public/index.html和src/index.js必须存在;
  • 只有在public目录下的文件才能被public/index.html使用;
  • 只有在src目录下的文件才会被webpack打包,所以要把js、css文件放在src目录下

三、可执行命令

/* package.json */
"scripts": {
    "start": "react-scripts start",   开发环境运行,默认监听3000端口
    "build": "react-scripts build",   生产环境运行,进行项目打包,默认打包到build目录
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },

npm run eject

如果create-react-app中的webpack配置满足不了需求,可以运行这个命令将所有webpack配置以及服务移到项目目录中,这样修改起来就很灵活了,但是这个命令是不可回退的,以下运行后的目录结构:

my-react-app/
  config/
    jest/
      cssTransform.js
      fileTransform.js
    env.js
    paths.js
    webpack.config.dev.js
    webpack.config.prod.js
    webpackDevServer.config.js
  scripts/
    build.js
    start.js
    test.js
  node_modules/
  package.json
  public/
    index.html   页面模板
    favicon.ico
  src/
    App.css
    App.js
    App.test.js
    index.css
    index.js   入口文件
    logo.svg
/* package.json */
"scripts": {
    "start": "node scripts/start.js",
    "build": "node scripts/build.js",
    "test": "node scripts/test.js"
  },

项目地址:https://github.com/SuRuiGit/m...

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值