Files
bw-mini-app/config/index.ts
iHeyTang 9d890478d8 feat(config): enhance development configuration and update platform support
- Added `devServer` configuration for H5 platform to allow file system access.
- Updated platform type to include 'h5' in the factory.
- Adjusted icon paths in app configuration for consistency.
- Cleaned up code formatting and removed deprecated Redux store documentation.
2025-09-26 15:07:00 +08:00

142 lines
3.7 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: [
{
from: 'src/assets/icons/',
to: 'assets/icons/',
},
],
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);
});