vite-plugin-taro 0.1.2 → 0.1.4

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.
Files changed (3) hide show
  1. package/README.en.md +38 -30
  2. package/README.md +38 -30
  3. package/package.json +3 -3
package/README.en.md CHANGED
@@ -17,7 +17,7 @@ Live demo: <https://sep2.github.io/vite-plugin-taro>. See [Sample app](https://g
17
17
  - **Battle-tested Taro foundation** Use the full set of Taro APIs and components instead of reinventing cross-platform primitives.
18
18
  - **Tailwind ready** Built-in Tailwind CSS v4 support for both WeChat Mini Program and H5 styles.
19
19
  - **Conditional compilation** Use Taro-style `#ifdef` / `#ifndef` / `#if` blocks to split code and styles by `wx` / `h5` target.
20
- - **Type-friendly** Import Taro capabilities consistently through `virtual:taro/api` and `virtual:taro/components`, with TypeScript type support.
20
+ - **Type-friendly** The project supports TypeScript all the way.
21
21
  - **WeChat Skyline** Support WeChat Mini Program output with Skyline rendering mode.
22
22
 
23
23
  ## Quick start
@@ -28,11 +28,11 @@ Use `create-vite-taro` for new apps. It generates a Vite 8 + React 19 + Taro pro
28
28
 
29
29
  ```sh
30
30
  # Create a new app from the default template
31
- pnpm create vite-taro my-app
31
+ npm create vite-taro@latest my-app
32
32
 
33
33
  # Enter the project and install dependencies
34
34
  cd my-app
35
- pnpm install
35
+ npm install
36
36
  ```
37
37
 
38
38
  ### 2. Configure WeChat App ID
@@ -43,18 +43,18 @@ The template creates `.env.local`. Set `VITE_PLUGIN_TARO_WECHAT_APP_ID` to your
43
43
 
44
44
  ```sh
45
45
  # WeChat Mini Program: rebuild dist/wx in watch mode
46
- pnpm dev:wx
46
+ npm run dev:wx
47
47
 
48
48
  # Then open dist/wx in WeChat DevTools
49
49
 
50
50
  # H5: start the Vite dev server
51
- pnpm dev:h5
51
+ npm run dev:h5
52
52
 
53
53
  # Then open the standard Vite dev URL in your browser
54
54
  # http://localhost:5173
55
55
  ```
56
56
 
57
- You can keep `pnpm dev:wx` and `pnpm dev:h5` running at the same time in separate terminals.
57
+ You can keep `npm run dev:wx` and `npm run dev:h5` running at the same time in separate terminals.
58
58
 
59
59
  Note: Because of WeChat DevTools and Mini Program runtime limitations, hot reload/fast rebuilds for the WeChat target may not always apply cleanly. For day-to-day iteration, prefer the H5 Vite dev server for fast feedback, and periodically verify the Mini Program result in WeChat DevTools.
60
60
 
@@ -62,33 +62,50 @@ Note: Because of WeChat DevTools and Mini Program runtime limitations, hot reloa
62
62
 
63
63
  ```sh
64
64
  # Production WeChat Mini Program output
65
- pnpm build:wx
65
+ npm run build:wx
66
66
 
67
67
  # Production H5 output
68
- pnpm build:h5
68
+ npm run build:h5
69
69
 
70
70
  # Preview the built H5 app
71
- pnpm preview:h5
71
+ npm run preview:h5
72
72
 
73
73
  # Typecheck with tsgo
74
- pnpm typecheck
74
+ npm run typecheck
75
75
  ```
76
76
 
77
- For existing apps or custom project layouts, follow the manual setup below.
77
+ ### 5. Use Taro virtual modules
78
+
79
+ Use these imports in app code:
80
+
81
+ ```tsx
82
+ import Taro from 'virtual:taro/api'
83
+ import { Text, View } from 'virtual:taro/components'
84
+ ```
85
+
86
+ | Import | Use |
87
+ | --- | --- |
88
+ | `virtual:taro/components` | Taro React components such as `View`, `Text`, `Button`, `Image`, and `ScrollView`. |
89
+ | `virtual:taro/api` | Taro APIs and hooks such as `Taro.navigateTo`, `Taro.getWindowInfo`, and `Taro.useLaunch`. |
90
+
91
+ Usage is the same as Taro itself; see the [Taro website](https://docs.taro.zone) for component and API details.
92
+
93
+ You no longer need to install `@tarojs/*` packages; application code should not import from `@tarojs/*`.
94
+
78
95
 
79
96
  ## Manual setup for existing apps
80
97
 
81
98
  For existing apps or custom project layouts, follow the steps below to wire the plugin manually. First, install the plugin:
82
99
 
83
100
  ```sh
84
- pnpm add -D vite-plugin-taro
101
+ npm install -D vite-plugin-taro
85
102
  ```
86
103
 
87
104
  Your app must also provide Vite 8, React 19, React DOM 19, a TypeScript checker, and Node/React type packages. If your app does not already have them, install the missing packages:
88
105
 
89
106
  ```sh
90
- pnpm add react react-dom
91
- pnpm add -D vite @typescript/native-preview @types/node @types/react @types/react-dom
107
+ npm install react react-dom
108
+ npm install -D vite @typescript/native-preview @types/node @types/react @types/react-dom
92
109
  ```
93
110
 
94
111
  You should NOT have direct dependencies on `@tarojs/*` packages anymore. Remove them if you have.
@@ -238,15 +255,6 @@ export default function IndexPage() {
238
255
  }
239
256
  ```
240
257
 
241
- Use these imports in app code:
242
-
243
- | Import | Use |
244
- | --- | --- |
245
- | `virtual:taro/components` | Taro React components such as `View`, `Text`, `Button`, `Image`, and `ScrollView`. |
246
- | `virtual:taro/api` | Taro APIs and hooks such as `Taro.navigateTo`, `Taro.getWindowInfo`, and `Taro.useLaunch`. |
247
-
248
- Do not import `@tarojs/*` packages directly in application code. Direct `@tarojs/*` usage is forbidden and unsupported by this plugin because it can bypass target-specific runtime aliases and H5 API transforms. Use `virtual:taro/api` and `virtual:taro/components` only.
249
-
250
258
  ### 5. Add the H5 HTML shell
251
259
 
252
260
  For H5, keep a normal Vite `index.html` with an `#app` mount node. The plugin injects the generated Taro H5 entry automatically, so you do not need a normal Vite `src/main.tsx` script.
@@ -287,12 +295,12 @@ On Windows shells, use `cross-env`.
287
295
  ### 7. Run each target
288
296
 
289
297
  ```sh
290
- pnpm dev:wx # Rebuild dist/wx in watch mode
291
- pnpm dev:h5 # Start the H5 dev server
292
- pnpm build:wx # Build dist/wx
293
- pnpm build:h5 # Build dist/h5
294
- pnpm preview:h5 # Preview dist/h5
295
- pnpm typecheck # Typecheck with tsgo
298
+ npm run dev:wx # Rebuild dist/wx in watch mode
299
+ npm run dev:h5 # Start the H5 dev server
300
+ npm run build:wx # Build dist/wx
301
+ npm run build:h5 # Build dist/h5
302
+ npm run preview:h5 # Preview dist/h5
303
+ npm run typecheck # Typecheck with tsgo
296
304
  ```
297
305
 
298
306
  Open the generated `dist/wx` directory in WeChat DevTools.
@@ -499,7 +507,7 @@ Common scripts:
499
507
  | Problem | Check |
500
508
  | --- | --- |
501
509
  | `VITE_PLUGIN_TARO_TARGET must be "wx" or "h5"` | Set the target environment variable in your script or `.env` file. |
502
- | `pnpm install` says dependency build scripts were ignored | Run `pnpm approve-builds`, approve the requested dependency build scripts, then rerun `pnpm install` if needed. |
510
+ | `pnpm install` says dependency build scripts were ignored | Run `pnpm approve-builds` and approve the requested dependency build scripts. |
503
511
  | A page cannot be resolved | Confirm that `pages[].path` has a matching `src/${path}.tsx` file. |
504
512
  | WeChat DevTools cannot open the app | Open the generated `dist/wx` folder and check `projectConfigJson.appid`. |
505
513
  | H5 shows a blank page | Keep `<div id="app"></div>` in `index.html`, register the plugin, and avoid adding a separate default Vite `main.tsx` entry. |
package/README.md CHANGED
@@ -17,7 +17,7 @@
17
17
  - **依托成熟 Taro 能力** 复用久经实战检验的 Taro API 和组件,完整使用 Taro 跨端能力。
18
18
  - **Tailwind 就绪** 内置 Tailwind CSS v4 支持,微信小程序与 H5 样式开箱即用。
19
19
  - **条件编译** 支持 Taro 风格 `#ifdef` / `#ifndef` / `#if`,可按 `wx` / `h5` 裁剪代码和样式。
20
- - **类型友好** 通过 `virtual:taro/api` 和 `virtual:taro/components` 统一导入 Taro 能力,并提供 TypeScript 类型支持。
20
+ - **类型友好** 项目全链路支持 TypeScript
21
21
  - **微信 Skyline** 支持微信小程序 Skyline 渲染模式输出。
22
22
 
23
23
  ## 快速开始
@@ -28,11 +28,11 @@
28
28
 
29
29
  ```sh
30
30
  # 使用默认模板创建新应用
31
- pnpm create vite-taro my-app
31
+ npm create vite-taro@latest my-app
32
32
 
33
33
  # 进入项目并安装依赖
34
34
  cd my-app
35
- pnpm install
35
+ npm install
36
36
  ```
37
37
 
38
38
  ### 2. 配置微信 App ID
@@ -43,18 +43,18 @@ pnpm install
43
43
 
44
44
  ```sh
45
45
  # 微信小程序:以 watch 模式重新构建 dist/wx
46
- pnpm dev:wx
46
+ npm run dev:wx
47
47
 
48
48
  # 然后在微信开发者工具中打开 dist/wx
49
49
 
50
50
  # H5:启动 Vite 开发服务器
51
- pnpm dev:h5
51
+ npm run dev:h5
52
52
 
53
53
  # 然后在浏览器中打开标准 Vite 地址
54
54
  # http://localhost:5173
55
55
  ```
56
56
 
57
- 你可以在两个终端中同时运行 `pnpm dev:wx` 和 `pnpm dev:h5`。
57
+ 你可以在两个终端中同时运行 `npm run dev:wx` 和 `npm run dev:h5`。
58
58
 
59
59
  提示:受微信限制,开发者工具热重载有时不会完整生效。建议日常优先使用 H5 的 Vite 热更新快速调试,并定期在微信开发者工具中验证小程序端效果。
60
60
 
@@ -62,33 +62,50 @@ pnpm dev:h5
62
62
 
63
63
  ```sh
64
64
  # 生产微信小程序产物
65
- pnpm build:wx
65
+ npm run build:wx
66
66
 
67
67
  # 生产 H5 产物
68
- pnpm build:h5
68
+ npm run build:h5
69
69
 
70
70
  # 预览构建后的 H5 应用
71
- pnpm preview:h5
71
+ npm run preview:h5
72
72
 
73
73
  # 使用 tsgo 进行类型检查
74
- pnpm typecheck
74
+ npm run typecheck
75
75
  ```
76
76
 
77
- 已有应用或自定义项目结构,请继续阅读下面的手动接入步骤。
77
+ ### 5. 使用 Taro 虚拟模块
78
+
79
+ 应用代码请使用这些导入:
80
+
81
+ ```tsx
82
+ import Taro from 'virtual:taro/api'
83
+ import { Text, View } from 'virtual:taro/components'
84
+ ```
85
+
86
+ | 导入 | 用途 |
87
+ | --- | --- |
88
+ | `virtual:taro/components` | Taro React 组件,例如 `View`、`Text`、`Button`、`Image` 和 `ScrollView`。 |
89
+ | `virtual:taro/api` | Taro API 和 hooks,例如 `Taro.navigateTo`、`Taro.getWindowInfo` 和 `Taro.useLaunch`。 |
90
+
91
+ 用法与 Taro 本身一致;组件和 API 的具体用法请参考 [Taro 官网](https://docs.taro.zone)。
92
+
93
+ 你不再需要安装 `@tarojs/*` 包;应用代码也不要从 `@tarojs/*` 导入。
94
+
78
95
 
79
96
  ## 手动接入已有应用
80
97
 
81
98
  已有应用或自定义项目结构,可以按下面的步骤手动接入插件。先安装插件:
82
99
 
83
100
  ```sh
84
- pnpm add -D vite-plugin-taro
101
+ npm install -D vite-plugin-taro
85
102
  ```
86
103
 
87
104
  你的应用还必须提供 Vite 8、React 19、React DOM 19、TypeScript 检查器,以及 Node/React 类型包。如果应用尚未安装它们,请安装缺失的包:
88
105
 
89
106
  ```sh
90
- pnpm add react react-dom
91
- pnpm add -D vite @typescript/native-preview @types/node @types/react @types/react-dom
107
+ npm install react react-dom
108
+ npm install -D vite @typescript/native-preview @types/node @types/react @types/react-dom
92
109
  ```
93
110
 
94
111
  你不应再直接依赖任何 `@tarojs/*` 包。如果已经依赖,请将它们移除。
@@ -238,15 +255,6 @@ export default function IndexPage() {
238
255
  }
239
256
  ```
240
257
 
241
- 应用代码请使用这些导入:
242
-
243
- | 导入 | 用途 |
244
- | --- | --- |
245
- | `virtual:taro/components` | Taro React 组件,例如 `View`、`Text`、`Button`、`Image` 和 `ScrollView`。 |
246
- | `virtual:taro/api` | Taro API 和 hooks,例如 `Taro.navigateTo`、`Taro.getWindowInfo` 和 `Taro.useLaunch`。 |
247
-
248
- 不要在应用代码中直接导入 `@tarojs/*` 包。此插件禁止且不支持直接使用 `@tarojs/*`,因为这可能绕过目标特定的运行时别名和 H5 API 转换。请只使用 `virtual:taro/api` 和 `virtual:taro/components`。
249
-
250
258
  ### 5. 添加 H5 HTML 外壳
251
259
 
252
260
  对于 H5,请保留一个普通的 Vite `index.html`,并包含 `#app` 挂载节点。插件会自动注入生成的 Taro H5 入口,因此你不需要普通 Vite 的 `src/main.tsx` 脚本。
@@ -287,12 +295,12 @@ export default function IndexPage() {
287
295
  ### 7. 运行每个目标
288
296
 
289
297
  ```sh
290
- pnpm dev:wx # 以 watch 模式重新构建 dist/wx
291
- pnpm dev:h5 # 启动 H5 开发服务器
292
- pnpm build:wx # 构建 dist/wx
293
- pnpm build:h5 # 构建 dist/h5
294
- pnpm preview:h5 # 预览 dist/h5
295
- pnpm typecheck # 使用 tsgo 进行类型检查
298
+ npm run dev:wx # 以 watch 模式重新构建 dist/wx
299
+ npm run dev:h5 # 启动 H5 开发服务器
300
+ npm run build:wx # 构建 dist/wx
301
+ npm run build:h5 # 构建 dist/h5
302
+ npm run preview:h5 # 预览 dist/h5
303
+ npm run typecheck # 使用 tsgo 进行类型检查
296
304
  ```
297
305
 
298
306
  在微信开发者工具中打开生成的 `dist/wx` 目录。
@@ -499,7 +507,7 @@ pnpm typecheck
499
507
  | 问题 | 检查项 |
500
508
  | --- | --- |
501
509
  | `VITE_PLUGIN_TARO_TARGET must be "wx" or "h5"` | 在脚本或 `.env` 文件中设置目标环境变量。 |
502
- | `pnpm install` 提示忽略了依赖构建脚本 | 运行 `pnpm approve-builds`,按提示批准需要构建的依赖;如有需要再重新执行 `pnpm install`。 |
510
+ | `pnpm install` 提示忽略了依赖构建脚本 | 运行 `pnpm approve-builds`,按提示批准需要构建的依赖。 |
503
511
  | 页面无法解析 | 确认 `pages[].path` 有匹配的 `src/${path}.tsx` 文件。 |
504
512
  | 微信开发者工具无法打开应用 | 打开生成的 `dist/wx` 文件夹,并检查 `projectConfigJson.appid`。 |
505
513
  | H5 显示空白页 | 确保 `index.html` 中保留 `<div id="app"></div>`,已注册插件,并避免添加单独的默认 Vite `main.tsx` 入口。 |
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite-plugin-taro",
3
- "version": "0.1.2",
3
+ "version": "0.1.4",
4
4
  "author": "sep2",
5
5
  "description": "Vite 8 plugin for building one React/Taro codebase for WeChat Mini Program and H5 targets.",
6
6
  "type": "module",
@@ -64,8 +64,8 @@
64
64
  "babel-plugin-transform-taroapi": "^4.2.0",
65
65
  "tailwindcss": "^4.3.1",
66
66
  "weapp-tailwindcss": "^5.0.13",
67
- "@tarojs/react": "npm:vite-plugin-taro-react@0.1.2",
68
- "@tarojs/plugin-framework-react": "npm:vite-plugin-taro-plugin-framework-react@0.1.2"
67
+ "@tarojs/plugin-framework-react": "npm:vite-plugin-taro-plugin-framework-react@0.1.4",
68
+ "@tarojs/react": "npm:vite-plugin-taro-react@0.1.4"
69
69
  },
70
70
  "peerDependencies": {
71
71
  "react": "^19.0.0",