vite-plugin-taro 0.2.2 → 0.3.1

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 (133) hide show
  1. package/README.md +83 -106
  2. package/README.zh.md +83 -104
  3. package/dist/node/build-context.d.ts +25 -0
  4. package/dist/node/build-context.js +48 -0
  5. package/dist/node/css/css-pipeline.d.ts +21 -0
  6. package/dist/node/css/css-pipeline.js +129 -0
  7. package/dist/node/plugins/conditional-directives.d.ts +3 -0
  8. package/dist/node/plugins/conditional-directives.js +62 -0
  9. package/dist/node/plugins/taro-runtime.d.ts +5 -0
  10. package/dist/node/plugins/taro-runtime.js +18 -0
  11. package/dist/node/targets/h5/plugin.d.ts +6 -0
  12. package/dist/node/targets/h5/plugin.js +117 -0
  13. package/dist/node/targets/h5/virtual-modules.d.ts +5 -0
  14. package/dist/node/targets/h5/virtual-modules.js +60 -0
  15. package/dist/node/targets/wx/companion-assets.d.ts +19 -0
  16. package/dist/node/targets/wx/companion-assets.js +129 -0
  17. package/dist/node/targets/wx/dev-server/development-session.d.ts +31 -0
  18. package/dist/node/targets/wx/dev-server/development-session.js +202 -0
  19. package/dist/node/targets/wx/dev-server/full-build-scheduler.d.ts +14 -0
  20. package/dist/node/targets/wx/dev-server/full-build-scheduler.js +60 -0
  21. package/dist/node/targets/wx/dev-server/js-utils.d.ts +5 -0
  22. package/dist/node/targets/wx/dev-server/js-utils.js +28 -0
  23. package/dist/node/targets/wx/dev-server/output.d.ts +19 -0
  24. package/dist/node/targets/wx/dev-server/output.js +44 -0
  25. package/dist/node/targets/wx/dev-server/rolldown-runtime-source.d.ts +8 -0
  26. package/dist/node/targets/wx/dev-server/rolldown-runtime-source.js +95 -0
  27. package/dist/node/targets/wx/dev-server/update-server-state.d.ts +65 -0
  28. package/dist/node/targets/wx/dev-server/update-server-state.js +116 -0
  29. package/dist/node/targets/wx/dev-server/update-transport.d.ts +28 -0
  30. package/dist/node/targets/wx/dev-server/update-transport.js +212 -0
  31. package/dist/node/targets/wx/dev-server/vite-bundled-dev-adapter.d.ts +44 -0
  32. package/dist/node/targets/wx/dev-server/vite-bundled-dev-adapter.js +145 -0
  33. package/dist/node/targets/wx/development-files.d.ts +8 -0
  34. package/dist/node/targets/wx/development-files.js +8 -0
  35. package/dist/node/targets/wx/plugin.d.ts +6 -0
  36. package/dist/node/targets/wx/plugin.js +143 -0
  37. package/dist/node/targets/wx/react-refresh.d.ts +4 -0
  38. package/dist/node/targets/wx/react-refresh.js +38 -0
  39. package/dist/node/targets/wx/virtual-modules.d.ts +16 -0
  40. package/dist/node/targets/wx/virtual-modules.js +120 -0
  41. package/dist/node/utils/async.d.ts +8 -0
  42. package/dist/node/utils/async.js +16 -0
  43. package/dist/node/utils/filesystem.d.ts +13 -0
  44. package/dist/node/utils/filesystem.js +43 -0
  45. package/dist/{vite/utils.d.ts → node/utils/modules.d.ts} +2 -2
  46. package/dist/{vite/utils.js → node/utils/modules.js} +10 -3
  47. package/dist/node/utils/packages.d.ts +2 -0
  48. package/dist/node/utils/packages.js +8 -0
  49. package/dist/node/vite-plugin.d.ts +4 -0
  50. package/dist/node/vite-plugin.js +33 -0
  51. package/dist/options.d.ts +21 -0
  52. package/dist/{shim/h5.d.ts → runtime/h5/taro-runtime.d.ts} +3 -1
  53. package/dist/runtime/h5/taro-runtime.js +9 -0
  54. package/dist/runtime/taro/api.d.ts +5 -0
  55. package/dist/{virtual → runtime/taro}/api.js +3 -0
  56. package/dist/runtime/taro/components.d.ts +2 -0
  57. package/dist/runtime/taro/components.js +2 -0
  58. package/dist/runtime/wx/page-update.d.ts +6 -0
  59. package/dist/runtime/wx/page-update.js +157 -0
  60. package/dist/{shim/wx.d.ts → runtime/wx/taro-runtime.d.ts} +1 -0
  61. package/dist/{shim/wx.js → runtime/wx/taro-runtime.js} +1 -0
  62. package/dist/runtime/wx/update-client-state.d.ts +68 -0
  63. package/dist/runtime/wx/update-client-state.js +84 -0
  64. package/dist/runtime/wx/update-client.d.ts +1 -0
  65. package/dist/runtime/wx/update-client.js +170 -0
  66. package/dist/vite.d.ts +2 -2
  67. package/dist/vite.js +1 -1
  68. package/package.json +15 -11
  69. package/src/node/build-context.ts +63 -0
  70. package/src/node/css/css-pipeline.ts +147 -0
  71. package/src/node/plugins/conditional-directives.ts +76 -0
  72. package/src/node/plugins/taro-runtime.ts +22 -0
  73. package/src/node/targets/h5/plugin.ts +135 -0
  74. package/src/node/targets/h5/virtual-modules.ts +71 -0
  75. package/src/node/targets/wx/companion-assets.ts +170 -0
  76. package/src/node/targets/wx/dev-server/development-session.ts +253 -0
  77. package/src/node/targets/wx/dev-server/full-build-scheduler.ts +62 -0
  78. package/src/node/targets/wx/dev-server/js-utils.ts +33 -0
  79. package/src/node/targets/wx/dev-server/output.ts +56 -0
  80. package/src/node/targets/wx/dev-server/rolldown-runtime-source.ts +95 -0
  81. package/src/node/targets/wx/dev-server/update-server-state.ts +183 -0
  82. package/src/node/targets/wx/dev-server/update-transport.ts +261 -0
  83. package/src/node/targets/wx/dev-server/vite-bundled-dev-adapter.ts +203 -0
  84. package/src/node/targets/wx/development-files.ts +11 -0
  85. package/src/node/targets/wx/plugin.ts +163 -0
  86. package/src/node/targets/wx/react-refresh.ts +51 -0
  87. package/src/node/targets/wx/virtual-modules.ts +152 -0
  88. package/src/node/utils/async.ts +19 -0
  89. package/src/node/utils/filesystem.ts +45 -0
  90. package/src/{vite/utils.ts → node/utils/modules.ts} +11 -3
  91. package/src/node/utils/packages.ts +10 -0
  92. package/src/node/vite-plugin.ts +41 -0
  93. package/src/options.ts +25 -0
  94. package/src/runtime/h5/taro-css.d.ts +3 -0
  95. package/src/runtime/h5/taro-runtime.ts +10 -0
  96. package/src/{virtual → runtime/taro}/api.ts +3 -0
  97. package/src/runtime/taro/components.ts +2 -0
  98. package/src/runtime/wx/page-update.ts +230 -0
  99. package/src/runtime/wx/react-refresh.d.ts +20 -0
  100. package/src/{shim/wx.ts → runtime/wx/taro-runtime.ts} +1 -0
  101. package/src/runtime/wx/update-client-state.ts +138 -0
  102. package/src/runtime/wx/update-client.ts +222 -0
  103. package/src/vite.ts +2 -2
  104. package/dist/shim/h5.js +0 -5
  105. package/dist/virtual/api.d.ts +0 -3
  106. package/dist/virtual/components.d.ts +0 -1
  107. package/dist/virtual/components.js +0 -1
  108. package/dist/vite/constants.d.ts +0 -4
  109. package/dist/vite/constants.js +0 -8
  110. package/dist/vite/plugins.d.ts +0 -8
  111. package/dist/vite/plugins.js +0 -186
  112. package/dist/vite/tailwindcss.d.ts +0 -3
  113. package/dist/vite/tailwindcss.js +0 -35
  114. package/dist/vite/targets/h5.d.ts +0 -31
  115. package/dist/vite/targets/h5.js +0 -201
  116. package/dist/vite/targets/wx.d.ts +0 -74
  117. package/dist/vite/targets/wx.js +0 -362
  118. package/dist/vite/types.d.ts +0 -38
  119. package/dist/vite/virtual-modules.d.ts +0 -3
  120. package/dist/vite/virtual-modules.js +0 -13
  121. package/dist/vite/vite-plugin-taro.d.ts +0 -7
  122. package/dist/vite/vite-plugin-taro.js +0 -80
  123. package/src/shim/h5.ts +0 -6
  124. package/src/virtual/components.ts +0 -1
  125. package/src/vite/constants.ts +0 -12
  126. package/src/vite/plugins.ts +0 -218
  127. package/src/vite/tailwindcss.ts +0 -41
  128. package/src/vite/targets/h5.ts +0 -229
  129. package/src/vite/targets/wx.ts +0 -436
  130. package/src/vite/types.ts +0 -48
  131. package/src/vite/virtual-modules.ts +0 -14
  132. package/src/vite/vite-plugin-taro.ts +0 -106
  133. /package/dist/{vite/types.js → options.js} +0 -0
package/README.md CHANGED
@@ -6,20 +6,20 @@
6
6
 
7
7
  [简体中文](README.zh.md) | English
8
8
 
9
- Build WeChat Mini Apps with the latest standards-based frontend stack: Vite 8, React 19, and Tailwind CSS v4.
9
+ Build WeChat Mini Program and Web apps with the latest standards-based frontend stack: Vite 8, React 19, Taro 4, and Tailwind CSS v4.
10
10
 
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.
11
+ `vite-plugin-taro` is for teams building Taro React apps with Vite: keep Taro's cross-platform components and APIs, leave Taro webpack behind, and fix/avoid common official Taro Vite pitfalls. One plugin builds WeChat Mini Program and Web.
12
12
 
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.
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) for how to run it locally.
14
14
 
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.
15
+ - **Vite 8 + React 19** Build one codebase for WeChat Mini Program and Web with the Vite ecosystem.
16
+ - **Hot reload** Re-engineered on Vite with seamless WeChat Mini Program support, so page edits no longer lose state.
17
+ - **Tailwind CSS v4 ready** Write utility classes directly; WeChat and Web styles adapt automatically.
18
+ - **Built on Taro, beyond Taro** Use Taro components and APIs while leaving the old webpack pipeline behind.
19
+ - **Skyline ready** Support WeChat Skyline rendering mode perfectly.
20
+ - **Conditional compilation** Split code and styles with Taro-style `#ifdef` / `#ifndef` blocks.
21
+ - **Workspace friendly** Supports standalone apps and monorepos, compatible with `npm`, `pnpm`, `Yarn`, and `Bun`.
22
+ - **TypeScript friendly** Type support from config to app code.
23
23
 
24
24
  ## Quick start
25
25
 
@@ -31,6 +31,9 @@ Use `create-vite-taro` for new apps. It scaffolds a Vite 8 + React 19 + Tailwind
31
31
  # Create a new app from the default template
32
32
  npm create vite-taro@latest my-app
33
33
 
34
+ # Or create with pnpm
35
+ pnpm --config.minimum-release-age=0 create vite-taro@latest my-app
36
+
34
37
  # Enter the project and install dependencies
35
38
  cd my-app
36
39
  npm install
@@ -43,7 +46,7 @@ The template creates `.env.local`. Set `VITE_PLUGIN_TARO_WECHAT_APP_ID` to your
43
46
  ### 3. Run in development
44
47
 
45
48
  ```sh
46
- # WeChat Mini Program: rebuild dist/wx in watch mode
49
+ # WeChat Mini Program: start Vite with hot reload
47
50
  npm run dev:wx
48
51
 
49
52
  # Then open dist/wx in WeChat DevTools
@@ -57,7 +60,7 @@ npm run dev:h5
57
60
 
58
61
  You can keep `npm run dev:wx` and `npm run dev:h5` running at the same time in separate terminals.
59
62
 
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.
63
+ WX development provides full Vite-powered hot reload through Rolldown's incremental module graph and React Refresh. JavaScript edits preserve the active native page and React/input state; CSS, assets, public files, and configuration changes are rebuilt automatically.
61
64
 
62
65
  ### 4. Build, preview, and typecheck
63
66
 
@@ -93,7 +96,6 @@ Usage is the same as Taro itself; see the [Taro website](https://docs.taro.zone)
93
96
 
94
97
  You no longer need to install `@tarojs/*` packages; application code should not import from `@tarojs/*`.
95
98
 
96
-
97
99
  ## Manual setup for existing apps
98
100
 
99
101
  For existing apps or custom project layouts, follow the steps below to wire the plugin manually. First, install the plugin:
@@ -109,7 +111,7 @@ npm install react react-dom
109
111
  npm install -D vite typescript@rc @types/node @types/react @types/react-dom cross-env
110
112
  ```
111
113
 
112
- You should NOT have direct dependencies on `@tarojs/*` packages anymore. Remove them if you have.
114
+ Remove all `@tarojs/*` packages from `dependencies` and `devDependencies`.
113
115
 
114
116
  The steps below create this source shape:
115
117
 
@@ -172,19 +174,9 @@ export default defineConfig(({ mode }) => {
172
174
  vitePluginTaro({
173
175
  target,
174
176
  app: 'src/app.ts',
175
- pages: [
176
- {
177
- path: 'pages/index/index',
178
- config: {
179
- navigationBarTitleText: 'Home'
180
- }
181
- }
182
- ],
177
+ pages: [{ path: 'pages/index/index', config: { navigationBarTitleText: 'Home' } }],
183
178
  appJson: {
184
- window: {
185
- navigationBarTitleText: 'Demo',
186
- navigationBarBackgroundColor: '#ffffff'
187
- }
179
+ window: { navigationBarTitleText: 'Demo' }
188
180
  },
189
181
  projectConfigJson: {
190
182
  appid: env.VITE_PLUGIN_TARO_WECHAT_APP_ID || 'touristappid',
@@ -206,6 +198,7 @@ Important conventions:
206
198
  - `app` is the root React app component module. It should default-export the app component.
207
199
  - Every `pages[].path` maps to a file at `src/${path}.tsx`. For example, `pages/index/index` requires `src/pages/index/index.tsx`.
208
200
  - `appJson.pages` is generated from `pages`; any `pages` field you put in `appJson` is overwritten.
201
+ - If your app uses Skyline, add the related `appJson` and `projectConfigJson` settings.
209
202
  - 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
203
 
211
204
  ### 3. Create the app component
@@ -213,75 +206,62 @@ Important conventions:
213
206
  `src/app.ts` is the shared application wrapper. It receives the current page as `children`.
214
207
 
215
208
  ```tsx
216
- import Taro from 'virtual:taro/api'
217
209
  import type { PropsWithChildren } from 'react'
218
210
  import './app.css'
219
211
 
220
- function App({ children }: PropsWithChildren) {
221
- Taro.useLaunch(() => {
222
- console.log('App launched')
223
- })
224
-
212
+ export default function App({ children }: PropsWithChildren) {
225
213
  return children
226
214
  }
215
+ ```
216
+
217
+ Import global styles from the app component. The next step creates `src/app.css`.
218
+
219
+ ### 4. Create global styles
220
+
221
+ `src/app.css` can use plain CSS, component CSS modules, and Tailwind CSS v4. The plugin injects Taro H5 component styles automatically; the default global stylesheet enables Tailwind CSS v4 for both targets:
222
+
223
+ ```css
224
+ @import "tailwindcss/theme.css";
225
+ @import "tailwindcss/preflight.css";
226
+ @import "tailwindcss/utilities.css";
227
227
 
228
- export default App
228
+ @source "./";
229
229
  ```
230
230
 
231
- Import global styles from the app component. They are collected into `app.wxss` for WeChat builds and included in H5 output.
231
+ Keep `@source "./";` so Tailwind scans your source tree.
232
232
 
233
- ### 4. Create a page component
233
+ ### 5. Create a page component
234
234
 
235
235
  `src/pages/index/index.tsx` is the React component for `pages/index/index`.
236
236
 
237
237
  ```tsx
238
- import Taro from 'virtual:taro/api'
239
- import { Button, Text, View } from 'virtual:taro/components'
238
+ import { Text, View } from 'virtual:taro/components'
240
239
 
241
240
  export default function IndexPage() {
242
- const windowInfo = Taro.getWindowInfo()
243
-
244
241
  return (
245
242
  <View className="p-4">
246
- <Text>Viewport width: {windowInfo.windowWidth}</Text>
247
- <Button
248
- onClick={() => {
249
- Taro.showToast({ title: 'Hello from Taro' })
250
- }}
251
- >
252
- Show toast
253
- </Button>
243
+ <Text>Hello Taro</Text>
254
244
  </View>
255
245
  )
256
246
  }
257
247
  ```
258
248
 
259
- ### 5. Add the H5 HTML shell
249
+ ### 6. Add the H5 HTML shell
260
250
 
261
251
  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
252
 
263
253
  ```html
264
- <!doctype html>
265
- <html lang="en">
266
- <head>
267
- <meta charset="UTF-8" />
268
- <meta name="viewport" content="width=device-width, initial-scale=1.0" />
269
- <title>Taro Vite App</title>
270
- </head>
271
- <body>
272
- <div id="app"></div>
273
- </body>
274
- </html>
254
+ <div id="app"></div>
275
255
  ```
276
256
 
277
- ### 6. Add scripts
257
+ ### 7. Add scripts
278
258
 
279
259
  Use the same scripts generated by `create-vite-taro`:
280
260
 
281
261
  ```json
282
262
  {
283
263
  "scripts": {
284
- "dev:wx": "cross-env NODE_ENV=development VITE_PLUGIN_TARO_TARGET=wx vite build --watch",
264
+ "dev:wx": "cross-env NODE_ENV=development VITE_PLUGIN_TARO_TARGET=wx vite",
285
265
  "dev:h5": "cross-env NODE_ENV=development VITE_PLUGIN_TARO_TARGET=h5 vite",
286
266
  "build:wx": "cross-env NODE_ENV=production VITE_PLUGIN_TARO_TARGET=wx vite build",
287
267
  "build:h5": "cross-env NODE_ENV=production VITE_PLUGIN_TARO_TARGET=h5 vite build",
@@ -291,10 +271,10 @@ Use the same scripts generated by `create-vite-taro`:
291
271
  }
292
272
  ```
293
273
 
294
- ### 7. Run each target
274
+ ### 8. Run each target
295
275
 
296
276
  ```sh
297
- npm run dev:wx # Rebuild dist/wx in watch mode
277
+ npm run dev:wx # Start WX development with hot reload
298
278
  npm run dev:h5 # Start the H5 dev server
299
279
  npm run build:wx # Build dist/wx
300
280
  npm run build:h5 # Build dist/h5
@@ -304,6 +284,8 @@ npm run typecheck # Typecheck with tsc
304
284
 
305
285
  Open the generated `dist/wx` directory in WeChat DevTools.
306
286
 
287
+ WX development completes an eager build of the App and every configured page before Vite reports ready. JavaScript and TypeScript component edits use React Refresh and preserve compatible React state, the current Taro page, and native input state. Module-local state resets on each code update. Changes to CSS, assets, or app configuration intentionally perform a complete rebuild and DevTools reload. The generated development project enables WeChat's `compileHotReLoad` setting automatically.
288
+
307
289
  | Target | Meaning | Output dir |
308
290
  | --- | --- | --- |
309
291
  | `wx` | WeChat Mini Program in both dev/prod mode. | `dist/wx` |
@@ -333,29 +315,13 @@ type VitePluginTaroOptions = {
333
315
  | --- | --- |
334
316
  | `target` | Active target for this Vite invocation. Use `wx` for WeChat Mini Program and `h5` for Web. |
335
317
  | `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. |
318
+ | `pages` | Ordered page list. The order becomes `app.json.pages` and the Web route order. |
337
319
  | `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`. |
320
+ | `pages[].config` | Page config merged into the generated WeChat page JSON and Web route config. |
321
+ | `appJson` | Base app config shared by both targets. The plugin overwrites the `pages` field from `options.pages`. |
340
322
  | `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
323
  | `sitemapJson` | WeChat `sitemap.json` content emitted for `wx` builds. It is required by the option type even when the current target is `h5`. |
342
324
 
343
- ## Styling
344
-
345
- You can use plain CSS, CSS modules, or Tailwind CSS v4.
346
-
347
- For Tailwind CSS v4, import Tailwind from a global CSS file such as `src/app.css`:
348
-
349
- ```css
350
- @import "tailwindcss/theme.css";
351
- @import "tailwindcss/preflight.css";
352
- @import "tailwindcss/utilities.css";
353
-
354
- @source "./";
355
- ```
356
-
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.
358
-
359
325
  ## Conditional compilation
360
326
 
361
327
  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`.
@@ -369,16 +335,14 @@ console.log('WeChat only')
369
335
  console.log('H5 only')
370
336
  // #endif
371
337
 
372
- // #if wx && !h5
373
- console.log('WeChat expression')
374
- // #elif h5
375
- console.log('H5 expression')
338
+ // #ifndef h5
339
+ console.log('Not H5')
376
340
  // #else
377
- console.log('fallback')
341
+ console.log('H5 fallback')
378
342
  // #endif
379
343
  ```
380
344
 
381
- Supported directives are `#ifdef`, `#ifndef`, `#if`, `#elif`, `#else`, and `#endif`. Conditions use the plugin target tokens `wx` and `h5`; `#if` expressions support `!`, `&&`, and `||`.
345
+ Supported directives are `#ifdef`, `#ifndef`, `#else`, and `#endif`. Conditions use the plugin target tokens `wx` and `h5`.
382
346
 
383
347
  ## Output by target
384
348
 
@@ -405,9 +369,9 @@ dist/wx/
405
369
 
406
370
  Open `dist/wx` with WeChat DevTools; do not open the source project directory.
407
371
 
408
- ### H5
372
+ ### H5 / Web
409
373
 
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`.
374
+ For `target: 'h5'`, the plugin injects a generated module into `index.html`, imports Taro H5 component styles before the app, 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`.
411
375
 
412
376
  ## Migrating from Taro
413
377
 
@@ -416,11 +380,13 @@ You can keep most React page components, business logic, assets, and styles, but
416
380
  Migration checklist:
417
381
 
418
382
  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.
383
+ 2. Move app config and page config into `vite.config.ts`. The plugin does not read Taro files such as `config/index.ts`, `app.config.ts`, or page `config.ts`.
420
384
  3. Register every page in `pages`. Each page path must match `src/${path}.tsx`.
421
385
  4. Replace Taro scripts with Vite scripts that set `VITE_PLUGIN_TARO_TARGET=wx` or `VITE_PLUGIN_TARO_TARGET=h5`.
422
386
  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.
387
+ 6. Move global styles to `src/app.css`, keep `import './app.css'` in the app entry, and add the Taro/Tailwind imports shown below.
388
+ 7. Remove all `@tarojs/*` packages from `dependencies` and `devDependencies`.
389
+ 8. Replace application imports from `@tarojs/*` with the plugin virtual modules.
424
390
 
425
391
  Before:
426
392
 
@@ -436,7 +402,17 @@ import Taro from 'virtual:taro/api'
436
402
  import { Text, View } from 'virtual:taro/components'
437
403
  ```
438
404
 
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.
405
+ Style migration:
406
+
407
+ ```css
408
+ @import "tailwindcss/theme.css";
409
+ @import "tailwindcss/preflight.css";
410
+ @import "tailwindcss/utilities.css";
411
+
412
+ @source "./";
413
+ ```
414
+
415
+ Remove all `@tarojs/*` packages and do not import them directly in application code. Let the plugin own Taro runtime resolution.
440
416
 
441
417
  ## Sample app
442
418
 
@@ -455,17 +431,17 @@ pnpm prepare:taro
455
431
  pnpm build:plugin
456
432
 
457
433
  # Run the sample app in WeChat
458
- pnpm dev:sample:wx
434
+ pnpm dev:loan-genius:wx
459
435
 
460
436
  # Build the sample app to WeChat output
461
- pnpm build:sample:wx
437
+ pnpm build:loan-genius:wx
462
438
 
463
439
  # Run the sample app in H5 dev mode
464
- pnpm dev:sample:h5
440
+ pnpm dev:loan-genius:h5
465
441
 
466
442
  # Build the sample app to H5 output and preview it
467
- pnpm build:sample:h5
468
- pnpm preview:sample:h5
443
+ pnpm build:loan-genius:h5
444
+ pnpm preview:loan-genius:h5
469
445
  ```
470
446
 
471
447
  Open `packages/loan-genius/dist/wx` with WeChat DevTools to test the Mini Program output.
@@ -488,11 +464,11 @@ Common scripts:
488
464
  | `pnpm typecheck` | Typecheck the plugin and sample app with `tsc`. |
489
465
  | `pnpm lint` | Run Biome checks. |
490
466
  | `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. |
467
+ | `pnpm dev:loan-genius:wx` | Start the WeChat Mini Program sample with hot reload. Build the plugin first. |
468
+ | `pnpm dev:loan-genius:h5` | Start the H5 sample app in Vite dev mode. Build the plugin first. |
469
+ | `pnpm build:loan-genius:wx` | Build the WeChat Mini Program sample to `packages/loan-genius/dist/wx`. |
470
+ | `pnpm build:loan-genius:h5` | Build the H5 sample app to `packages/loan-genius/dist/h5`. |
471
+ | `pnpm preview:loan-genius:h5` | Preview the built H5 sample. |
496
472
  | `pnpm changelog` | Regenerate `CHANGELOG.md` from git release tags. |
497
473
  | `pnpm publish:dry` | Dry-run package validation and publishing. |
498
474
  | `pnpm release <version\|bump>` | Validate, bump versions, update the changelog, create the release commit and tag, and push to trigger CI publishing. |
@@ -500,6 +476,7 @@ Common scripts:
500
476
 
501
477
  ## Limitations
502
478
 
479
+ - Only React apps are supported today.
503
480
  - Only `wx` and `h5` targets are generated today.
504
481
  - Application code must not import `@tarojs/*` packages directly.
505
482
 
@@ -513,8 +490,8 @@ Common scripts:
513
490
  | WeChat DevTools cannot open the app | Open the generated `dist/wx` folder and check `projectConfigJson.appid`. |
514
491
  | 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
492
  | 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. |
493
+ | Components render without expected styles on H5 | Ensure the app entry imports `./app.css` and the generated H5 entry is injected into `index.html`. |
494
+ | Tailwind classes do not appear | Ensure `src/app.css` imports Tailwind's CSS files, keeps `@source "./";`, and class names are statically discoverable. Restart the dev server after moving files. |
518
495
 
519
496
  ## Release workflow
520
497