vite-plugin-taro 0.1.7 → 0.2.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 +165 -166
- package/README.zh.md +542 -0
- package/dist/vite/constants.js +3 -5
- package/dist/vite/targets/h5.js +4 -4
- package/dist/vite/targets/wx.js +2 -2
- package/dist/vite/utils.js +5 -2
- package/package.json +5 -5
- package/src/vite/constants.ts +3 -6
- package/src/vite/targets/h5.ts +4 -4
- package/src/vite/targets/wx.ts +2 -2
- package/src/vite/utils.ts +5 -2
- package/README.en.md +0 -543
package/README.md
CHANGED
|
@@ -4,114 +4,114 @@
|
|
|
4
4
|

|
|
5
5
|
[](LICENSE)
|
|
6
6
|
|
|
7
|
-
简体中文
|
|
7
|
+
[简体中文](README.zh.md) | English
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
Build WeChat Mini Apps with the latest standards-based frontend stack: Vite 8, React 19, and Tailwind CSS v4.
|
|
10
10
|
|
|
11
|
-
`vite-plugin-taro`
|
|
11
|
+
`vite-plugin-taro` is for applications that want Taro's cross-platform React components and APIs, but prefer Vite instead of Taro webpack. You only need this plugin to build a complete WeChat Mini Program.
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
Live demo: <https://sep2.github.io/vite-plugin-taro>. See [Sample app](https://github.com/sep2/vite-plugin-taro/tree/main/packages/loan-genius/README.md) how to run it locally.
|
|
14
14
|
|
|
15
|
-
-
|
|
16
|
-
-
|
|
17
|
-
-
|
|
18
|
-
- **Tailwind
|
|
19
|
-
-
|
|
20
|
-
-
|
|
21
|
-
-
|
|
22
|
-
-
|
|
15
|
+
- **Native Vite builds** Use standard Vite 8 config instead of legacy webpack configuration, with support for all Vite plugins.
|
|
16
|
+
- **Hot reload** Both WeChat Mini Program and H5 support dev-mode watch, with Vite 8 HMR/rebuilds for fast feedback.
|
|
17
|
+
- **Battle-tested Taro foundation** Use the full set of Taro APIs and components instead of reinventing cross-platform primitives.
|
|
18
|
+
- **Tailwind ready** Built-in Tailwind CSS v4 support for both WeChat Mini Program and H5 styles.
|
|
19
|
+
- **Conditional compilation** Use Taro-style `#ifdef` / `#ifndef` / `#if` blocks to split code and styles by WeChat / web target.
|
|
20
|
+
- **Workspace friendly** Supports standalone apps and monorepos, with npm, pnpm, Yarn, Bun, and other package managers.
|
|
21
|
+
- **Type-friendly** The project supports TypeScript all the way.
|
|
22
|
+
- **WeChat Skyline** Support WeChat Mini Program output with Skyline rendering mode.
|
|
23
23
|
|
|
24
|
-
##
|
|
24
|
+
## Quick start
|
|
25
25
|
|
|
26
|
-
|
|
26
|
+
Use `create-vite-taro` for new apps. It scaffolds a Vite 8 + React 19 + Tailwind CSS v4 + Taro 4 project.
|
|
27
27
|
|
|
28
|
-
### 1.
|
|
28
|
+
### 1. Create and install
|
|
29
29
|
|
|
30
30
|
```sh
|
|
31
|
-
#
|
|
31
|
+
# Create a new app from the default template
|
|
32
32
|
npm create vite-taro@latest my-app
|
|
33
33
|
|
|
34
|
-
#
|
|
34
|
+
# Enter the project and install dependencies
|
|
35
35
|
cd my-app
|
|
36
36
|
npm install
|
|
37
37
|
```
|
|
38
38
|
|
|
39
|
-
### 2.
|
|
39
|
+
### 2. Configure WeChat Mini Program App ID
|
|
40
40
|
|
|
41
|
-
|
|
41
|
+
The template creates `.env.local`. Set `VITE_PLUGIN_TARO_WECHAT_APP_ID` to your WeChat Mini Program App ID.
|
|
42
42
|
|
|
43
|
-
### 3.
|
|
43
|
+
### 3. Run in development
|
|
44
44
|
|
|
45
45
|
```sh
|
|
46
|
-
#
|
|
46
|
+
# WeChat Mini Program: rebuild dist/wx in watch mode
|
|
47
47
|
npm run dev:wx
|
|
48
48
|
|
|
49
|
-
#
|
|
49
|
+
# Then open dist/wx in WeChat DevTools
|
|
50
50
|
|
|
51
|
-
# H5
|
|
51
|
+
# H5: start the Vite dev server
|
|
52
52
|
npm run dev:h5
|
|
53
53
|
|
|
54
|
-
#
|
|
54
|
+
# Then open the standard Vite dev URL in your browser
|
|
55
55
|
# http://localhost:5173
|
|
56
56
|
```
|
|
57
57
|
|
|
58
|
-
|
|
58
|
+
You can keep `npm run dev:wx` and `npm run dev:h5` running at the same time in separate terminals.
|
|
59
59
|
|
|
60
|
-
|
|
60
|
+
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.
|
|
61
61
|
|
|
62
|
-
### 4.
|
|
62
|
+
### 4. Build, preview, and typecheck
|
|
63
63
|
|
|
64
64
|
```sh
|
|
65
|
-
#
|
|
65
|
+
# Production WeChat Mini Program output
|
|
66
66
|
npm run build:wx
|
|
67
67
|
|
|
68
|
-
#
|
|
68
|
+
# Production H5 output
|
|
69
69
|
npm run build:h5
|
|
70
70
|
|
|
71
|
-
#
|
|
71
|
+
# Preview the built H5 app
|
|
72
72
|
npm run preview:h5
|
|
73
73
|
|
|
74
|
-
#
|
|
74
|
+
# Typecheck with tsgo
|
|
75
75
|
npm run typecheck
|
|
76
76
|
```
|
|
77
77
|
|
|
78
|
-
### 5.
|
|
78
|
+
### 5. Use Taro virtual modules
|
|
79
79
|
|
|
80
|
-
|
|
80
|
+
Use these imports in app code:
|
|
81
81
|
|
|
82
82
|
```tsx
|
|
83
83
|
import Taro from 'virtual:taro/api'
|
|
84
84
|
import { Text, View } from 'virtual:taro/components'
|
|
85
85
|
```
|
|
86
86
|
|
|
87
|
-
|
|
|
87
|
+
| Import | Use |
|
|
88
88
|
| --- | --- |
|
|
89
|
-
| `virtual:taro/components` | Taro React
|
|
90
|
-
| `virtual:taro/api` | Taro
|
|
89
|
+
| `virtual:taro/components` | Taro React components such as `View`, `Text`, `Button`, `Image`, and `ScrollView`. |
|
|
90
|
+
| `virtual:taro/api` | Taro APIs and hooks such as `Taro.navigateTo`, `Taro.getWindowInfo`, and `Taro.useLaunch`. |
|
|
91
91
|
|
|
92
|
-
|
|
92
|
+
Usage is the same as Taro itself; see the [Taro website](https://docs.taro.zone) for component and API details.
|
|
93
93
|
|
|
94
|
-
|
|
94
|
+
You no longer need to install `@tarojs/*` packages; application code should not import from `@tarojs/*`.
|
|
95
95
|
|
|
96
96
|
|
|
97
|
-
##
|
|
97
|
+
## Manual setup for existing apps
|
|
98
98
|
|
|
99
|
-
|
|
99
|
+
For existing apps or custom project layouts, follow the steps below to wire the plugin manually. First, install the plugin:
|
|
100
100
|
|
|
101
101
|
```sh
|
|
102
102
|
npm install -D vite-plugin-taro
|
|
103
103
|
```
|
|
104
104
|
|
|
105
|
-
|
|
105
|
+
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:
|
|
106
106
|
|
|
107
107
|
```sh
|
|
108
108
|
npm install react react-dom
|
|
109
|
-
npm install -D vite @typescript/native-preview @types/node @types/react @types/react-dom
|
|
109
|
+
npm install -D vite @typescript/native-preview @types/node @types/react @types/react-dom cross-env
|
|
110
110
|
```
|
|
111
111
|
|
|
112
|
-
|
|
112
|
+
You should NOT have direct dependencies on `@tarojs/*` packages anymore. Remove them if you have.
|
|
113
113
|
|
|
114
|
-
|
|
114
|
+
The steps below create this source shape:
|
|
115
115
|
|
|
116
116
|
```text
|
|
117
117
|
my-app/
|
|
@@ -127,11 +127,11 @@ my-app/
|
|
|
127
127
|
└── index.tsx
|
|
128
128
|
```
|
|
129
129
|
|
|
130
|
-
|
|
130
|
+
You can also see a sample layout at [packages/loan-genius](https://github.com/sep2/vite-plugin-taro/tree/main/packages/loan-genius).
|
|
131
131
|
|
|
132
|
-
### 1.
|
|
132
|
+
### 1. Add TypeScript declarations
|
|
133
133
|
|
|
134
|
-
|
|
134
|
+
Add the plugin client types to `tsconfig.json` so TypeScript knows about the virtual modules:
|
|
135
135
|
|
|
136
136
|
```json
|
|
137
137
|
{
|
|
@@ -144,9 +144,9 @@ my-app/
|
|
|
144
144
|
}
|
|
145
145
|
```
|
|
146
146
|
|
|
147
|
-
### 2.
|
|
147
|
+
### 2. Configure Vite
|
|
148
148
|
|
|
149
|
-
|
|
149
|
+
Create `vite.config.ts` and choose the plugin target from an environment variable:
|
|
150
150
|
|
|
151
151
|
```ts
|
|
152
152
|
import { defineConfig, loadEnv } from 'vite'
|
|
@@ -200,17 +200,17 @@ export default defineConfig(({ mode }) => {
|
|
|
200
200
|
})
|
|
201
201
|
```
|
|
202
202
|
|
|
203
|
-
|
|
203
|
+
Important conventions:
|
|
204
204
|
|
|
205
|
-
-
|
|
206
|
-
- `app`
|
|
207
|
-
-
|
|
208
|
-
- `appJson.pages`
|
|
209
|
-
-
|
|
205
|
+
- `target` must be `wx` or `h5` for each Vite run.
|
|
206
|
+
- `app` is the root React app component module. It should default-export the app component.
|
|
207
|
+
- Every `pages[].path` maps to a file at `src/${path}.tsx`. For example, `pages/index/index` requires `src/pages/index/index.tsx`.
|
|
208
|
+
- `appJson.pages` is generated from `pages`; any `pages` field you put in `appJson` is overwritten.
|
|
209
|
+
- The plugin does not read Taro CLI config files such as `config/index.ts`, `app.config.ts`, or page `config.ts` files. Pass app and page config through the plugin options.
|
|
210
210
|
|
|
211
|
-
### 3.
|
|
211
|
+
### 3. Create the app component
|
|
212
212
|
|
|
213
|
-
`src/app.ts`
|
|
213
|
+
`src/app.ts` is the shared application wrapper. It receives the current page as `children`.
|
|
214
214
|
|
|
215
215
|
```tsx
|
|
216
216
|
import Taro from 'virtual:taro/api'
|
|
@@ -228,11 +228,11 @@ function App({ children }: PropsWithChildren) {
|
|
|
228
228
|
export default App
|
|
229
229
|
```
|
|
230
230
|
|
|
231
|
-
|
|
231
|
+
Import global styles from the app component. They are collected into `app.wxss` for WeChat builds and included in H5 output.
|
|
232
232
|
|
|
233
|
-
### 4.
|
|
233
|
+
### 4. Create a page component
|
|
234
234
|
|
|
235
|
-
`src/pages/index/index.tsx`
|
|
235
|
+
`src/pages/index/index.tsx` is the React component for `pages/index/index`.
|
|
236
236
|
|
|
237
237
|
```tsx
|
|
238
238
|
import Taro from 'virtual:taro/api'
|
|
@@ -256,9 +256,9 @@ export default function IndexPage() {
|
|
|
256
256
|
}
|
|
257
257
|
```
|
|
258
258
|
|
|
259
|
-
### 5.
|
|
259
|
+
### 5. Add the H5 HTML shell
|
|
260
260
|
|
|
261
|
-
|
|
261
|
+
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.
|
|
262
262
|
|
|
263
263
|
```html
|
|
264
264
|
<!doctype html>
|
|
@@ -274,44 +274,42 @@ export default function IndexPage() {
|
|
|
274
274
|
</html>
|
|
275
275
|
```
|
|
276
276
|
|
|
277
|
-
### 6.
|
|
277
|
+
### 6. Add scripts
|
|
278
278
|
|
|
279
|
-
|
|
279
|
+
Use the same scripts generated by `create-vite-taro`:
|
|
280
280
|
|
|
281
281
|
```json
|
|
282
282
|
{
|
|
283
283
|
"scripts": {
|
|
284
|
-
"dev:wx": "NODE_ENV=development VITE_PLUGIN_TARO_TARGET=wx vite build --watch",
|
|
285
|
-
"dev:h5": "NODE_ENV=development VITE_PLUGIN_TARO_TARGET=h5 vite",
|
|
286
|
-
"build:wx": "NODE_ENV=production VITE_PLUGIN_TARO_TARGET=wx vite build",
|
|
287
|
-
"build:h5": "NODE_ENV=production VITE_PLUGIN_TARO_TARGET=h5 vite build",
|
|
288
|
-
"preview:h5": "NODE_ENV=production VITE_PLUGIN_TARO_TARGET=h5 vite preview --outDir dist/h5",
|
|
284
|
+
"dev:wx": "cross-env NODE_ENV=development VITE_PLUGIN_TARO_TARGET=wx vite build --watch",
|
|
285
|
+
"dev:h5": "cross-env NODE_ENV=development VITE_PLUGIN_TARO_TARGET=h5 vite",
|
|
286
|
+
"build:wx": "cross-env NODE_ENV=production VITE_PLUGIN_TARO_TARGET=wx vite build",
|
|
287
|
+
"build:h5": "cross-env NODE_ENV=production VITE_PLUGIN_TARO_TARGET=h5 vite build",
|
|
288
|
+
"preview:h5": "cross-env NODE_ENV=production VITE_PLUGIN_TARO_TARGET=h5 vite preview --outDir dist/h5",
|
|
289
289
|
"typecheck": "tsgo -b"
|
|
290
290
|
}
|
|
291
291
|
}
|
|
292
292
|
```
|
|
293
293
|
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
### 7. 运行每个目标
|
|
294
|
+
### 7. Run each target
|
|
297
295
|
|
|
298
296
|
```sh
|
|
299
|
-
npm run dev:wx #
|
|
300
|
-
npm run dev:h5 #
|
|
301
|
-
npm run build:wx #
|
|
302
|
-
npm run build:h5 #
|
|
303
|
-
npm run preview:h5 #
|
|
304
|
-
npm run typecheck #
|
|
297
|
+
npm run dev:wx # Rebuild dist/wx in watch mode
|
|
298
|
+
npm run dev:h5 # Start the H5 dev server
|
|
299
|
+
npm run build:wx # Build dist/wx
|
|
300
|
+
npm run build:h5 # Build dist/h5
|
|
301
|
+
npm run preview:h5 # Preview dist/h5
|
|
302
|
+
npm run typecheck # Typecheck with tsgo
|
|
305
303
|
```
|
|
306
304
|
|
|
307
|
-
|
|
305
|
+
Open the generated `dist/wx` directory in WeChat DevTools.
|
|
308
306
|
|
|
309
|
-
|
|
|
307
|
+
| Target | Meaning | Output dir |
|
|
310
308
|
| --- | --- | --- |
|
|
311
|
-
| `wx` |
|
|
312
|
-
| `h5` | H5
|
|
309
|
+
| `wx` | WeChat Mini Program in both dev/prod mode. | `dist/wx` |
|
|
310
|
+
| `h5` | H5 production output. | `dist/h5` |
|
|
313
311
|
|
|
314
|
-
##
|
|
312
|
+
## Options
|
|
315
313
|
|
|
316
314
|
```ts
|
|
317
315
|
type VitePluginTaroTarget = 'wx' | 'h5'
|
|
@@ -331,22 +329,22 @@ type VitePluginTaroOptions = {
|
|
|
331
329
|
}
|
|
332
330
|
```
|
|
333
331
|
|
|
334
|
-
|
|
|
332
|
+
| Option | Description |
|
|
335
333
|
| --- | --- |
|
|
336
|
-
| `target` |
|
|
337
|
-
| `app` |
|
|
338
|
-
| `pages` |
|
|
339
|
-
| `pages[].path` |
|
|
340
|
-
| `pages[].config` |
|
|
341
|
-
| `appJson` |
|
|
342
|
-
| `projectConfigJson` |
|
|
343
|
-
| `sitemapJson` |
|
|
334
|
+
| `target` | Active target for this Vite invocation. Use `wx` for WeChat Mini Program and `h5` for Web. |
|
|
335
|
+
| `app` | Source file that default-exports the root React app component, for example `src/app.ts` or `src/app.tsx`. |
|
|
336
|
+
| `pages` | Ordered page list. The order becomes `app.json.pages` and the H5 route order. |
|
|
337
|
+
| `pages[].path` | Taro-style route and output path without extension, for example `pages/index/index`. The page component must exist at `src/${path}.tsx`. |
|
|
338
|
+
| `pages[].config` | Page config merged into the generated WeChat page JSON and H5 route config. |
|
|
339
|
+
| `appJson` | Base app config. The plugin overwrites the `pages` field from `options.pages`. |
|
|
340
|
+
| `projectConfigJson` | WeChat `project.config.json` content emitted for `wx` builds. It is required by the option type even when the current target is `h5`. |
|
|
341
|
+
| `sitemapJson` | WeChat `sitemap.json` content emitted for `wx` builds. It is required by the option type even when the current target is `h5`. |
|
|
344
342
|
|
|
345
|
-
##
|
|
343
|
+
## Styling
|
|
346
344
|
|
|
347
|
-
|
|
345
|
+
You can use plain CSS, CSS modules, or Tailwind CSS v4.
|
|
348
346
|
|
|
349
|
-
|
|
347
|
+
For Tailwind CSS v4, import Tailwind from a global CSS file such as `src/app.css`:
|
|
350
348
|
|
|
351
349
|
```css
|
|
352
350
|
@import "tailwindcss/theme.css";
|
|
@@ -356,11 +354,11 @@ type VitePluginTaroOptions = {
|
|
|
356
354
|
@source "./";
|
|
357
355
|
```
|
|
358
356
|
|
|
359
|
-
|
|
357
|
+
The plugin registers `weapp-tailwindcss` for `wx` builds and `@tailwindcss/vite` for `h5` builds. For `wx`, CSS emitted by Vite is collected into `app.wxss`, and page `.wxss` companion files are emitted for each page.
|
|
360
358
|
|
|
361
|
-
##
|
|
359
|
+
## Conditional compilation
|
|
362
360
|
|
|
363
|
-
|
|
361
|
+
The plugin strips inactive Taro-style conditional comment blocks before Vite parses source. This works in TypeScript, JavaScript, JSX/TSX, CSS, Sass, Less, and Stylus files outside `node_modules`.
|
|
364
362
|
|
|
365
363
|
```ts
|
|
366
364
|
// #ifdef wx
|
|
@@ -380,15 +378,15 @@ console.log('fallback')
|
|
|
380
378
|
// #endif
|
|
381
379
|
```
|
|
382
380
|
|
|
383
|
-
|
|
381
|
+
Supported directives are `#ifdef`, `#ifndef`, `#if`, `#elif`, `#else`, and `#endif`. Conditions use the plugin target tokens `wx` and `h5`; `#if` expressions support `!`, `&&`, and `||`.
|
|
384
382
|
|
|
385
|
-
##
|
|
383
|
+
## Output by target
|
|
386
384
|
|
|
387
|
-
###
|
|
385
|
+
### WeChat Mini Program
|
|
388
386
|
|
|
389
|
-
|
|
387
|
+
For `target: 'wx'`, the plugin configures Vite to emit WeChat-compatible CommonJS chunks and Mini Program companion files.
|
|
390
388
|
|
|
391
|
-
|
|
389
|
+
Typical output:
|
|
392
390
|
|
|
393
391
|
```text
|
|
394
392
|
dist/wx/
|
|
@@ -405,74 +403,74 @@ dist/wx/
|
|
|
405
403
|
└── pages/**
|
|
406
404
|
```
|
|
407
405
|
|
|
408
|
-
|
|
406
|
+
Open `dist/wx` with WeChat DevTools; do not open the source project directory.
|
|
409
407
|
|
|
410
408
|
### H5
|
|
411
409
|
|
|
412
|
-
|
|
410
|
+
For `target: 'h5'`, the plugin injects a generated module into `index.html`, imports Taro's H5 component styles, builds route records from `pages`, and mounts the app with Taro's hash-history router. Routes use the page paths from your config, for example `#/pages/index/index`.
|
|
413
411
|
|
|
414
|
-
##
|
|
412
|
+
## Migrating from Taro
|
|
415
413
|
|
|
416
|
-
|
|
414
|
+
You can keep most React page components, business logic, assets, and styles, but the build entry moves from Taro CLI config to Vite config.
|
|
417
415
|
|
|
418
|
-
|
|
416
|
+
Migration checklist:
|
|
419
417
|
|
|
420
|
-
1.
|
|
421
|
-
2.
|
|
422
|
-
3.
|
|
423
|
-
4.
|
|
424
|
-
5.
|
|
425
|
-
6.
|
|
418
|
+
1. Install `vite-plugin-taro` and create `vite.config.ts` with `vitePluginTaro(...)`.
|
|
419
|
+
2. Move app config and page config into the plugin options. The plugin does not read Taro CLI files such as `config/index.ts`, `app.config.ts`, or page `config.ts` files.
|
|
420
|
+
3. Register every page in `pages`. Each page path must match `src/${path}.tsx`.
|
|
421
|
+
4. Replace Taro scripts with Vite scripts that set `VITE_PLUGIN_TARO_TARGET=wx` or `VITE_PLUGIN_TARO_TARGET=h5`.
|
|
422
|
+
5. For H5, add a normal Vite `index.html` with `<div id="app"></div>` and no separate `src/main.tsx` entry.
|
|
423
|
+
6. Replace application imports from `@tarojs/*` with the plugin virtual modules.
|
|
426
424
|
|
|
427
|
-
|
|
425
|
+
Before:
|
|
428
426
|
|
|
429
427
|
```tsx
|
|
430
428
|
import Taro from '@tarojs/taro'
|
|
431
429
|
import { Text, View } from '@tarojs/components'
|
|
432
430
|
```
|
|
433
431
|
|
|
434
|
-
|
|
432
|
+
After:
|
|
435
433
|
|
|
436
434
|
```tsx
|
|
437
435
|
import Taro from 'virtual:taro/api'
|
|
438
436
|
import { Text, View } from 'virtual:taro/components'
|
|
439
437
|
```
|
|
440
438
|
|
|
441
|
-
|
|
439
|
+
Direct `@tarojs/*` imports in application code are forbidden. Let the plugin own Taro runtime resolution so WeChat and H5 builds receive the correct target-specific aliases.
|
|
442
440
|
|
|
443
|
-
##
|
|
441
|
+
## Sample app
|
|
444
442
|
|
|
445
|
-
|
|
443
|
+
The sample app lives in [`packages/loan-genius`](https://github.com/sep2/vite-plugin-taro/tree/main/packages/loan-genius). It demonstrates the page convention, target selection, WeChat output, H5 routing, and Tailwind styling.
|
|
446
444
|
|
|
447
445
|
```sh
|
|
448
446
|
git clone https://github.com/sep2/vite-plugin-taro.git
|
|
449
447
|
|
|
450
|
-
#
|
|
448
|
+
# Install dependencies
|
|
451
449
|
pnpm install
|
|
452
450
|
|
|
453
|
-
#
|
|
451
|
+
# Run once, it generates the patched Taro packages
|
|
454
452
|
pnpm prepare:taro
|
|
455
453
|
|
|
456
|
-
#
|
|
454
|
+
# Build the plugin for sample app to use
|
|
457
455
|
pnpm build:plugin
|
|
458
456
|
|
|
459
|
-
#
|
|
457
|
+
# Run the sample app in WeChat
|
|
460
458
|
pnpm dev:sample:wx
|
|
461
459
|
|
|
462
|
-
#
|
|
460
|
+
# Build the sample app to WeChat output
|
|
463
461
|
pnpm build:sample:wx
|
|
464
462
|
|
|
465
|
-
#
|
|
463
|
+
# Run the sample app in H5 dev mode
|
|
466
464
|
pnpm dev:sample:h5
|
|
467
465
|
|
|
468
|
-
#
|
|
466
|
+
# Build the sample app to H5 output and preview it
|
|
469
467
|
pnpm build:sample:h5
|
|
470
468
|
pnpm preview:sample:h5
|
|
471
469
|
```
|
|
472
470
|
|
|
473
|
-
|
|
471
|
+
Open `packages/loan-genius/dist/wx` with WeChat DevTools to test the Mini Program output.
|
|
474
472
|
|
|
475
|
-
##
|
|
473
|
+
## Develop this repository
|
|
476
474
|
|
|
477
475
|
```sh
|
|
478
476
|
pnpm install
|
|
@@ -481,53 +479,54 @@ pnpm build:plugin
|
|
|
481
479
|
pnpm typecheck
|
|
482
480
|
```
|
|
483
481
|
|
|
484
|
-
|
|
482
|
+
Common scripts:
|
|
485
483
|
|
|
486
|
-
|
|
|
484
|
+
| Script | Description |
|
|
487
485
|
| --- | --- |
|
|
488
|
-
| `pnpm prepare:taro` |
|
|
489
|
-
| `pnpm build:plugin` |
|
|
490
|
-
| `pnpm typecheck` |
|
|
491
|
-
| `pnpm lint` |
|
|
492
|
-
| `pnpm format` |
|
|
493
|
-
| `pnpm dev:sample:wx` |
|
|
494
|
-
| `pnpm dev:sample:h5` |
|
|
495
|
-
| `pnpm build:sample:wx` |
|
|
496
|
-
| `pnpm build:sample:h5` |
|
|
497
|
-
| `pnpm preview:sample:h5` |
|
|
498
|
-
| `pnpm
|
|
499
|
-
| `pnpm
|
|
500
|
-
| `pnpm
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
486
|
+
| `pnpm prepare:taro` | Regenerate the patched React 19 Taro packages from upstream npm tarballs and local patch files. |
|
|
487
|
+
| `pnpm build:plugin` | Build `packages/vite-plugin-taro` into `dist`. |
|
|
488
|
+
| `pnpm typecheck` | Typecheck the plugin and sample app with `tsgo`. |
|
|
489
|
+
| `pnpm lint` | Run Biome checks. |
|
|
490
|
+
| `pnpm format` | Apply Biome formatting. |
|
|
491
|
+
| `pnpm dev:sample:wx` | Build the sample WeChat Mini Program in watch mode. Build the plugin first. |
|
|
492
|
+
| `pnpm dev:sample:h5` | Start the sample H5 app in Vite dev mode. Build the plugin first. |
|
|
493
|
+
| `pnpm build:sample:wx` | Build the WeChat Mini Program sample to `packages/loan-genius/dist/wx`. |
|
|
494
|
+
| `pnpm build:sample:h5` | Build the H5 sample app to `packages/loan-genius/dist/h5`. |
|
|
495
|
+
| `pnpm preview:sample:h5` | Preview the built H5 sample. |
|
|
496
|
+
| `pnpm changelog` | Regenerate `CHANGELOG.md` from git release tags. |
|
|
497
|
+
| `pnpm publish:dry` | Dry-run package validation and publishing. |
|
|
498
|
+
| `pnpm release <version\|bump>` | Validate, bump versions, update the changelog, create the release commit and tag, and push to trigger CI publishing. |
|
|
499
|
+
| `pnpm publish:all` | Publish the public packages in dependency order; mainly used by the tag-based Trusted Publishing workflow. |
|
|
500
|
+
|
|
501
|
+
## Limitations
|
|
502
|
+
|
|
503
|
+
- Only `wx` and `h5` targets are generated today.
|
|
504
|
+
- Application code must not import `@tarojs/*` packages directly.
|
|
505
|
+
|
|
506
|
+
## Troubleshooting
|
|
507
|
+
|
|
508
|
+
| Problem | Check |
|
|
510
509
|
| --- | --- |
|
|
511
|
-
| `VITE_PLUGIN_TARO_TARGET must be "wx" or "h5"` |
|
|
512
|
-
| `pnpm install`
|
|
513
|
-
|
|
|
514
|
-
|
|
|
515
|
-
| H5
|
|
516
|
-
| Taro
|
|
517
|
-
|
|
|
518
|
-
| Tailwind
|
|
510
|
+
| `VITE_PLUGIN_TARO_TARGET must be "wx" or "h5"` | Set the target environment variable in your script or `.env` file. |
|
|
511
|
+
| `pnpm install` says dependency build scripts were ignored | Run `pnpm approve-builds` and approve the requested dependency build scripts. |
|
|
512
|
+
| A page cannot be resolved | Confirm that `pages[].path` has a matching `src/${path}.tsx` file. |
|
|
513
|
+
| WeChat DevTools cannot open the app | Open the generated `dist/wx` folder and check `projectConfigJson.appid`. |
|
|
514
|
+
| 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. |
|
|
515
|
+
| Taro APIs are missing or behave differently | Remove direct `@tarojs/*` imports from application code and import Taro from `virtual:taro/api`. |
|
|
516
|
+
| Components render without expected styles on H5 | Import components from `virtual:taro/components` and keep the plugin enabled for the `h5` target. |
|
|
517
|
+
| Tailwind classes do not appear | Ensure your global CSS imports Tailwind and includes an `@source` path that covers your source files. |
|
|
519
518
|
|
|
520
|
-
##
|
|
519
|
+
## Release workflow
|
|
521
520
|
|
|
522
|
-
|
|
521
|
+
This repository publishes automatically with npm Trusted Publishing and GitHub Actions. Normal pushes to `main` do not publish; only tags matching `v*.*.*` trigger `.github/workflows/publish.yml`.
|
|
523
522
|
|
|
524
|
-
|
|
523
|
+
Create a release:
|
|
525
524
|
|
|
526
525
|
```sh
|
|
527
526
|
pnpm release patch
|
|
528
527
|
```
|
|
529
528
|
|
|
530
|
-
`pnpm release`
|
|
529
|
+
`pnpm release` requires a clean `main` working tree, runs `pnpm version:bump`, validates with `pnpm publish:dry -- --no-git-check`, creates the `chore: release vX.Y.Z` commit and `vX.Y.Z` tag, then pushes the branch and tag to trigger CI. You can also release an exact version or prerelease:
|
|
531
530
|
|
|
532
531
|
```sh
|
|
533
532
|
pnpm release 0.2.0
|
|
@@ -536,8 +535,8 @@ pnpm release patch --dry-run
|
|
|
536
535
|
pnpm release patch --no-push
|
|
537
536
|
```
|
|
538
537
|
|
|
539
|
-
CI
|
|
538
|
+
CI runs `pnpm publish:all -- --no-git-check`, packs packages in dependency order, and publishes public packages through npm OIDC. Do not configure `NPM_TOKEN` for the publish workflow; each npm package's Trusted Publisher should point to `publish.yml`.
|
|
540
539
|
|
|
541
|
-
##
|
|
540
|
+
## License
|
|
542
541
|
|
|
543
542
|
MIT
|