nomadro/apps/miniprogram/weapp/config/index.ts
Eric dc7a46ee0b Make WeChat launch path pages/home/index and document the index redirect.
Keep 20261011 hub visuals on home; index only reLaunches to avoid missing page wxss.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-10-11 16:03:31 +08:00

127 lines
4.4 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 path from 'path'
import { defineConfig, type UserConfigExport } from '@tarojs/cli'
/** WeChat weapp only; sourceRoot shares ../h5/src */
const target = process.env.TARO_APP_TARGET || process.env.TARO_ENV || 'weapp'
if (target === 'h5') {
throw new Error(
'[nomadro] H5 is apps/miniprogram/h5 — use: pnpm --dir h5 dev',
)
}
const defaultApi = process.env.TARO_APP_API || 'https://api.nomadro.cn'
const h5Src = path.resolve(__dirname, '..', '..', 'h5', 'src')
/** 与门户同源视觉:这些表用真实 px/rem,禁止 750→rpx */
const pxExclude = (file: string) =>
/[\\/]styles[\\/]hub\.scss/.test(file) ||
/[\\/]styles[\\/]navmini\.scss/.test(file) ||
/[\\/]styles[\\/]ebook-cover\.scss/.test(file) ||
/[\\/]styles[\\/]community\.scss/.test(file) ||
/[\\/]styles[\\/]community-navbar\.scss/.test(file) ||
/[\\/]styles[\\/]portal-nav-h5\.scss/.test(file) ||
/[\\/]styles[\\/]vip-landing\.scss/.test(file) ||
/[\\/]styles[\\/]h5-theme\.scss/.test(file) ||
/[\\/]styles[\\/]weapp-parity\.scss/.test(file) ||
/[\\/]styles[\\/]page-rem\.scss/.test(file) ||
/[\\/]pages[\\/]home[\\/]index\.scss/.test(file) ||
/[\\/]pages[\\/]index[\\/]index\.scss/.test(file) ||
/[\\/]pages[\\/]nav[\\/]index\.scss/.test(file) ||
/[\\/]pages[\\/]book[\\/]index\.scss/.test(file) ||
/[\\/]pages[\\/]community[\\/]index\.scss/.test(file) ||
/[\\/]pages[\\/]vip[\\/]index\.scss/.test(file) ||
/[\\/]pages[\\/]vip-course[\\/]index\.scss/.test(file) ||
/[\\/]pages[\\/]vip-lesson[\\/]index\.scss/.test(file) ||
/[\\/]pages[\\/]vip-ebook[\\/]index\.scss/.test(file) ||
/[\\/]pages[\\/]vip-store[\\/]index\.scss/.test(file) ||
/[\\/]pages[\\/]vip-store-detail[\\/]index\.scss/.test(file) ||
/[\\/]pages[\\/]vip-store-orders[\\/]index\.scss/.test(file) ||
/[\\/]pages[\\/]vip-memo[\\/]index\.scss/.test(file) ||
/[\\/]pages[\\/]vip-memo-detail[\\/]index\.scss/.test(file) ||
/[\\/]components[\\/]DebugFab\.scss/.test(file)
export default defineConfig(async (merge) => {
const baseConfig: UserConfigExport = {
projectName: 'nomadro-weapp',
date: '2026-3-30',
designWidth: 750,
deviceRatio: {
640: 2.34 / 2,
750: 1,
375: 2,
828: 1.81 / 2,
},
sourceRoot: '../h5/src',
outputRoot: 'dist',
plugins: ['@tarojs/plugin-framework-react'],
defineConstants: {
TARO_APP_API: JSON.stringify(defaultApi),
TARO_APP_COMMUNITY_API: JSON.stringify(
process.env.TARO_APP_COMMUNITY_API || 'https://nomadweb.nomadro.com/api/v1',
),
TARO_APP_GATEWAY: JSON.stringify(
process.env.TARO_APP_GATEWAY || process.env.TARO_APP_API || defaultApi,
),
TARO_APP_TARGET: JSON.stringify('weapp'),
},
copy: {
patterns: [
{
from: path.join(h5Src, 'assets'),
to: 'assets/',
ignore: ['**/.DS_Store', '**/icons/**'],
},
],
options: {},
},
framework: 'react',
compiler: {
type: 'webpack5',
prebundle: { enable: false },
},
cache: { enable: true },
alias: {
'@': h5Src,
},
modifyWebpackChain(chain) {
const weappNm = path.resolve(__dirname, '..', 'node_modules')
chain.resolve.modules.prepend(weappNm)
chain.resolve.alias.set(
'@tarojs/plugin-platform-weapp',
path.join(weappNm, '@tarojs/plugin-platform-weapp'),
)
// 导航图标不进包:运行时用 https://nomadro.cn/icons(代码质量:图片合计≤200K)
// watch 完成后补缺失页面 wxss(home/index 样式进 common 时 Taro 不落文件)
// eslint-disable-next-line @typescript-eslint/no-var-requires
const { EnsurePageWxssPlugin } = require(path.join(
__dirname,
'..',
'scripts',
'ensure-page-wxss-plugin.cjs',
))
chain.plugin('ensure-page-wxss').use(EnsurePageWxssPlugin, [
{ pagesRoot: path.resolve(__dirname, '..', 'dist', 'pages') },
])
},
mini: {
enableSourceMap: false,
/** 分包独占依赖不进主包 common(压主包 ≤1.5MB) */
optimizeMainPackage: {
enable: true,
},
postcss: {
pxtransform: {
enable: true,
config: { exclude: pxExclude },
},
cssModules: { enable: false },
},
},
}
if (process.env.NODE_ENV === 'development') {
return merge({}, baseConfig, { logger: { quiet: false, stats: true } })
}
return merge({}, baseConfig)
})