Files
bw-mini-app/config/index.ts
imeepos 14205a9021 feat: 配置 TailwindCSS 并迁移到 Redux
- 配置 TailwindCSS 支持小程序开发
  - 安装 tailwindcss, postcss, autoprefixer
  - 安装 weapp-tailwindcss 插件支持小程序
  - 配置 tailwind.config.js 和 postcss.config.js
  - 更新 Taro 配置支持 TailwindCSS

- 从 Zustand 迁移到 Redux Toolkit
  - 移除 zustand 依赖
  - 安装 redux, react-redux, redux-thunk, @reduxjs/toolkit
  - 重构状态管理架构:
    - src/constants/ - Action 类型常量
    - src/actions/ - Action creators 和异步 actions
    - src/reducers/ - Reducers
    - src/selectors/ - 状态选择器
    - src/hooks/redux.ts - 类型化 hooks
  - 更新组件使用新的 Redux API
  - 保持数据持久化功能

- 更新应用配置
  - 将 app.ts 重命名为 app.tsx 支持 JSX
  - 添加 Redux Provider 到应用根组件
  - 更新 TODO.md 标记完成状态

- 构建验证通过,所有功能正常
2025-09-03 16:33:06 +08:00

142 lines
3.6 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { defineConfig, type UserConfigExport } from '@tarojs/cli'
import { UnifiedWebpackPluginV5 } from 'weapp-tailwindcss/webpack'
import devConfig from './dev'
import prodConfig from './prod'
// https://taro-docs.jd.com/docs/next/config#defineconfig-辅助函数
export default defineConfig<'vite'>(async (merge) => {
// 不同平台的 appId 配置
const appIds = {
weapp: process.env.TARO_APP_ID_WEAPP || 'your-weapp-appid',
tt: process.env.TARO_APP_ID_TT || 'your-tt-appid',
alipay: process.env.TARO_APP_ID_ALIPAY || 'your-alipay-appid',
swan: process.env.TARO_APP_ID_SWAN || 'your-swan-appid',
qq: process.env.TARO_APP_ID_QQ || 'your-qq-appid',
jd: process.env.TARO_APP_ID_JD || 'your-jd-appid'
}
const baseConfig: UserConfigExport<'vite'> = {
projectName: 'bw-mini-app',
date: '2025-9-1',
designWidth: 750,
deviceRatio: {
640: 2.34 / 2,
750: 1,
375: 2,
828: 1.81 / 2
},
sourceRoot: 'src',
outputRoot: process.env.TARO_ENV ? `dist/${process.env.TARO_ENV}` : 'dist',
plugins: [
"@tarojs/plugin-generator"
],
defineConstants: {
},
copy: {
patterns: [
],
options: {
}
},
framework: 'react',
compiler: 'vite',
mini: {
postcss: {
pxtransform: {
enable: true,
config: {
}
},
cssModules: {
enable: false, // 默认为 false如需使用 css modules 功能,则设为 true
config: {
namingPattern: 'module', // 转换模式,取值为 global/module
generateScopedName: '[name]__[local]___[hash:base64:5]'
}
}
},
webpackChain(chain) {
chain.merge({
plugin: {
install: {
plugin: UnifiedWebpackPluginV5,
args: [{
appType: 'taro',
// 下面个配置,会开启 rem -> rpx 的转化
rem2rpx: true
}]
}
}
})
}
},
// 小程序平台特定配置
weapp: {
outputRoot: 'dist/weapp',
appId: appIds.weapp
},
tt: {
outputRoot: 'dist/tt',
appId: appIds.tt
},
alipay: {
outputRoot: 'dist/alipay',
appId: appIds.alipay
},
swan: {
outputRoot: 'dist/swan',
appId: appIds.swan
},
qq: {
outputRoot: 'dist/qq',
appId: appIds.qq
},
jd: {
outputRoot: 'dist/jd',
appId: appIds.jd
},
h5: {
publicPath: '/',
staticDirectory: 'static',
miniCssExtractPluginOption: {
ignoreOrder: true,
filename: 'css/[name].[hash].css',
chunkFilename: 'css/[name].[chunkhash].css'
},
postcss: {
autoprefixer: {
enable: true,
config: {}
},
cssModules: {
enable: false, // 默认为 false如需使用 css modules 功能,则设为 true
config: {
namingPattern: 'module', // 转换模式,取值为 global/module
generateScopedName: '[name]__[local]___[hash:base64:5]'
}
}
},
},
rn: {
appName: 'taroDemo',
postcss: {
cssModules: {
enable: false, // 默认为 false如需使用 css modules 功能,则设为 true
}
}
}
}
process.env.BROWSERSLIST_ENV = process.env.NODE_ENV
if (process.env.NODE_ENV === 'development') {
// 本地开发构建配置(不混淆压缩)
return merge({}, baseConfig, devConfig)
}
// 生产构建配置(默认开启压缩混淆等)
return merge({}, baseConfig, prodConfig)
})