create-vite-taro 0.6.20 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # create-vite-taro
2
2
 
3
- Create a Vite 8 + React 19 + Taro app for WeChat Mini Program and Web targets.
3
+ Create a Vite 8 + React 19 + Taro app for WeChat Mini Program, Alipay Mini Program, and Web targets.
4
4
 
5
5
  > **AI-assisted development is recommended:** Follow the [VPT AI development guide](https://vpt.js.org/guides/ai/) and let a coding assistant create, develop, test, and validate your app.
6
6
 
package/index.js CHANGED
@@ -51,6 +51,7 @@ console.log('Next steps:')
51
51
  if (cdCommand) console.log(` ${cdCommand}`)
52
52
  console.log(` ${packageManager} install`)
53
53
  console.log(` ${getScriptCommand(packageManager, 'dev:wx')}`)
54
+ console.log(` ${getScriptCommand(packageManager, 'dev:zfb')}`)
54
55
  console.log(` ${getScriptCommand(packageManager, 'dev:h5')}`)
55
56
 
56
57
  function parseArgs(args) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "create-vite-taro",
3
- "version": "0.6.20",
4
- "description": "Create Vite 8 + React 19 + Taro apps for H5 and WeChat Mini Program targets.",
3
+ "version": "0.7.0",
4
+ "description": "Create Vite 8 + React 19 + Taro apps for WeChat, Alipay, and H5 targets.",
5
5
  "type": "module",
6
6
  "bin": {
7
7
  "create-vite-taro": "./index.js"
@@ -27,6 +27,7 @@
27
27
  "create",
28
28
  "react",
29
29
  "wechat",
30
+ "alipay",
30
31
  "mini-program"
31
32
  ],
32
33
  "author": "sep2",
@@ -1,6 +1,6 @@
1
1
  # VPT
2
2
 
3
- 基于 Vite 8、React 19、Taro 4、TypeScript 和 Tailwind CSS v4,一套代码运行于微信小程序和 Web。
3
+ 基于 Vite 8、React 19、Taro 4、TypeScript 和 Tailwind CSS v4,一套代码运行于微信小程序、支付宝小程序和 Web。
4
4
 
5
5
  - [文档](https://vpt.js.org)
6
6
  - [GitHub](https://github.com/sep2/vite-plugin-taro)
@@ -41,6 +41,22 @@ npm install
41
41
 
42
42
  开发期间保持命令运行。模板已开启热更新、关闭本地开发的 URL 校验,并默认关闭开发者工具中暂不支持热更新的 Skyline。
43
43
 
44
+ ### 支付宝小程序
45
+
46
+ 1. 在 `.env.local` 中填写支付宝 App ID:
47
+
48
+ ```dotenv
49
+ VITE_VPT_ALIPAY_APP_ID=2021000000000000
50
+ ```
51
+
52
+ 2. 启动开发构建:
53
+
54
+ ```sh
55
+ npm run dev:zfb
56
+ ```
57
+
58
+ 3. 用支付宝小程序开发者工具导入 `dist/zfb`,不要导入项目根目录。
59
+
44
60
  ### Web
45
61
 
46
62
  ```sh
@@ -58,9 +74,9 @@ import Taro from 'virtual:taro/api'
58
74
  import { Button, Text, View } from 'virtual:taro/components'
59
75
  ```
60
76
 
61
- 不要直接安装或导入 `@tarojs/*`。在 `vite.config.ts` 中添加页面并修改应用或微信项目配置。
77
+ 不要直接安装或导入 `@tarojs/*`。在 `vite.config.ts` 中添加页面,并按当前目标修改应用与开发工具项目配置。
62
78
 
63
- 模板包含条件编译、微信原生组件、懒加载、自定义导航栏、Tailwind CSS、CSS Modules 和全局样式示例;不需要的示例可直接删除。
79
+ 模板包含条件编译、微信原生组件、支付宝与 Web 共用的 Taro 组件、懒加载、自定义导航栏、Tailwind CSS、CSS Modules 和全局样式示例;不需要的示例可直接删除。
64
80
 
65
81
  ### 样式
66
82
 
@@ -68,23 +84,25 @@ import { Button, Text, View } from 'virtual:taro/components'
68
84
 
69
85
  ### 热更新
70
86
 
71
- 微信端热更新通常会保留 App 数据、当前页面、兼容的 React Hook 状态和原生输入值。修改 Vite 配置、组件或 Hook 结构不兼容,或更新无法安全应用时,会整页重载。详见[热更新指南](https://vpt.js.org/guides/hot-module-replacement/)。
87
+ 小程序端热更新通常会保留 App 数据、当前页面、兼容的 React Hook 状态和原生输入值。修改 Vite 配置、组件或 Hook 结构不兼容,或更新无法安全应用时,会整页重载。详见[热更新指南](https://vpt.js.org/guides/hot-module-replacement/)。
72
88
 
73
89
  ## 命令
74
90
 
75
91
  | 命令 | 用途 | 输出 |
76
92
  | --- | --- | --- |
77
93
  | `npm run dev:wx` | 开发微信小程序 | `dist/wx` |
94
+ | `npm run dev:zfb` | 开发支付宝小程序 | `dist/zfb` |
78
95
  | `npm run dev:h5` | 开发 Web | — |
79
96
  | `npm run build:wx` | 构建微信小程序 | `dist/wx` |
97
+ | `npm run build:zfb` | 构建支付宝小程序 | `dist/zfb` |
80
98
  | `npm run build:h5` | 构建 Web | `dist/h5` |
81
99
  | `npm run preview:h5` | 预览 Web 生产构建 | — |
82
100
  | `npm run typecheck` | TypeScript 类型检查 | — |
83
101
 
84
102
  ## 常见问题
85
103
 
86
- - **开发者工具无法打开项目:** 确认导入的是 `dist/wx`,且 `.env.local` 中的 App ID 可用。
87
- - **热更新失败:** 依次关闭微信开发者工具、停止 `dev:wx`、删除 `dist/wx`、重新运行 `npm run dev:wx`,再打开开发者工具并导入 `dist/wx`。
104
+ - **开发者工具无法打开项目:** 确认导入的是当前目标的 `dist/wx` 或 `dist/zfb`,且 `.env.local` 中对应的 App ID 可用。
105
+ - **热更新失败:** 关闭对应开发者工具,停止开发命令,删除当前目标的输出目录,重新运行 `dev:wx` `dev:zfb`,再导入生成目录。
88
106
  - **Tailwind 类未生效:** 保留 `src/app.css` 中的 `@source "./";`,并使用完整类名。
89
107
  - **pnpm 忽略依赖构建脚本:** 运行 `pnpm approve-builds`,批准所需脚本后重新安装。
90
108
 
@@ -1 +1,2 @@
1
1
  VITE_VPT_WECHAT_APP_ID=wx0000000000000000
2
+ VITE_VPT_ALIPAY_APP_ID=2021000000000000
@@ -5,8 +5,10 @@
5
5
  "type": "module",
6
6
  "scripts": {
7
7
  "dev:wx": "cross-env NODE_ENV=development VITE_VPT_TARGET=wx vite",
8
+ "dev:zfb": "cross-env NODE_ENV=development VITE_VPT_TARGET=zfb vite",
8
9
  "dev:h5": "cross-env NODE_ENV=development VITE_VPT_TARGET=h5 vite",
9
10
  "build:wx": "cross-env NODE_ENV=production VITE_VPT_TARGET=wx vite build",
11
+ "build:zfb": "cross-env NODE_ENV=production VITE_VPT_TARGET=zfb vite build",
10
12
  "build:h5": "cross-env NODE_ENV=production VITE_VPT_TARGET=h5 vite build",
11
13
  "preview:h5": "cross-env NODE_ENV=production VITE_VPT_TARGET=h5 vite preview --outDir dist/h5",
12
14
  "typecheck": "tsc -b"
@@ -21,9 +23,9 @@
21
23
  "@types/react-dom": "^19.2.5",
22
24
  "typescript": "^7.0.2",
23
25
  "cross-env": "^10.1.0",
24
- "rolldown": "1.2.5",
26
+ "rolldown": "1.2.7",
25
27
  "vite": "8.2.2",
26
- "vite-plugin-taro": "^0.6.20"
28
+ "vite-plugin-taro": "^0.7.0"
27
29
  },
28
30
  "overrides": {
29
31
  "@types/react": "$@types/react"
@@ -3,12 +3,10 @@ import { View } from 'virtual:taro/components'
3
3
  import type { PropsWithChildren } from 'react'
4
4
  import './app.css'
5
5
  import { Footer } from './components/footer/footer.tsx'
6
- import { initNavigationBar } from './components/navigation-bar/use-navigation-bar.ts'
7
6
 
8
7
  function App({ children }: PropsWithChildren) {
9
8
  useLaunch(() => {
10
9
  console.log('App launched')
11
- initNavigationBar()
12
10
  })
13
11
 
14
12
  return (
@@ -2,8 +2,8 @@
2
2
  import { NativeCounter } from './native-counter.tsx'
3
3
  // #endif
4
4
 
5
- // #ifdef h5
6
- import { WebCounter } from './web-counter.tsx'
5
+ // #ifndef wx
6
+ import { SharedCounter } from './shared-counter.tsx'
7
7
  // #endif
8
8
 
9
9
  export interface CounterProps {
@@ -17,7 +17,7 @@ export function Counter(props: CounterProps) {
17
17
  return <NativeCounter {...props} />
18
18
  // #endif
19
19
 
20
- // #ifdef h5
21
- return <WebCounter {...props} />
20
+ // #ifndef wx
21
+ return <SharedCounter {...props} />
22
22
  // #endif
23
23
  }
@@ -1,7 +1,7 @@
1
1
  import { Button, Text, View } from 'virtual:taro/components'
2
2
  import type { CounterProps } from './counter.tsx'
3
3
 
4
- export function WebCounter({ count, onDecrement, onIncrement }: CounterProps) {
4
+ export function SharedCounter({ count, onDecrement, onIncrement }: CounterProps) {
5
5
  return (
6
6
  <View className="flex flex-col rounded-2xl bg-surface-muted p-4">
7
7
  <Text className="text-center text-xs font-bold tracking-widest text-foreground">SHARED COUNTER</Text>
@@ -11,11 +11,11 @@ function px(value: number): string {
11
11
  }
12
12
 
13
13
  export function NavigationBar({ title }: NavigationBarProps) {
14
- const { navBar, menuInfo } = useNavigationBar()
15
- const containerStyle: CSSProperties = { height: px(navBar.height) }
16
- const statusBarStyle: CSSProperties = { height: px(navBar.top) }
17
- const contentStyle: CSSProperties = { padding: `${px(navBar.py)} ${px(navBar.px)}` }
18
- const sideStyle: CSSProperties = { flexBasis: px(menuInfo.width), width: px(menuInfo.width) }
14
+ const { height, top, paddingX, paddingY, menuWidth } = useNavigationBar()
15
+ const containerStyle: CSSProperties = { height: px(height) }
16
+ const statusBarStyle: CSSProperties = { height: px(top) }
17
+ const contentStyle: CSSProperties = { padding: `${px(paddingY)} ${px(paddingX)}` }
18
+ const sideStyle: CSSProperties = { flexBasis: px(menuWidth), width: px(menuWidth) }
19
19
 
20
20
  return (
21
21
  <View className="flex w-full flex-col text-primary" style={containerStyle}>
@@ -1,87 +1,95 @@
1
1
  import Taro from 'virtual:taro/api'
2
- import { useState } from 'react'
3
2
 
4
3
  const isWechatTarget = import.meta.env.VITE_VPT_TARGET === 'wx'
4
+ const isAlipayTarget = import.meta.env.VITE_VPT_TARGET === 'zfb'
5
5
 
6
- interface NavigationBarNavInfo {
6
+ interface NavigationBarMetrics {
7
7
  height: number
8
8
  top: number
9
- py: number
10
- px: number
9
+ paddingX: number
10
+ paddingY: number
11
+ menuWidth: number
11
12
  }
12
13
 
13
- interface NavigationBarMenuInfo {
14
- bottom: number
14
+ interface MenuButtonMetrics {
15
15
  height: number
16
- left: number
17
16
  right: number
18
17
  top: number
19
18
  width: number
20
19
  }
21
20
 
22
- interface NavigationBarInfo {
23
- navBar: NavigationBarNavInfo
24
- menuInfo: NavigationBarMenuInfo
21
+ /** Alipay fields narrowed from Taro's shared system-info result type. */
22
+ type AlipaySystemInfo = ReturnType<typeof Taro.getSystemInfoSync> & {
23
+ statusBarHeight: number
24
+ titleBarHeight: number
25
25
  }
26
26
 
27
- let navigationBarInfo: NavigationBarInfo = {
28
- navBar: { height: 0, top: 0, py: 0, px: 0 },
29
- menuInfo: { bottom: 0, height: 0, left: 0, right: 0, top: 0, width: 0 }
30
- }
31
-
32
- function createFallbackMenuInfo(screenWidth: number): NavigationBarMenuInfo {
33
- const width = 88
34
- const height = 32
35
- const top = 6
36
- const right = Math.max(width, screenWidth - 16)
27
+ // The app uses one immutable navigation layout per process; this mutable slot avoids repeated native reads across Page mounts.
28
+ let cachedNavigationBarMetrics: NavigationBarMetrics | undefined
37
29
 
30
+ function getFallbackMenuButtonMetrics(screenWidth: number): MenuButtonMetrics {
38
31
  return {
39
- bottom: top + height,
40
- height,
41
- left: right - width,
42
- right,
43
- top,
44
- width
32
+ height: 32,
33
+ right: Math.max(88, screenWidth - 16),
34
+ top: 6,
35
+ width: 88
45
36
  }
46
37
  }
47
38
 
48
- function getMenuInfo(screenWidth: number): NavigationBarMenuInfo {
39
+ function getMenuButtonMetrics(screenWidth: number): MenuButtonMetrics {
49
40
  if (isWechatTarget) {
50
- const menuButtonInfo = Taro.getMenuButtonBoundingClientRect()
51
- if (menuButtonInfo.width > 0 && menuButtonInfo.height > 0) return menuButtonInfo
41
+ const menuButtonMetrics = Taro.getMenuButtonBoundingClientRect()
42
+ if (menuButtonMetrics.width > 0 && menuButtonMetrics.height > 0) return menuButtonMetrics
52
43
  }
53
44
 
54
- return createFallbackMenuInfo(screenWidth)
45
+ return getFallbackMenuButtonMetrics(screenWidth)
55
46
  }
56
47
 
57
- export function initNavigationBar(): NavigationBarInfo {
58
- const windowInfo = Taro.getWindowInfo()
59
- const screenWidth = windowInfo.screenWidth || 375
60
- const statusBarHeight = isWechatTarget ? (windowInfo.statusBarHeight ?? 44) : 0
61
- const menuInfo = getMenuInfo(screenWidth)
62
- const menuButtonStatusBarGap = Math.max(0, menuInfo.top - statusBarHeight)
63
- const navBarHeight = menuButtonStatusBarGap * 2 + menuInfo.height + statusBarHeight
64
- const paddingX = Math.max(0, screenWidth - menuInfo.right)
65
-
66
- navigationBarInfo = {
67
- navBar: {
68
- height: navBarHeight,
69
- top: statusBarHeight,
70
- py: menuButtonStatusBarGap,
71
- px: paddingX
72
- },
73
- menuInfo
48
+ function getAlipayNavigationBarMetrics(systemInfo: AlipaySystemInfo): NavigationBarMetrics {
49
+ const { statusBarHeight, titleBarHeight } = systemInfo
50
+
51
+ return {
52
+ height: statusBarHeight + titleBarHeight,
53
+ top: statusBarHeight,
54
+ paddingX: 16,
55
+ paddingY: (titleBarHeight - 32) / 2,
56
+ menuWidth: 88
74
57
  }
58
+ }
59
+
60
+ function getNavigationBarMetrics(
61
+ screenWidth: number,
62
+ statusBarHeight: number,
63
+ menuButtonMetrics: MenuButtonMetrics
64
+ ): NavigationBarMetrics {
65
+ const menuButtonStatusBarGap = Math.max(0, menuButtonMetrics.top - statusBarHeight)
75
66
 
76
- return navigationBarInfo
67
+ return {
68
+ height: menuButtonStatusBarGap * 2 + menuButtonMetrics.height + statusBarHeight,
69
+ top: statusBarHeight,
70
+ paddingX: Math.max(0, screenWidth - menuButtonMetrics.right),
71
+ paddingY: menuButtonStatusBarGap,
72
+ menuWidth: menuButtonMetrics.width
73
+ }
77
74
  }
78
75
 
79
- function getNavigationBarInfo(): NavigationBarInfo {
80
- if (navigationBarInfo.navBar.height > 0) return navigationBarInfo
81
- return initNavigationBar()
76
+ function getNavigationBarMetricsCached(): NavigationBarMetrics {
77
+ if (cachedNavigationBarMetrics) return cachedNavigationBarMetrics
78
+
79
+ if (isAlipayTarget) {
80
+ cachedNavigationBarMetrics = getAlipayNavigationBarMetrics(Taro.getSystemInfoSync() as AlipaySystemInfo)
81
+ return cachedNavigationBarMetrics
82
+ }
83
+
84
+ const windowInfo = Taro.getWindowInfo()
85
+ const screenWidth = windowInfo.screenWidth || 375
86
+ const statusBarHeight = isWechatTarget ? (windowInfo.statusBarHeight ?? 44) : 0
87
+ const menuButtonMetrics = getMenuButtonMetrics(screenWidth)
88
+
89
+ cachedNavigationBarMetrics = getNavigationBarMetrics(screenWidth, statusBarHeight, menuButtonMetrics)
90
+ return cachedNavigationBarMetrics
82
91
  }
83
92
 
84
- export function useNavigationBar(): NavigationBarInfo {
85
- const [currentNavigationBarInfo] = useState(getNavigationBarInfo)
86
- return currentNavigationBarInfo
93
+ export function useNavigationBar(): NavigationBarMetrics {
94
+ return getNavigationBarMetricsCached()
87
95
  }
@@ -1,3 +1,3 @@
1
1
  interface ImportMetaEnv {
2
- readonly VITE_VPT_TARGET: 'wx' | 'h5'
2
+ readonly VITE_VPT_TARGET: 'wx' | 'zfb' | 'h5'
3
3
  }
@@ -1,12 +1,13 @@
1
1
  import path from 'node:path'
2
2
  import { fileURLToPath } from 'node:url'
3
3
  import { defineConfig, loadEnv } from 'vite'
4
- import vpt, { type VptTarget } from 'vite-plugin-taro'
4
+ import vpt, { type VptJsonObject, type VptTarget } from 'vite-plugin-taro'
5
5
 
6
6
  export default defineConfig(({ mode }) => {
7
7
  const env = loadEnv(mode, process.cwd(), 'VITE_VPT_')
8
8
  const target = getTarget(env)
9
- const wechatAppId = env.VITE_VPT_WECHAT_APP_ID || 'touristappid'
9
+ const wechatAppId = env.VITE_VPT_WECHAT_APP_ID
10
+ const alipayAppId = env.VITE_VPT_ALIPAY_APP_ID
10
11
 
11
12
  return {
12
13
  build: {
@@ -19,73 +20,177 @@ export default defineConfig(({ mode }) => {
19
20
  pages: [
20
21
  {
21
22
  path: 'pages/home/index',
22
- config: {
23
- navigationStyle: 'custom',
24
- navigationBarTextStyle: 'black'
25
- }
23
+ config: createPageJson(target)
26
24
  }
27
25
  ],
28
- appJson: {
29
- lazyCodeLoading: 'requiredComponents',
30
- window: {
31
- navigationStyle: 'custom',
32
- navigationBarTextStyle: 'black'
33
- },
34
- renderer: 'skyline',
35
- componentFramework: 'glass-easel',
36
- rendererOptions: {
37
- skyline: {
38
- defaultDisplayBlock: true,
39
- defaultContentBox: true
40
- }
41
- }
26
+ appJson: createAppJson(target),
27
+ projectConfigJson: createProjectConfigJson({ target, wechatAppId, alipayAppId }),
28
+ projectPrivateConfigJson: createProjectPrivateConfigJson(target),
29
+ sitemapJson: { rules: [{ action: 'allow', page: '*' }] },
30
+ hmr: {
31
+ mode: target === 'zfb' ? 'interpreter' : 'devtools'
42
32
  },
43
- projectConfigJson: {
44
- appid: wechatAppId,
45
- projectname: 'vite-taro-app',
46
- description: '',
47
- compileType: 'miniprogram',
48
- setting: {
49
- // WeChat DevTools does not support hot reload with Skyline yet.
50
- skylineRenderEnable: false,
51
- urlCheck: false,
52
- es6: false,
53
- postcss: false,
54
- minified: false,
55
- compileHotReLoad: true,
56
- enhance: false,
57
- uglifyFileName: false,
58
- preloadBackgroundData: false,
59
- newFeature: true,
60
- autoAudits: false,
61
- coverView: true,
62
- showShadowRootInWxmlPanel: false,
63
- scopeDataCheck: false,
64
- useCompilerModule: false
33
+ })
34
+ ]
35
+ }
36
+ })
37
+
38
+ function createPageJson(target: VptTarget): VptJsonObject {
39
+ switch (target) {
40
+ case 'wx': {
41
+ return {
42
+ navigationStyle: 'custom',
43
+ navigationBarTextStyle: 'black'
44
+ }
45
+ }
46
+ case 'zfb': {
47
+ return {
48
+ transparentTitle: 'always',
49
+ titlePenetrate: 'YES'
50
+ }
51
+ }
52
+ default: {
53
+ return {}
54
+ }
55
+ }
56
+ }
57
+
58
+ function createAppJson(target: VptTarget): VptJsonObject {
59
+ switch (target) {
60
+ case 'wx': {
61
+ return {
62
+ lazyCodeLoading: 'requiredComponents',
63
+ renderer: 'skyline',
64
+ componentFramework: 'glass-easel',
65
+ glassEaselWebview: true,
66
+ rendererOptions: {
67
+ skyline: {
68
+ defaultDisplayBlock: true,
69
+ defaultContentBox: true
65
70
  }
66
71
  },
67
- projectPrivateConfigJson: {
68
- setting: {
69
- urlCheck: false
72
+ window: {
73
+ navigationStyle: 'custom',
74
+ navigationBarTextStyle: 'black'
75
+ }
76
+ }
77
+ }
78
+ case 'zfb': {
79
+ return {
80
+ lazyCodeLoading: 'renderedComponents',
81
+ useDynamicPlugins: true,
82
+ window: {
83
+ transparentTitle: 'always',
84
+ titlePenetrate: 'YES'
85
+ }
86
+ }
87
+ }
88
+ default: {
89
+ return {}
90
+ }
91
+ }
92
+ }
93
+
94
+ function createProjectConfigJson({
95
+ target,
96
+ wechatAppId,
97
+ alipayAppId
98
+ }: {
99
+ target: VptTarget
100
+ wechatAppId: string
101
+ alipayAppId: string | undefined
102
+ }): VptJsonObject {
103
+ switch (target) {
104
+ case 'wx': {
105
+ return {
106
+ appid: wechatAppId,
107
+ projectname: 'vpt-project',
108
+ description: '',
109
+ compileType: 'miniprogram',
110
+ setting: {
111
+ skylineRenderEnable: false,
112
+ urlCheck: false,
113
+ es6: false,
114
+ postcss: false,
115
+ minified: false,
116
+ enhance: false,
117
+ uglifyFileName: false,
118
+ minifyWXSS: false,
119
+ minifyWXML: false,
120
+ compileHotReLoad: true,
121
+ preloadBackgroundData: false,
122
+ newFeature: true,
123
+ autoAudits: false,
124
+ coverView: true,
125
+ showShadowRootInWxmlPanel: false,
126
+ scopeDataCheck: false,
127
+ useCompilerModule: false
128
+ }
129
+ }
130
+ }
131
+ case 'zfb': {
132
+ return {
133
+ appid: alipayAppId,
134
+ miniprogramRoot: './',
135
+ format: 2,
136
+ compileOptions: {
137
+ component2: true,
138
+ globalObjectMode: 'enable',
139
+ transpile: {
140
+ script: {
141
+ ignore: ['**']
142
+ }
70
143
  }
71
144
  },
72
- sitemapJson: {
73
- rules: [{ action: 'allow', page: '*' }]
145
+ developOptions: {
146
+ lazyCompile: false,
147
+ hotReload: true,
148
+ skipTranspile: true,
149
+ sourcemap: false,
150
+ minify: false
74
151
  }
75
- })
76
- ]
152
+ }
153
+ }
154
+ default: {
155
+ return {}
156
+ }
77
157
  }
78
- })
158
+ }
79
159
 
80
- const targetEnvName = 'VITE_VPT_TARGET'
81
- const projectRoot = fileURLToPath(new URL('.', import.meta.url))
160
+ function createProjectPrivateConfigJson(target: VptTarget): VptJsonObject {
161
+ switch (target) {
162
+ case 'wx': {
163
+ return {
164
+ setting: {
165
+ urlCheck: false
166
+ }
167
+ }
168
+ }
169
+ case 'zfb': {
170
+ return {
171
+ ignoreHttpDomainCheck: true,
172
+ ignoreCertificateDomainCheck: true,
173
+ ignoreWebViewDomainCheck: true
174
+ }
175
+ }
176
+ default:
177
+ return {}
178
+ }
179
+ }
82
180
 
83
181
  function getTarget(env: Record<string, string>): VptTarget {
182
+ const targetEnvName = 'VITE_VPT_TARGET'
183
+
84
184
  const target = env[targetEnvName]
85
- if (target === 'wx' || target === 'h5') return target
86
- throw new Error(`${targetEnvName} must be "wx" or "h5".`)
185
+
186
+ if (target === 'wx' || target === 'zfb' || target === 'h5') {
187
+ return target
188
+ }
189
+
190
+ throw new Error(`${targetEnvName} must be "wx", "zfb", or "h5".`)
87
191
  }
88
192
 
193
+ const projectRoot = fileURLToPath(new URL('.', import.meta.url))
89
194
  function fromRoot(...segments: string[]): string {
90
195
  return path.resolve(projectRoot, ...segments)
91
196
  }