React: React脚手架

一、简言

React开发目前已经非常流行,对于如何实现对React项目的管理和维护,React生态圈出现了大量可用的开发工具,例如Browserify、Gulp、Grunt、webpack等。其中,webpack称为CommonJS模块的主流工具之一,它是一个模块绑定器,拥有模块化和网络性能的两大优点,可以将不同类型的文件转换为单个文件,也可以将所有的依赖项打包成单个文件。当然,使用webpack管理React,开发者需要通过命令行去安装webpack和Babel,然后对webpack进行配置。相比于之前的web开发模式,使用webpack开发,开发者不用再去关心转译等问题,安心开发即可,效率更高。技术不断更新,工具层出不穷,React团队很快推出了一个可以自动生成React项目的命令行工具create-react-app,使得开发者不用再去手动配置webpack、Babel等,就可以快速启动React项目,也称为React脚手架,真是懒人开发的极致了。安装后的脚手架如图示:

二、安装

1、安装软件包create-react-app,它已经完成了React环境搭建

npm install -g create-react-app

2、在指定目录下创建React项目

//进入指定目录
cd ./xxx/xxx  

//创建React项目,reactProject为项目名称
//项目创建后,三个依赖库:React/ReactDOM/react-script都已经被引入进去了,而且,Babel、webpack等工具默认也已经完成了安装,无需开发者手动去配置
create-react-app reactProject 

3、运行React项目

//以交互模式执行项目中的所有测试文件
//npm test 或者 yarn test

//打包一个准备上线的bundle文件,其中的代码已经经过转译和压缩
//npm run build 或者 yarn build

//启动项目,可以看到网页打开了: http://localhost:3000/
npm start 或者 yarn start

三、示例

1、创建项目react-demo

2、进入目录运行项目

3、页面启动运行成功

四、结构

使用webStorm打开项目,项目结构很清晰。在生成的项目文件夹中,可以看到包含App.js文件的src文件夹,开发者在这里,可以编辑root组件,以及导入其他组件文件进行后续的开发。

原文地址:https://www.cnblogs.com/XYQ-208910/p/11988268.html

时间: 2024-08-27 13:39:08

React: React脚手架的相关文章

React/React Native 的ES5 ES6写法对照表

转载: http://bbs.reactnative.cn/topic/15/react-react-native-%E7%9A%84es5-es6%E5%86%99%E6%B3%95%E5%AF%B9%E7%85%A7%E8%A1%A8 英文版: https://babeljs.io/blog/2015/06/07/react-on-es6-plus 很多React/React Native的初学者都被ES6的问题迷惑:各路大神都建议我们直接学习ES6的语法(class Foo extends

[React] React Fundamentals: Integrating Components with D3 and AngularJS

Since React is only interested in the V (view) of MVC, it plays well with other toolkits and frameworks. This includes AngularJS and D3. A app with React and D3.js: /** @jsx React.DOM */ var App = React.createClass({ getInitialState: function () { re

react+antdUI脚手架

概述这款基于React开发的UI框架,界面非常简洁美观,在这篇文章中我主要为大家介绍一下如何用Ant开始搭建React项目详细代码下载:http://www.demodashi.com/demo/12205.html 一.安装webstorm + Noje.js(全局安装)详细安装这里略过 二.全局安装create-react-app脚手架用管理员身份运行cmd,输入: npm install -g create-react-app yarn 成功! 三.创建React项目antd-demo1继

react用脚手架创建一个react项目

官网地址:https://react.docschina.org/ 确保本地安装了Node.js node的版本大于8.10    npm的版本大于5.6 1.在本地的某个位置创建一个文件夹,执行以下代码: npx create-react-app my-app(项目名称 可以自定义) 等待...... 创建好项目后,跳转到项目跟目录: cd my-app 然后运行项目: npm start 弹出这个页面代表项目已经创建好了! 原文地址:https://www.cnblogs.com/fqh12

yeoman 的react redux 脚手架工具

https://www.npmjs.com/package/generator-react-webpack 上面的组件还是用的es6 的class ,在 http://www.imooc.com/video/13215 里面已经开始使用函数式的组件了. 也就是三个阶段  commonjs   |类    函数式|   (es6模块)

[React] React Router: Nested Routes

Since react-router routes are components, creating nested routes is as simple as making one route a child of another in JSX. Make the nested component: class App extends React.Component { render(){ return( <Router history={hashHistory}> <Route pa

[React] React Router: IndexRoute

IndexRoute allows us to define a default child component to be rendered at a specific route when no other sub-route is available. When Home page display, we also make About component as default Route to dsiplay, only when use click Contact link, then

[React] React Fundamentals: with-addons - ReactLink

It can be tedious to type out all the boilerplate needed to get the DOM and states in React to synchronize. Luckily, React provides a version of the toolkit with a selection of available addons. This lesson is going to dig into ReactLink, and how thi

[React] React Router: Router, Route, and Link

In this lesson we'll take our first look at the most common components available to us in react-router; Router, Route, and Link. import React from 'react'; import {hashHistory, Route, Router, Link} from 'react-router'; const Home = () => <div><