zl程序教程

您现在的位置是:首页 >  前端

当前栏目

实战build-react(一)

React 实战 build
2023-09-11 14:17:23 时间

https://www.jianshu.com/p/34468f13263c(copy)  目录结构

一、安装

npm install -g create-react-app

二、创建react应用

create-react-app 项目名称

进入项目文件

npm start   或 yarn

然后chrome浏览器网上应用安装

React Developer Tools和Redux DevTools

https://blog.csdn.net/lengyoumo/article/details/80336922(copy)

yarn --version

如果没有

安装方式:npm install yarn -g

如果有

安装redux

yarn add redux

//---------------------------------------------------选择性执行,不是必要的,有些项目需要-----------------------------------------------------------

此时没有webpack.config.js文件,然后执行npm run eject暴露webpack.config.js文件,在config文件夹里

但是有缺点,执行后所有开发环境的模块包都加进了运行环境里了

或者可以尝试https://blog.csdn.net/qq_42190134/article/details/88528852(copy)

大神指导

 

https://blog.csdn.net/qq_32842925/article/details/83375791(copy)

npm start #运行开发环境服务
npm run build #将项目打包捆绑成用于生产环境的静态文件
npm test #运行测试文件
npm run eject # ↵
#将所有工具和包移动并将其配置为项目的依赖,这样会把这些文件都差到package.json文件的dependences下
#为的是开发时使用了自定义的第三方库能被准确标记。

 

 //---------------------------------------------------end----------------------------------------------------------

手动webpack

https://zhuanlan.zhihu.com/p/45506253

创建两个文件store下的index和reducer

//store/index.js
import {createStore} from 'redux';
import reducer from './reducer';
const store =createStore(reducer);

export default store;
//store/reducer.js
const defaultState={
texts:'',
list:[1,2]
};
export default (state=defaultState,action)=>{
return state;
}

 

yarn add axios 或 npm install axios --save
yarn add <package...>

This will install one or more packages in your dependencies.

yarn add <package...> [--dev/-D]

Using --dev or -D will install one or more packages in your devDependencies.

yarn add <package...> [--peer/-P]

Using --peer or -P will install one or more packages in your peerDependencies.

yarn add <package...> [--optional/-O]

Using --optional or -O will install one or more packages in your optionalDependencies.

yarn add <package...> [--exact/-E]