bw-mini-app/config/index.ts

147 lines
3.9 KiB
TypeScript
Raw Permalink 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: 'assets',
router: {
mode: 'browser'
},
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
},
},
},
};
// Set browserslist environment for legacy plugin
if (process.env.TARO_ENV === 'h5') {
process.env.BROWSERSLIST_ENV = process.env.NODE_ENV === 'production' ? 'production' : 'default';
}
if (process.env.NODE_ENV === 'development') {
// 本地开发构建配置(不混淆压缩)
return merge({}, baseConfig, devConfig);
}
// 生产构建配置(默认开启压缩混淆等)
return merge({}, baseConfig, prodConfig);
});