nomadro/apps/miniprogram/weapp/config/index.ts
eric 98a54730ff Port nomadvip VIP into native WeChat pages and document the flow.
Add vip-course/lesson/ebook with source markdown seeds, VIP order API + admin offers, ban web-view for content, and update READMEs for weapp rebuild/extract scripts.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-10-04 22:30:27 +08:00

114 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 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)
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)
})