在react中使用windicss的問題
更新時間:2022年10月09日 10:27:07 作者:qq_48557089
這篇文章主要介紹了在react中使用windicss的問題,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
react使用windicss
參考官方文檔 Webpack 集成 {#integration-for-webpack} | Windi CSS

react 支持craco框架
windicss有什么不理解的可以參考 Tailwind CSS 中文文檔
1. 安裝 windicss架構(gòu)
yarn add windicss-webpack-plugin -D # npm i windicss-webpack-plugin -D
2. 安裝craco
npm install @craco/craco
3. 根目錄下創(chuàng)建 craco.config.js
// craco.config.js?
?
const WindiCSSWebpackPlugin = require('windicss-webpack-plugin')
?
module.exports = {
? // ...
? webpack: {
? ? plugins: {
? ? ? add: [
? ? ? ? new WindiCSSWebpackPlugin({
? ? ? ? ? virtualModulePath: 'src',
? ? ? ? }),
? ? ? ],
? ? },
? },
}4. 修改package.json
將react-scripts修改為craco
// package.json?
?
"scripts": {
? - "start": "react-scripts start",
? - "build": "react-scripts build",
? - "test": "react-scripts test",
? - "eject": "react-scripts eject"
?
? + "start": "craco start",
? + "build": "craco build",
? + "test": "craco test",
? + "eject": "craco eject"5. 在src/index.js 添加如下內(nèi)容
import './virtual:windi.css'
6. 根目錄下創(chuàng)建 windi.config.js
// windi.config.js?
?
import { defineConfig } from 'windicss/helpers'
?
export default defineConfig({
? extract: {
? ? include: ['**/*.{jsx,js,css,html}'],
? ? exclude: ['node_modules', '.git', '.next'],
? },
})以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關(guān)文章
react-draggable實現(xiàn)拖拽功能實例詳解
這篇文章主要給大家介紹了關(guān)于react-draggable實現(xiàn)拖拽功能的相關(guān)資料,React-Draggable一個使元素可拖動的簡單組件,文中通過代碼示例介紹的非常詳細,需要的朋友可以參考下2023-08-08
基于React的狀態(tài)管理實現(xiàn)一個簡單的顏色轉(zhuǎn)換器
這篇文章主要介紹了用React的狀態(tài)管理,簡簡單單實現(xiàn)一個顏色轉(zhuǎn)換器,文中有詳細的代碼示例供大家參考,具有一定的參考價值,需要的朋友可以參考下2023-08-08
React router cache route實現(xiàn)緩存頁面流程介紹
react-router自身沒有路由緩存的特性,在5.x版本之前,我們可以基于react-router-cache-route來實現(xiàn)路由緩存功能。但是react-router 6.x在實現(xiàn)上做了比較大的變化,react-router-cache-route沒有提供相應的支持2023-01-01

