- react-admin
-
scss-package
-
classnames
import classnames from 'classnames'; <div className={classNames('dog', { cat: true, fish: false })} />; // style <div className={classnames('bg-4', { [styles['home-wrap']]: true })}>
-
index.module.scss
-
最新 react-app 已默认加入 cssModule,自动映射作用域
import styles from 'index.module.scss'; const Home = () => { return <div className={styles.wrap}>...</div>; };
-
-
react-loadable: 暂时先移除,不需要支持服务端渲染
- 注意: 该库会导致 react 报警告: UNSAFE_componentWillMount...
- 需时刻关注该库的时候升级
-
React.lazy, Suspense: 原生进行代码分割
import { BrowserRouter as Router, Route, Switch } from 'react-router-dom'; import React, { Suspense, lazy } from 'react'; const Home = lazy(() => import(/* webpackChunkName: 'Home' */ './routes/Home')); const About = lazy(() => import(/* webpackChunkName: 'About' */ './routes/About')); const App = () => ( <Router> <Suspense fallback={<div>Loading...</div>}> <Switch> <Route exact path="/" component={Home} /> <Route path="/about" component={About} /> </Switch> </Suspense> </Router> );
- react-app-rewired customize-cra 去覆盖 webpack 的默认配置
- yarn add react-app-rewired customize-cra -D
// config-overrides.js
// 配置别名
const { override, addWebpackAlias } = require('customize-cra');
const path = require('path');
module.exports = override(
addWebpackAlias({
['@']: path.resolve(__dirname, 'src')
})
);
// 修改package.json中的scripts
"scripts": {
"start": "react-app-rewired start",
"build": "react-app-rewired build",
"test": "react-app-rewired test",
"eject": "react-scripts eject"
}
- obj?.name?.a?.b
- arr?.[0]