React+TypeScript+H5+Antd-mobile項(xiàng)目搭建

1. 創(chuàng)建React+TypeScript項(xiàng)目

create-react-app projectName --template typescript

2. 初始化GIT倉(cāng)庫(kù)

git init
git add .
git commit -m "init"

3. 暴露webpack配置文件

// 需要前面的初始化倉(cāng)庫(kù)支持
npm run eject

4. 添加less

yarn add less less-loader

5. 修改webpack配置(添加less)

找到webpack.config.js,添加

const lessRegex = /\.less$/
const lessModuleRegex = /\.module\.less$/
image

然后在module對(duì)象中的rules中解析less

// less
{
  test: lessRegex,
    exclude: lessModuleRegex,
    use: getStyleLoaders(
        {
            importLoaders: 3,
            sourceMap: isEnvProduction && shouldUseSourceMap
        },
        'less-loader'
    ),
    sideEffects: true
},
{
  test: lessModuleRegex,
    use: getStyleLoaders(
        {
            importLoaders: 3,
            sourceMap: isEnvProduction && shouldUseSourceMap,
            modules: {
                getLocalIdent: getCSSModuleLocalIdent
            }
        },
        'less-loader'
    )
}
image

6. 移動(dòng)端適配

添加lib-flexible和postcss-pxtorem

yarn add lib-flexible postcss-pxtorem

在index.tsx引入lib-flexible

import 'lib-flexible';
image

在webpack.config.js中配置postcss-pxtore插件,在postcssOptions中配置

[
    'postcss-pxtorem',
  {
    rootValue: 75,
    unitPrecision: 5,
    selectorBlackList: ['adm'], // 過濾antd-mobile插件
    propList: [*]
  }
]
image

7. 添加antd-mobile UI框架

antd-mobile官網(wǎng)

yarn add antd-mobile
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容