create-vite-taro 0.7.4 → 0.7.5-beta.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 +1 -1
- package/index.js +1 -0
- package/package.json +1 -1
- package/templates/default/README.md +22 -4
- package/templates/default/_env.local +1 -0
- package/templates/default/package.json +3 -0
- package/templates/default/src/components/navigation-bar/use-navigation-bar.ts +11 -5
- package/templates/default/src/global.d.ts +1 -1
- package/templates/default/vite.config.ts +63 -18
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
|
|
3
|
+
Create a Vite 8 + React 19 + Taro app for WeChat, Alipay, TikTok Mini Programs, 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
|
@@ -56,6 +56,7 @@ if (cdCommand) console.log(` ${cdCommand}`)
|
|
|
56
56
|
console.log(` ${packageManager} install`)
|
|
57
57
|
console.log(` ${getScriptCommand(packageManager, 'dev:wx')}`)
|
|
58
58
|
console.log(` ${getScriptCommand(packageManager, 'dev:zfb')}`)
|
|
59
|
+
console.log(` ${getScriptCommand(packageManager, 'dev:tt')}`)
|
|
59
60
|
console.log(` ${getScriptCommand(packageManager, 'dev:h5')}`)
|
|
60
61
|
|
|
61
62
|
function parseArgs(args) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# VPT
|
|
2
2
|
|
|
3
|
-
基于 Vite 8、React 19、Taro 4、TypeScript 和 Tailwind CSS v4
|
|
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)
|
|
@@ -57,6 +57,22 @@ npm install
|
|
|
57
57
|
|
|
58
58
|
3. 用支付宝小程序开发者工具导入 `dist/zfb`,不要导入项目根目录。
|
|
59
59
|
|
|
60
|
+
### 抖音小程序(TT)
|
|
61
|
+
|
|
62
|
+
1. 在 `.env.local` 中填写抖音 App ID:
|
|
63
|
+
|
|
64
|
+
```dotenv
|
|
65
|
+
VITE_VPT_TIKTOK_APP_ID=testAppId
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
2. 启动开发构建:
|
|
69
|
+
|
|
70
|
+
```sh
|
|
71
|
+
npm run dev:tt
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
3. 用抖音小程序开发者工具导入 `dist/tt`,不要导入项目根目录。
|
|
75
|
+
|
|
60
76
|
### Web
|
|
61
77
|
|
|
62
78
|
```sh
|
|
@@ -76,7 +92,7 @@ import { Button, Text, View } from 'virtual:taro/components'
|
|
|
76
92
|
|
|
77
93
|
不要直接安装或导入 `@tarojs/*`。在 `vite.config.ts` 中添加页面,并按当前目标修改应用与开发工具项目配置。
|
|
78
94
|
|
|
79
|
-
|
|
95
|
+
模板包含条件编译、微信原生组件、支付宝、抖音与 Web 共用的 Taro 组件、懒加载、自定义导航栏、Tailwind CSS、CSS Modules 和全局样式示例;不需要的示例可直接删除。
|
|
80
96
|
|
|
81
97
|
### 样式
|
|
82
98
|
|
|
@@ -92,17 +108,19 @@ import { Button, Text, View } from 'virtual:taro/components'
|
|
|
92
108
|
| --- | --- | --- |
|
|
93
109
|
| `npm run dev:wx` | 开发微信小程序 | `dist/wx` |
|
|
94
110
|
| `npm run dev:zfb` | 开发支付宝小程序 | `dist/zfb` |
|
|
111
|
+
| `npm run dev:tt` | 开发抖音小程序 | `dist/tt` |
|
|
95
112
|
| `npm run dev:h5` | 开发 Web | — |
|
|
96
113
|
| `npm run build:wx` | 构建微信小程序 | `dist/wx` |
|
|
97
114
|
| `npm run build:zfb` | 构建支付宝小程序 | `dist/zfb` |
|
|
115
|
+
| `npm run build:tt` | 构建抖音小程序 | `dist/tt` |
|
|
98
116
|
| `npm run build:h5` | 构建 Web | `dist/h5` |
|
|
99
117
|
| `npm run preview:h5` | 预览 Web 生产构建 | — |
|
|
100
118
|
| `npm run typecheck` | TypeScript 类型检查 | — |
|
|
101
119
|
|
|
102
120
|
## 常见问题
|
|
103
121
|
|
|
104
|
-
- **开发者工具无法打开项目:** 确认导入的是当前目标的 `dist
|
|
105
|
-
- **热更新失败:** 关闭对应开发者工具,停止开发命令,删除当前目标的输出目录,重新运行 `dev
|
|
122
|
+
- **开发者工具无法打开项目:** 确认导入的是当前目标的 `dist/...`,且 `.env.local` 中对应的 App ID 可用。
|
|
123
|
+
- **热更新失败:** 关闭对应开发者工具,停止开发命令,删除当前目标的输出目录,重新运行 `dev:...`,再导入生成目录。
|
|
106
124
|
- **Tailwind 类未生效:** 保留 `src/app.css` 中的 `@source "./";`,并使用完整类名。
|
|
107
125
|
- **pnpm 忽略依赖构建脚本:** 运行 `pnpm approve-builds`,批准所需脚本后重新安装。
|
|
108
126
|
|
|
@@ -6,9 +6,11 @@
|
|
|
6
6
|
"scripts": {
|
|
7
7
|
"dev:wx": "cross-env NODE_ENV=development VITE_VPT_TARGET=wx vite",
|
|
8
8
|
"dev:zfb": "cross-env NODE_ENV=development VITE_VPT_TARGET=zfb vite",
|
|
9
|
+
"dev:tt": "cross-env NODE_ENV=development VITE_VPT_TARGET=tt vite",
|
|
9
10
|
"dev:h5": "cross-env NODE_ENV=development VITE_VPT_TARGET=h5 vite",
|
|
10
11
|
"build:wx": "cross-env NODE_ENV=production VITE_VPT_TARGET=wx vite build",
|
|
11
12
|
"build:zfb": "cross-env NODE_ENV=production VITE_VPT_TARGET=zfb vite build",
|
|
13
|
+
"build:tt": "cross-env NODE_ENV=production VITE_VPT_TARGET=tt vite build",
|
|
12
14
|
"build:h5": "cross-env NODE_ENV=production VITE_VPT_TARGET=h5 vite build",
|
|
13
15
|
"preview:h5": "cross-env NODE_ENV=production VITE_VPT_TARGET=h5 vite preview --outDir dist/h5",
|
|
14
16
|
"typecheck": "tsc -b"
|
|
@@ -23,6 +25,7 @@
|
|
|
23
25
|
"@types/react-dom": "^19.3.0",
|
|
24
26
|
"typescript": "^7.0.2",
|
|
25
27
|
"cross-env": "^10.1.0",
|
|
28
|
+
"rolldown": "1.2.8",
|
|
26
29
|
"vite": "8.3.0"
|
|
27
30
|
},
|
|
28
31
|
"overrides": {
|
|
@@ -2,6 +2,7 @@ import Taro from 'virtual:taro/api'
|
|
|
2
2
|
|
|
3
3
|
const isWechatTarget = import.meta.env.VITE_VPT_TARGET === 'wx'
|
|
4
4
|
const isAlipayTarget = import.meta.env.VITE_VPT_TARGET === 'zfb'
|
|
5
|
+
const isTtTarget = import.meta.env.VITE_VPT_TARGET === 'tt'
|
|
5
6
|
|
|
6
7
|
interface NavigationBarMetrics {
|
|
7
8
|
height: number
|
|
@@ -37,9 +38,11 @@ function getFallbackMenuButtonMetrics(screenWidth: number): MenuButtonMetrics {
|
|
|
37
38
|
}
|
|
38
39
|
|
|
39
40
|
function getMenuButtonMetrics(screenWidth: number): MenuButtonMetrics {
|
|
40
|
-
if (isWechatTarget) {
|
|
41
|
+
if (isWechatTarget || isTtTarget) {
|
|
41
42
|
const menuButtonMetrics = Taro.getMenuButtonBoundingClientRect()
|
|
42
|
-
if (menuButtonMetrics.width > 0 && menuButtonMetrics.height > 0)
|
|
43
|
+
if (menuButtonMetrics.width > 0 && menuButtonMetrics.height > 0) {
|
|
44
|
+
return menuButtonMetrics
|
|
45
|
+
}
|
|
43
46
|
}
|
|
44
47
|
|
|
45
48
|
return getFallbackMenuButtonMetrics(screenWidth)
|
|
@@ -74,16 +77,19 @@ function getNavigationBarMetrics(
|
|
|
74
77
|
}
|
|
75
78
|
|
|
76
79
|
function getNavigationBarMetricsCached(): NavigationBarMetrics {
|
|
77
|
-
if (cachedNavigationBarMetrics)
|
|
80
|
+
if (cachedNavigationBarMetrics) {
|
|
81
|
+
return cachedNavigationBarMetrics
|
|
82
|
+
}
|
|
78
83
|
|
|
79
84
|
if (isAlipayTarget) {
|
|
80
85
|
cachedNavigationBarMetrics = getAlipayNavigationBarMetrics(Taro.getSystemInfoSync() as AlipaySystemInfo)
|
|
81
86
|
return cachedNavigationBarMetrics
|
|
82
87
|
}
|
|
83
88
|
|
|
84
|
-
|
|
89
|
+
// TT exposes its window metrics through getSystemInfoSync rather than WeChat's getWindowInfo.
|
|
90
|
+
const windowInfo = isTtTarget ? Taro.getSystemInfoSync() : Taro.getWindowInfo()
|
|
85
91
|
const screenWidth = windowInfo.screenWidth || 375
|
|
86
|
-
const statusBarHeight = isWechatTarget ? (windowInfo.statusBarHeight ?? 44) : 0
|
|
92
|
+
const statusBarHeight = isWechatTarget || isTtTarget ? (windowInfo.statusBarHeight ?? 44) : 0
|
|
87
93
|
const menuButtonMetrics = getMenuButtonMetrics(screenWidth)
|
|
88
94
|
|
|
89
95
|
cachedNavigationBarMetrics = getNavigationBarMetrics(screenWidth, statusBarHeight, menuButtonMetrics)
|
|
@@ -5,9 +5,9 @@ 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
9
|
const target = getTarget(env)
|
|
9
|
-
const
|
|
10
|
-
const alipayAppId = env.VITE_VPT_ALIPAY_APP_ID
|
|
10
|
+
const appId = getAppId(env, target)
|
|
11
11
|
|
|
12
12
|
return {
|
|
13
13
|
build: {
|
|
@@ -24,12 +24,12 @@ export default defineConfig(({ mode }) => {
|
|
|
24
24
|
}
|
|
25
25
|
],
|
|
26
26
|
appJson: createAppJson(target),
|
|
27
|
-
projectConfigJson: createProjectConfigJson({ target,
|
|
27
|
+
projectConfigJson: createProjectConfigJson({ target, appId }),
|
|
28
28
|
projectPrivateConfigJson: createProjectPrivateConfigJson(target),
|
|
29
29
|
sitemapJson: { rules: [{ action: 'allow', page: '*' }] },
|
|
30
30
|
hmr: {
|
|
31
|
-
mode: target === '
|
|
32
|
-
}
|
|
31
|
+
mode: target === 'wx' ? 'devtools' : 'interpreter'
|
|
32
|
+
}
|
|
33
33
|
})
|
|
34
34
|
]
|
|
35
35
|
}
|
|
@@ -49,6 +49,12 @@ function createPageJson(target: VptTarget): VptJsonObject {
|
|
|
49
49
|
titlePenetrate: 'YES'
|
|
50
50
|
}
|
|
51
51
|
}
|
|
52
|
+
case 'tt': {
|
|
53
|
+
return {
|
|
54
|
+
navigationStyle: 'custom',
|
|
55
|
+
navigationBarTextStyle: 'black'
|
|
56
|
+
}
|
|
57
|
+
}
|
|
52
58
|
default: {
|
|
53
59
|
return {}
|
|
54
60
|
}
|
|
@@ -85,25 +91,25 @@ function createAppJson(target: VptTarget): VptJsonObject {
|
|
|
85
91
|
}
|
|
86
92
|
}
|
|
87
93
|
}
|
|
94
|
+
case 'tt': {
|
|
95
|
+
return {
|
|
96
|
+
window: {
|
|
97
|
+
navigationStyle: 'custom',
|
|
98
|
+
navigationBarTextStyle: 'black'
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
88
102
|
default: {
|
|
89
103
|
return {}
|
|
90
104
|
}
|
|
91
105
|
}
|
|
92
106
|
}
|
|
93
107
|
|
|
94
|
-
function createProjectConfigJson({
|
|
95
|
-
target,
|
|
96
|
-
wechatAppId,
|
|
97
|
-
alipayAppId
|
|
98
|
-
}: {
|
|
99
|
-
target: VptTarget
|
|
100
|
-
wechatAppId: string
|
|
101
|
-
alipayAppId: string | undefined
|
|
102
|
-
}): VptJsonObject {
|
|
108
|
+
function createProjectConfigJson({ target, appId }: { target: VptTarget; appId: string | undefined }): VptJsonObject {
|
|
103
109
|
switch (target) {
|
|
104
110
|
case 'wx': {
|
|
105
111
|
return {
|
|
106
|
-
appid:
|
|
112
|
+
appid: appId,
|
|
107
113
|
projectname: 'vpt-project',
|
|
108
114
|
description: '',
|
|
109
115
|
compileType: 'miniprogram',
|
|
@@ -130,7 +136,7 @@ function createProjectConfigJson({
|
|
|
130
136
|
}
|
|
131
137
|
case 'zfb': {
|
|
132
138
|
return {
|
|
133
|
-
appid:
|
|
139
|
+
appid: appId,
|
|
134
140
|
miniprogramRoot: './',
|
|
135
141
|
format: 2,
|
|
136
142
|
compileOptions: {
|
|
@@ -151,6 +157,21 @@ function createProjectConfigJson({
|
|
|
151
157
|
}
|
|
152
158
|
}
|
|
153
159
|
}
|
|
160
|
+
case 'tt': {
|
|
161
|
+
return {
|
|
162
|
+
appid: appId,
|
|
163
|
+
projectname: 'vpt-project',
|
|
164
|
+
miniprogramRoot: './',
|
|
165
|
+
compileHotReload: true,
|
|
166
|
+
setting: {
|
|
167
|
+
urlCheck: false,
|
|
168
|
+
es6: false,
|
|
169
|
+
postcss: false,
|
|
170
|
+
minified: false,
|
|
171
|
+
autoCompile: true
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
}
|
|
154
175
|
default: {
|
|
155
176
|
return {}
|
|
156
177
|
}
|
|
@@ -173,21 +194,45 @@ function createProjectPrivateConfigJson(target: VptTarget): VptJsonObject {
|
|
|
173
194
|
ignoreWebViewDomainCheck: true
|
|
174
195
|
}
|
|
175
196
|
}
|
|
197
|
+
case 'tt': {
|
|
198
|
+
return {
|
|
199
|
+
setting: {
|
|
200
|
+
urlCheck: false
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
}
|
|
176
204
|
default:
|
|
177
205
|
return {}
|
|
178
206
|
}
|
|
179
207
|
}
|
|
180
208
|
|
|
209
|
+
function getAppId(env: Record<string, string>, target: VptTarget): string {
|
|
210
|
+
switch (target) {
|
|
211
|
+
case 'wx': {
|
|
212
|
+
return env.VITE_VPT_WECHAT_APP_ID ?? ''
|
|
213
|
+
}
|
|
214
|
+
case 'zfb': {
|
|
215
|
+
return env.VITE_VPT_ALIPAY_APP_ID ?? ''
|
|
216
|
+
}
|
|
217
|
+
case 'tt': {
|
|
218
|
+
return env.VITE_VPT_TIKTOK_APP_ID ?? ''
|
|
219
|
+
}
|
|
220
|
+
default: {
|
|
221
|
+
return ''
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
|
|
181
226
|
function getTarget(env: Record<string, string>): VptTarget {
|
|
182
227
|
const targetEnvName = 'VITE_VPT_TARGET'
|
|
183
228
|
|
|
184
229
|
const target = env[targetEnvName]
|
|
185
230
|
|
|
186
|
-
if (target === 'wx' || target === 'zfb' || target === 'h5') {
|
|
231
|
+
if (target === 'wx' || target === 'zfb' || target === 'tt' || target === 'h5') {
|
|
187
232
|
return target
|
|
188
233
|
}
|
|
189
234
|
|
|
190
|
-
throw new Error(`${targetEnvName} must be "wx", "zfb", or "h5".`)
|
|
235
|
+
throw new Error(`${targetEnvName} must be "wx", "zfb", "tt", or "h5".`)
|
|
191
236
|
}
|
|
192
237
|
|
|
193
238
|
const projectRoot = fileURLToPath(new URL('.', import.meta.url))
|