webpack4脚手架搭建-react版

143 阅读1分钟

承接 基础版

实现功能:

  • 模块热替换
  • 路由管理
  • 菜单配置
  • 状态管理
  • 追加react语法检测

预期实现功能

  • state范式化

添加react相关

基础

  • 基础依赖
    npm install --save react react-dom
  • 兼容与优化
    npm install --save-dev babel-preset-react babel-preset-react-optimize
  • 热替换
    npm install --save-dev react-hot-loader
    配置:
    1.组件需添加一层
    import React from 'react'
    import { hot } from 'react-hot-loader'
    const App = () =>
    Hello world!
    export default hot(module)(App)
  • 语法检测 npm install --save-dev eslint-plugin-react eslint-plugin-jsx-a11y
    配置:
    1. .eslintrc.js配置文件添加:
      plugins: ['react'],
      extends: ['eslint:recommended', 'plugin:react/recommended'],

路由

npm install --save react-router react-router-dom

状态管理

npm install --save redux react-redux redux-thunk redux-logger

其他

相关链接

完整代码,移步 项目