React大屏可視化腳手架教程示例
使用 create-react-app 初始化
# 使用了 create-react-app 的 typescript 模板 yarn create react-app my-big-screen --template typescript # 初始化之后進(jìn)入 my-big-screen 文件目錄下執(zhí)行 yarn start # localhost:3000 就能看到 react 的 hello 頁面了
引入 antd UI庫
# 在 根目錄 下 yarn add antd
使用 craco 插件來自定義配置
安裝 craco
yarn add @craco/craco
修改 package.json 文件如下
# 原本 "scripts": { "start": "react-scripts start", "build": "react-scripts build", "test": "react-scripts test", "eject": "react-scripts eject" } # 修改之后 "scripts": { "start": "craco start", "build": "craco build", "test": "craco test", "eject": "craco eject" }
在根目錄添加 craco.config.js 文件
module.exports = {}
自定義 antd 主題,使用 less 作為 css 預(yù)處理器
安裝 craco-antd
yarn add craco-antd
修改 craco.config.js 文件
const CracoAntDesignPlugin = require('craco-antd'); module.exports = { plugins: [ { plugin: CracoAntDesignPlugin, options: { customizeTheme: { '@primary-color': '#1DA57A', }, }, }, ], };
craco-less .module.less 模擬vue組件中style的scope 功能
craco-less 依賴 已經(jīng)內(nèi)置在 @craco/craco 依賴中,無需主動(dòng)安裝
配置 craco.config.js 文件
const CracoAntDesignPlugin = require('craco-antd') const CracoLessPlugin = require('craco-less') const { loaderByName } = require('@craco/craco') module.exports = { plugins: [ { plugin: CracoAntDesignPlugin, options: { customizeTheme: { '@primary-color': '#1DA57A' } } }, { plugin: CracoLessPlugin, options: { modifyLessRule(lessRule, context) { // You have to exclude these file suffixes first, // if you want to modify the less module's suffix lessRule.exclude = /\.m\.less$/ return lessRule }, modifyLessModuleRule(lessModuleRule, context) { // Configure the file suffix lessModuleRule.test = /\.m\.less$/ // Configure the generated local ident name. const cssLoader = lessModuleRule.use.find(loaderByName('css-loader')) cssLoader.options.modules = { localIdentName: '[local]_[hash:base64:5]' } return lessModuleRule } } } ] }
配置 * ./src/react-app-env.d.ts * 文件
/// <reference types="react-scripts" /> // 定義在 全局的 變量 然后就可以 window.* 進(jìn)行訪問了 interface Window { __REDUX_DEVTOOLS_EXTENSION_COMPOSE__: any AMap: any } declare module "*.module.less" { const classes: { readonly [key: string]: string }; export default classes; }
使用示例(類似vue scope 的效果)
# index.module.less 文件命名 app { font-size: 40px; color: #f00; }
# 在組件中引入 import styles from './index.module.less' <div className={styles['app']}>hello</div>
使用 ESLint Prettier 兩個(gè)插件來做代碼格式校驗(yàn)和自動(dòng)格式化
以上操作版本記錄
{ "name": "xxx", "version": "0.1.0", "private": true, "dependencies": { "@craco/craco": "^6.2.0", "@testing-library/jest-dom": "^5.11.4", "@testing-library/react": "^11.1.0", "@testing-library/user-event": "^12.1.10", "@types/jest": "^26.0.15", "@types/node": "^12.0.0", "@types/react": "^17.0.0", "@types/react-dom": "^17.0.0", "@types/react-router-dom": "^5.1.8", "@typescript-eslint/eslint-plugin": "^4.30.0", "@typescript-eslint/parser": "^4.30.0", "antd": "^4.16.13", "craco-antd": "^1.19.0", "eslint": "^7.32.0", "eslint-config-alloy": "^4.3.0", "eslint-loader": "^4.0.2", "eslint-plugin-react": "^7.25.1", "react": "^17.0.2", "react-dom": "^17.0.2", "react-redux": "^7.2.4", "react-router-dom": "^5.2.1", "react-scripts": "4.0.3", "typescript": "^4.1.2", "web-vitals": "^1.0.1" }, "scripts": { "start": "set PORT=3090 && craco start", "build": "craco build", "test": "craco test", "eject": "craco eject", "lint": "eslint '{src}/**/*.{ts,tsx,js,jsx}'", "lint_fix": "eslint {src} --ext .ts,.tsx,.js,jsx --fix" }, "browserslist": { "production": [ ">0.2%", "not dead", "not op_mini all" ], "development": [ "last 1 chrome version", "last 1 firefox version", "last 1 safari version" ] } }
以上就是React大屏可視化腳手架教程示例的詳細(xì)內(nèi)容,更多關(guān)于React大屏可視化腳手架的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!
相關(guān)文章
React中路由參數(shù)如何改變頁面不刷新數(shù)據(jù)的情況
這篇文章主要介紹了React中路由參數(shù)如何改變頁面不刷新數(shù)據(jù)的情況,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-08-08Remix后臺(tái)開發(fā)之remix-antd-admin配置過程
這篇文章主要為大家介紹了Remix后臺(tái)開發(fā)之remix-antd-admin配置過程詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-04-04React?Native?Modal?的封裝與使用實(shí)例詳解
這篇文章主要介紹了React?Native?Modal?的封裝與使用,本文通過實(shí)例代碼圖文相結(jié)合給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2022-09-09react清空ant.design中表單內(nèi)容的方法實(shí)現(xiàn)
本文主要介紹了react清空ant.design中表單內(nèi)容的方法實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2023-12-12react中使用redux-persist做持久化儲(chǔ)存的過程記錄
這篇文章主要介紹了react中使用redux-persist做持久化儲(chǔ)存的相關(guān)資料,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2024-01-01react項(xiàng)目引入antd框架方式以及遇到的一些坑
這篇文章主要介紹了react項(xiàng)目引入antd框架方式以及遇到的一些坑,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-03-03使用ReactJS實(shí)現(xiàn)tab頁切換、菜單欄切換、手風(fēng)琴切換和進(jìn)度條效果
這篇文章主要介紹了使用ReactJS實(shí)現(xiàn)tab頁切換、菜單欄切換、手風(fēng)琴切換和進(jìn)度條效果的相關(guān)資料,非常不錯(cuò),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2016-10-10