nomadro/apps/miniprogram/weapp/config/index.ts
Eric 3f7528f824 Add VIP knowledge community and device shop with native weapp UX.
Document memo/shop admin routes, deploy scripts, and cache-first feed performance in README.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-10-06 16:58:17 +08:00

119 lines
4.0 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[\\/]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)
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'] },
{ from: path.join(h5Src, 'public', 'icons'), to: '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'),
)
// eslint-disable-next-line @typescript-eslint/no-var-requires
const CopyWebpackPlugin = require('copy-webpack-plugin')
chain.plugin('nomadro-copy-icons').use(CopyWebpackPlugin, [
{
patterns: [
{
from: path.join(h5Src, 'public', 'icons'),
to: 'icons',
noErrorOnMissing: true,
},
],
},
])
},
mini: {
enableSourceMap: false,
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)
})