create-vite-taro 0.8.3 → 0.8.5

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, Alipay, TikTok Mini Programs, and Web targets.
3
+ Create a Vite 8 + React 19 + Taro app for WeChat, Alipay, Taobao, 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
@@ -6,6 +6,7 @@ import process from 'node:process'
6
6
  import readline from 'node:readline/promises'
7
7
  import { fileURLToPath } from 'node:url'
8
8
  import generatorPackage from './package.json' with { type: 'json' }
9
+ import templatePackage from './templates/default/package.json' with { type: 'json' }
9
10
 
10
11
  const packageRoot = path.dirname(fileURLToPath(import.meta.url))
11
12
  const defaultProjectName = 'vite-taro-app'
@@ -51,12 +52,14 @@ const cdCommand = displayProjectPath === '.' ? undefined : `cd ${quotePath(displ
51
52
 
52
53
  console.log(`\nCreated ${projectName} in ${projectPath}\n`)
53
54
  console.log('Next steps:')
54
- if (cdCommand) console.log(` ${cdCommand}`)
55
+ if (cdCommand) {
56
+ console.log(` ${cdCommand}`)
57
+ }
55
58
  console.log(` ${packageManager} install`)
56
- console.log(` ${getScriptCommand(packageManager, 'dev:wx')}`)
57
- console.log(` ${getScriptCommand(packageManager, 'dev:zfb')}`)
58
- console.log(` ${getScriptCommand(packageManager, 'dev:tt')}`)
59
- console.log(` ${getScriptCommand(packageManager, 'dev:h5')}`)
59
+ const developmentScripts = Object.keys(templatePackage.scripts).filter((script) => script.startsWith('dev:'))
60
+ for (const script of developmentScripts) {
61
+ console.log(` ${getScriptCommand(packageManager, script)}`)
62
+ }
60
63
 
61
64
  function parseArgs(args) {
62
65
  const options = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-vite-taro",
3
- "version": "0.8.3",
3
+ "version": "0.8.5",
4
4
  "description": "Create Vite 8 + React 19 + Taro apps for WeChat, Alipay, TikTok, and H5 targets.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -1,133 +1,34 @@
1
1
  # VPT
2
2
 
3
- 基于 Vite 8、React 19、Taro 4、TypeScript 和 Tailwind CSS v4,一套代码运行于微信、支付宝、抖音小程序和 Web。
3
+ 基于 Vite 8、React 19、Taro、TypeScript 和 Tailwind CSS,一套代码运行于微信、支付宝、淘宝、抖音小程序和 Web。
4
4
 
5
- - [文档](https://vpt.js.org)
6
- - [GitHub](https://github.com/sep2/vite-plugin-taro)
7
-
8
- ## AI 开发
9
-
10
- 把下面的提示词交给编程助手,让它先读取 VPT 文档,再开发并验证功能:
11
-
12
- ```text
13
- 请先阅读 https://vpt.js.org/llms.txt,再根据我的需求开发这个 VPT 项目。
14
- ```
15
-
16
- 测试微信小程序时,可安装微信官方的[开发者工具 Skills](https://developers.weixin.qq.com/miniprogram/dev/devtools/Skills.html),让 AI 操作模拟器、读取日志、截图和预览。
5
+ [文档](https://vpt.js.org) · [GitHub](https://github.com/sep2/vite-plugin-taro)
17
6
 
18
7
  ## 快速开始
19
8
 
20
- 安装依赖:
21
-
22
9
  ```sh
23
- npm install
10
+ pnpm install
24
11
  ```
25
12
 
26
- ### 微信小程序
27
-
28
- 1. 在 `.env.local` 中填写微信 App ID:
29
-
30
- ```dotenv
31
- VITE_VPT_WECHAT_APP_ID=wx1234567890abcdef
32
- ```
33
-
34
- 2. 启动开发构建:
35
-
36
- ```sh
37
- npm run dev:wx
38
- ```
39
-
40
- 3. 用微信开发者工具导入 `dist/wx`,不要导入项目根目录。
41
-
42
- 开发期间保持命令运行。模板已开启热更新、关闭本地开发的 URL 校验,并默认关闭开发者工具中暂不支持热更新的 Skyline。
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
-
60
- ### 抖音小程序
61
-
62
- 1. 在 `.env.local` 中填写抖音 App ID:
63
-
64
- ```dotenv
65
- VITE_VPT_TIKTOK_APP_ID=testAppId
66
- ```
13
+ 开发小程序前,在 `.env.local` 中填写对应平台的 App ID,然后选择开发命令:
67
14
 
68
- 2. 启动开发构建:
15
+ | 平台 | 开发 | 构建 | 构建目录 |
16
+ | --- | --- | --- | --- |
17
+ | 微信 | `pnpm dev:wx` | `pnpm build:wx` | `dist/wx` |
18
+ | 支付宝 | `pnpm dev:zfb` | `pnpm build:zfb` | `dist/zfb` |
19
+ | 淘宝 | `pnpm dev:tb` | `pnpm build:tb` | `dist/tb` |
20
+ | 抖音 | `pnpm dev:tt` | `pnpm build:tt` | `dist/tt` |
21
+ | Web | `pnpm dev:h5` | `pnpm build:h5` | `dist/h5` |
69
22
 
70
- ```sh
71
- npm run dev:tt
72
- ```
23
+ 监听文件变化并自动重新构建生产版本:`pnpm build:wx --watch`。
73
24
 
74
- 3. 用抖音开发者工具导入 `dist/tt`,不要导入项目根目录。
75
-
76
- ### Web
77
-
78
- ```sh
79
- npm run dev:h5
80
- ```
81
-
82
- 打开 Vite 输出的地址,通常是 <http://localhost:5173>。
25
+ 其他命令:`pnpm typecheck` 检查类型,`pnpm preview:h5` 预览 Web 生产构建。
83
26
 
84
27
  ## 开发
85
28
 
86
- 模板包含 Home、Explore、About 三个真实 Tab 页面,默认页面是 `src/pages/home/index.tsx`。路由、标签和图标名称统一定义在 `src/tab-pages.ts`。
87
-
88
- 每个页面负责自己的全屏布局和 `TabBar`,`src/app.tsx` 负责应用生命周期和全局样式,直接返回 `children`。通过 `Taro.switchTab()` 切换 Tab 时,已访问页面的 React 状态会保留。
89
-
90
- `vite.config.ts` 显式声明页面并启用 `prerender: true`,原生 Tab 路由由 `tabPages` 生成。微信使用 `tabBar.custom: true`,由页面中的 React 标签栏负责渲染;`tabBar.list` 保留原生 `switchTab()` 所需的路由声明。支付宝使用 `tabBar.customize: true` 和 `tabBar.items`,VPT 自动生成隐藏的原生标签栏占位组件。
91
-
92
- VPT 通过虚拟模块提供 Taro 组件和 API:
93
-
94
- ```tsx
95
- import Taro from 'virtual:taro/api'
96
- import { Button, Text, View } from 'virtual:taro/components'
97
- ```
98
-
99
- 不要直接安装或导入 `@tarojs/*`。在 `vite.config.ts` 中添加页面,并按当前目标修改应用与开发工具项目配置。
100
-
101
- 模板包含条件编译、微信原生组件、支付宝、抖音与 Web 共用的 Taro 组件、懒加载、自定义导航栏、React 标签栏、Tailwind CSS、CSS Modules 和全局样式示例;不需要的示例可直接删除。
102
-
103
- ### 样式
104
-
105
- 全局样式和 Tailwind 主题位于 `src/app.css`。保留 Tailwind 导入和 `@source "./";`,并在源码中写完整类名,不要拼接类名。组件独立样式使用 `*.module.css`。
106
-
107
- ### 热更新
108
-
109
- 小程序端热更新通常会保留 App 数据、当前页面、兼容的 React Hook 状态和原生输入值。修改 Vite 配置、组件或 Hook 结构不兼容,或更新无法安全应用时,会整页重载。详见[热更新指南](https://vpt.js.org/guides/hot-module-replacement/)。
110
-
111
- ## 命令
112
-
113
- | 命令 | 用途 | 输出 |
114
- | --- | --- | --- |
115
- | `npm run dev:wx` | 开发微信小程序 | `dist/wx` |
116
- | `npm run dev:zfb` | 开发支付宝小程序 | `dist/zfb` |
117
- | `npm run dev:tt` | 开发抖音小程序 | `dist/tt` |
118
- | `npm run dev:h5` | 开发 Web | — |
119
- | `npm run build:wx` | 构建微信小程序 | `dist/wx` |
120
- | `npm run build:zfb` | 构建支付宝小程序 | `dist/zfb` |
121
- | `npm run build:tt` | 构建抖音小程序 | `dist/tt` |
122
- | `npm run build:h5` | 构建 Web | `dist/h5` |
123
- | `npm run preview:h5` | 预览 Web 生产构建 | — |
124
- | `npm run typecheck` | TypeScript 类型检查 | — |
125
-
126
- ## 常见问题
127
-
128
- - **开发者工具无法打开项目:** 确认导入的是当前目标的 `dist/...`,且 `.env.local` 中对应的 App ID 可用。
129
- - **热更新失败:** 关闭对应开发者工具,停止开发命令,删除当前目标的输出目录,重新运行 `dev:...`,再导入生成目录。
130
- - **Tailwind 类未生效:** 保留 `src/app.css` 中的 `@source "./";`,并使用完整类名。
131
- - **pnpm 忽略依赖构建脚本:** 运行 `pnpm approve-builds`,批准所需脚本后重新安装。
29
+ - `src/pages/home/index.tsx`:首页,从这里开始修改。
30
+ - `vite.config.ts`:页面注册、构建目标与平台配置。
31
+ - `src/tab-pages.ts`:Tab 路由、标签和图标名称。
32
+ - `src/app.css`:全局样式与 Tailwind 主题,保留 `@source "./";` 并使用完整类名。
132
33
 
133
- 继续阅读[快速开始指南](https://vpt.js.org/guides/quick-start/)或[完整文档](https://vpt.js.org)。
34
+ 通过 `virtual:taro/api` 和 `virtual:taro/components` 使用 Taro API 与组件。更多用法见[快速开始指南](https://vpt.js.org/guides/quick-start/)。
@@ -1,3 +1,4 @@
1
1
  VITE_VPT_WECHAT_APP_ID=wx0000000000000000
2
2
  VITE_VPT_ALIPAY_APP_ID=2021000000000000
3
+ VITE_VPT_TAOBAO_APP_ID=2021000000000000
3
4
  VITE_VPT_TIKTOK_APP_ID=testAppId
@@ -6,10 +6,12 @@
6
6
  "scripts": {
7
7
  "dev:wx": "cross-env VITE_VPT_TARGET=wx vite",
8
8
  "dev:zfb": "cross-env VITE_VPT_TARGET=zfb vite",
9
+ "dev:tb": "cross-env VITE_VPT_TARGET=tb vite",
9
10
  "dev:tt": "cross-env VITE_VPT_TARGET=tt vite",
10
11
  "dev:h5": "cross-env VITE_VPT_TARGET=h5 vite",
11
12
  "build:wx": "cross-env VITE_VPT_TARGET=wx vite build",
12
13
  "build:zfb": "cross-env VITE_VPT_TARGET=zfb vite build",
14
+ "build:tb": "cross-env VITE_VPT_TARGET=tb vite build",
13
15
  "build:tt": "cross-env VITE_VPT_TARGET=tt vite build",
14
16
  "build:h5": "cross-env VITE_VPT_TARGET=h5 vite build",
15
17
  "preview:h5": "cross-env VITE_VPT_TARGET=h5 vite preview --outDir dist/h5",
@@ -1,7 +1,7 @@
1
1
  import Taro from 'virtual:taro/api'
2
2
 
3
3
  const isWechatTarget = import.meta.env.VITE_VPT_TARGET === 'wx'
4
- const isAlipayTarget = import.meta.env.VITE_VPT_TARGET === 'zfb'
4
+ const isAlipayTarget = import.meta.env.VITE_VPT_TARGET === 'zfb' || import.meta.env.VITE_VPT_TARGET === 'tb'
5
5
  const isTtTarget = import.meta.env.VITE_VPT_TARGET === 'tt'
6
6
 
7
7
  interface NavigationBarMetrics {
@@ -19,7 +19,7 @@ interface MenuButtonMetrics {
19
19
  width: number
20
20
  }
21
21
 
22
- /** Alipay fields narrowed from Taro's shared system-info result type. */
22
+ /** Alipay and Taobao fields narrowed from Taro's shared system-info result type. */
23
23
  type AlipaySystemInfo = ReturnType<typeof Taro.getSystemInfoSync> & {
24
24
  statusBarHeight: number
25
25
  titleBarHeight: number
@@ -1,3 +1,3 @@
1
1
  interface ImportMetaEnv {
2
- readonly VITE_VPT_TARGET: 'wx' | 'zfb' | 'tt' | 'h5'
2
+ readonly VITE_VPT_TARGET: 'wx' | 'zfb' | 'tb' | 'tt' | 'h5'
3
3
  }
@@ -3,7 +3,7 @@ import { NavigationBar } from '../../components/navigation-bar/navigation-bar.ts
3
3
  import { TabBar } from '../../components/tab-bar/tab-bar.tsx'
4
4
  import { tabPages } from '../../tab-pages.ts'
5
5
 
6
- const platforms = ['WeChat', 'Alipay', 'TikTok', 'Web'] as const
6
+ const platforms = ['WeChat', 'Alipay', 'Taobao', 'TikTok', 'Web'] as const
7
7
 
8
8
  export default function AboutPage() {
9
9
  return (
@@ -20,7 +20,7 @@ export default function AboutPage() {
20
20
 
21
21
  <View className="mt-9 rounded-3xl bg-primary p-7 text-white shadow-xl sm:p-9">
22
22
  <Text className="brand-serif block text-3xl font-semibold text-white">
23
- One project. Four places.
23
+ One project. Five platforms.
24
24
  </Text>
25
25
  <Text className="mt-3 block text-sm leading-6 text-on-primary-muted">
26
26
  Share the interface and tailor the details to each platform as you go.
@@ -19,7 +19,7 @@ const steps = [
19
19
  {
20
20
  number: '03',
21
21
  title: 'Ship to every target',
22
- description: 'Build for WeChat, Alipay, TikTok or the web from the same source.',
22
+ description: 'Build for WeChat, Alipay, Taobao, TikTok or the web from the same source.',
23
23
  file: 'npm run build:wx'
24
24
  }
25
25
  ] as const
@@ -10,13 +10,14 @@ const featureCards = [
10
10
  {
11
11
  number: '01',
12
12
  title: 'Vite-speed feedback',
13
- description: 'Save a React component and see the smallest possible update in WeChat DevTools or the browser.',
13
+ description:
14
+ 'Save a React component and see the smallest possible update in Mini Program DevTools or the browser.',
14
15
  tiltClass: 'rotate-[-0.35deg]'
15
16
  },
16
17
  {
17
18
  number: '02',
18
19
  title: 'One React tree',
19
- description: 'Share components, hooks and application state between WeChat Mini Program and H5.',
20
+ description: 'Share components, hooks and application state across Mini Programs and the web.',
20
21
  tiltClass: 'translate-y-1 rotate-[0.25deg]'
21
22
  },
22
23
  {
@@ -49,8 +50,8 @@ function HomePage() {
49
50
  Build naturally. Ship everywhere.
50
51
  </Text>
51
52
  <Text className="mt-4 block w-full max-w-xl text-sm leading-7 text-muted sm:text-base">
52
- A botanical little starter for building polished WeChat Mini Programs and Web apps with one
53
- modern React codebase.
53
+ A botanical little starter for building polished Mini Programs and Web apps with one modern
54
+ React codebase.
54
55
  </Text>
55
56
 
56
57
  <View className="mt-7 flex flex-row flex-wrap items-center justify-center gap-3">
@@ -11,7 +11,7 @@ export default function ApiCard() {
11
11
  Make this starter yours.
12
12
  </span>
13
13
  <span className="mt-3 block text-sm leading-6 text-on-primary-muted">
14
- Add pages, connect your data and ship the same experience to WeChat and H5.
14
+ Add pages, connect your data and ship the same experience to Mini Programs and the web.
15
15
  </span>
16
16
  </div>
17
17
  <button
@@ -57,7 +57,8 @@ function createPageJson(target: VptTarget): VptJsonObject {
57
57
  navigationBarTextStyle: 'black'
58
58
  }
59
59
  }
60
- case 'zfb': {
60
+ case 'zfb':
61
+ case 'tb': {
61
62
  return {
62
63
  transparentTitle: 'always',
63
64
  titlePenetrate: 'YES'
@@ -104,9 +105,11 @@ function createAppJson(target: VptTarget): VptJsonObject {
104
105
  }
105
106
  }
106
107
  }
107
- case 'zfb': {
108
+ case 'zfb':
109
+ case 'tb': {
108
110
  return {
109
111
  lazyCodeLoading: 'renderedComponents',
112
+ subPackageBuildType: 'shared',
110
113
  useDynamicPlugins: true,
111
114
  tabBar: {
112
115
  customize: true,
@@ -172,7 +175,8 @@ function createProjectConfigJson(target: VptTarget, appId: string | undefined):
172
175
  }
173
176
  }
174
177
  }
175
- case 'zfb': {
178
+ case 'zfb':
179
+ case 'tb': {
176
180
  return {
177
181
  appid: appId,
178
182
  miniprogramRoot: './',
@@ -225,7 +229,8 @@ function createProjectPrivateConfigJson(target: VptTarget): VptJsonObject {
225
229
  }
226
230
  }
227
231
  }
228
- case 'zfb': {
232
+ case 'zfb':
233
+ case 'tb': {
229
234
  return {
230
235
  ignoreHttpDomainCheck: true,
231
236
  ignoreCertificateDomainCheck: true,
@@ -252,6 +257,9 @@ function getAppId(env: Record<string, string>, target: VptTarget): string {
252
257
  case 'zfb': {
253
258
  return env.VITE_VPT_ALIPAY_APP_ID ?? ''
254
259
  }
260
+ case 'tb': {
261
+ return env.VITE_VPT_TAOBAO_APP_ID ?? ''
262
+ }
255
263
  case 'tt': {
256
264
  return env.VITE_VPT_TIKTOK_APP_ID ?? ''
257
265
  }
@@ -266,11 +274,11 @@ function getTarget(env: Record<string, string>): VptTarget {
266
274
 
267
275
  const target = env[targetEnvName]
268
276
 
269
- if (target === 'wx' || target === 'zfb' || target === 'tt' || target === 'h5') {
277
+ if (target === 'wx' || target === 'zfb' || target === 'tb' || target === 'tt' || target === 'h5') {
270
278
  return target
271
279
  }
272
280
 
273
- throw new Error(`${targetEnvName} must be "wx", "zfb", "tt", or "h5".`)
281
+ throw new Error(`${targetEnvName} must be "wx", "zfb", "tb", "tt", or "h5".`)
274
282
  }
275
283
 
276
284
  const projectRoot = fileURLToPath(new URL('.', import.meta.url))