nomadro/apps/miniprogram/h5/config/index.ts
eric 3e5b7c2098 Monorepo super-optimize: src layout, workspace scripts, docs.
Collapse portal under src/, unify pnpm workspace/scripts, thin VIP topic re-exports, drop orphan vip scaffolds and one-shot scripts, ignore xhs/release, document root commands.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-10-01 00:34:04 +08:00

114 lines
3.2 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'
/** 本目录仅编 Taro H5;微信见上级 weapp 根,抖音见 tt/,小红书见 xhs/ */
const target = 'h5'
const defaultApi = process.env.TARO_APP_API || 'https://api.nomadro.cn'
const h5ViteProxy = {
'/ebook-api': {
target: process.env.TARO_H5_EBOOK_PROXY || 'https://api.nomadro.cn',
changeOrigin: true,
secure: false,
rewrite: (p: string) => p.replace(/^\/ebook-api/, ''),
},
'/community-api': {
target: process.env.TARO_H5_COMMUNITY_PROXY || 'https://nomadweb.nomadro.com',
changeOrigin: true,
secure: false,
rewrite: (p: string) => p.replace(/^\/community-api/, '/api/v1'),
},
'/api': {
target: process.env.TARO_H5_PROXY || 'https://nomadro.cn',
changeOrigin: true,
secure: false,
},
}
export default defineConfig(async (merge) => {
const baseConfig: UserConfigExport = {
projectName: 'nomadro-h5',
date: '2026-3-30',
designWidth: 750,
deviceRatio: {
640: 2.34 / 2,
750: 1,
375: 2,
828: 1.81 / 2,
},
sourceRoot: '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(target),
},
copy: {
patterns: [
{ from: 'src/assets/', to: 'assets/' },
{ from: path.resolve(__dirname, '..', 'src', 'public', 'icons'), to: 'icons' },
],
options: {},
},
framework: 'react',
compiler: {
type: 'vite',
vitePlugins: [
{
name: 'nomadro-spa-fallback',
configureServer(server: {
middlewares: { use: (fn: (req: { url?: string }, res: unknown, next: () => void) => void) => void }
}) {
server.middlewares.use((req, _res, next) => {
if (req.url === '/' || req.url === '') {
req.url = '/index.html'
}
next()
})
},
},
],
},
cache: { enable: false },
alias: {
'@': path.resolve(__dirname, '..', 'src'),
},
modifyViteConfig(viteConfig: { publicDir?: string; appType?: string }) {
viteConfig.publicDir = path.resolve(__dirname, '..', 'src', 'public')
viteConfig.appType = 'spa'
},
h5: {
publicPath: '/',
staticDirectory: 'static',
router: {
mode: 'hash',
},
devServer: {
host: '0.0.0.0',
port: 10086,
open: false,
proxy: h5ViteProxy,
},
postcss: {
autoprefixer: { enable: true },
cssModules: { enable: false },
// 对齐 Next:真实 px/rem,禁止 750 设计稿换算
pxtransform: {
enable: false,
},
},
},
}
if (process.env.NODE_ENV === 'development') {
return merge({}, baseConfig, { logger: { quiet: false, stats: true } })
}
return merge({}, baseConfig)
})