微信小程序端修改config服务器地址配置

This commit is contained in:
2026-07-21 07:35:39 +08:00
parent 47b39e3ba0
commit ade68972a9
6 changed files with 18 additions and 15 deletions
+5 -2
View File
@@ -9,8 +9,11 @@
pnpm --filter @dukang/mini-user dev
# → http://localhost:5177
# 微信小程序
# 微信小程序(本地联调,development
pnpm --filter @dukang/mini-user dev:weapp
# 微信小程序(生产构建 → API: https://api.dukanghaoke.com
pnpm build:mini-user:weapp
# 用微信开发者工具打开 apps/mini-userminiprogramRoot = dist/
```
@@ -18,7 +21,7 @@ pnpm --filter @dukang/mini-user dev:weapp
| 环节 | 文件 | 说明 |
|------|------|------|
| **编译注入** | `config/index.ts``defineConstants.TARO_APP_API_ORIGIN` | 本地默认 `http://localhost:3000``NODE_ENV=production` 默认 `https://api.dukanghaoke.com`;可用 `VITE_API_TARGET` 覆盖 |
| **编译注入** | `config/index.ts``defineConstants.TARO_APP_API_ORIGIN` | `dev:weapp` / watch → `localhost:3000``build:weapp``--mode production`)→ `https://api.dukanghaoke.com`;可用 `VITE_API_TARGET` 覆盖 |
| **运行时拼装** | `src/lib/api.ts``resolveApiBase()` | `{origin}/api/v1` |
### 微信登录 `invalid code`
+8 -2
View File
@@ -2,10 +2,16 @@ import { createRequire } from 'node:module';
import path from 'node:path';
import { defineConfig } from '@tarojs/cli';
/** watch / --mode development 视为本地联调;其余(含 build:weapp)走生产 */
const isDevMode =
process.env.NODE_ENV === 'development' ||
process.argv.includes('--watch') ||
process.argv.includes('development');
/** 小程序/H5 请求的后端 origin(不含 /api);本地默认本机,生产构建默认远程 */
const API_ORIGIN =
process.env.VITE_API_TARGET ??
(process.env.NODE_ENV === 'production' ? 'https://api.dukanghaoke.com' : 'http://localhost:3000');
(isDevMode ? 'http://localhost:3000' : 'https://api.dukanghaoke.com');
const requireFromApp = createRequire(path.resolve(__dirname, '../package.json'));
@@ -91,7 +97,7 @@ export default defineConfig(async () => ({
},
mini: {
/** dev:weapp 预览模式需开启,否则 React hooks 在 Vite 下会失效 */
debugReact: process.env.NODE_ENV !== 'production',
debugReact: isDevMode,
postcss: {
pxtransform: { enable: true, config: {} },
cssModules: { enable: false },
+2 -2
View File
@@ -7,8 +7,8 @@
"dev": "node ../../scripts/dev-mini-user-h5.mjs",
"dev:vite": "node --max-old-space-size=8192 ./node_modules/@tarojs/cli/bin/taro build --type h5 --watch",
"dev:weapp": "node --max-old-space-size=8192 ./node_modules/@tarojs/cli/bin/taro build --type weapp --watch --mode development",
"build": "node --max-old-space-size=8192 ./node_modules/@tarojs/cli/bin/taro build --type h5",
"build:weapp": "node --max-old-space-size=8192 ./node_modules/@tarojs/cli/bin/taro build --type weapp",
"build": "node --max-old-space-size=8192 ./node_modules/@tarojs/cli/bin/taro build --type h5 --mode production",
"build:weapp": "node --max-old-space-size=8192 ./node_modules/@tarojs/cli/bin/taro build --type weapp --mode production",
"lint": "echo ok"
},
"dependencies": {
+1 -7
View File
@@ -39,19 +39,13 @@ body::-webkit-scrollbar,
#app::-webkit-scrollbar,
.taro_page::-webkit-scrollbar,
.taro_router::-webkit-scrollbar,
.taro-tabbar__panel::-webkit-scrollbar,
*::-webkit-scrollbar {
.taro-tabbar__panel::-webkit-scrollbar {
width: 0 !important;
height: 0 !important;
display: none !important;
background: transparent;
}
* {
scrollbar-width: none;
-ms-overflow-style: none;
}
/* H5:页面内已渲染 UserTabBar,隐藏 Taro 自带底栏,避免双层 Tab */
.taro-tabbar__tabbar,
.taro-tabbar__border {