create-vite-taro 0.6.3 → 0.6.6
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/package.json
CHANGED
|
@@ -1,56 +1,113 @@
|
|
|
1
1
|
# Vite Taro App
|
|
2
2
|
|
|
3
|
-
Vite 8
|
|
3
|
+
A cross-platform app built with [Vite 8](https://vite.dev), React 19, Taro 4, TypeScript, and Tailwind CSS v4. The same React codebase runs as a WeChat Mini Program and a Web app.
|
|
4
4
|
|
|
5
|
-
Documentation
|
|
5
|
+
- [Documentation](https://vpt.js.org)
|
|
6
|
+
- [GitHub](https://github.com/sep2/vite-plugin-taro)
|
|
6
7
|
|
|
7
|
-
|
|
8
|
+
## Get started
|
|
8
9
|
|
|
9
|
-
|
|
10
|
+
Install the dependencies:
|
|
10
11
|
|
|
11
12
|
```sh
|
|
12
|
-
# Install dependencies after scaffolding
|
|
13
13
|
npm install
|
|
14
|
+
```
|
|
14
15
|
|
|
15
|
-
|
|
16
|
-
npm run dev:wx
|
|
16
|
+
### Web
|
|
17
17
|
|
|
18
|
-
|
|
18
|
+
```sh
|
|
19
19
|
npm run dev:h5
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
Open the URL printed by Vite, usually <http://localhost:5173>.
|
|
23
|
+
|
|
24
|
+
### WeChat Mini Program
|
|
25
|
+
|
|
26
|
+
1. Replace the generated placeholder in `.env.local` with your WeChat App ID:
|
|
27
|
+
|
|
28
|
+
```dotenv
|
|
29
|
+
VITE_VPT_WECHAT_APP_ID=wx1234567890abcdef
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
2. Start the WeChat development build:
|
|
33
|
+
|
|
34
|
+
```sh
|
|
35
|
+
npm run dev:wx
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
3. In WeChat DevTools, import `dist/wx`—not the project root.
|
|
39
|
+
|
|
40
|
+
Keep the Vite process running while you work. The template configures WeChat DevTools for hot reload, disables URL checks for local development, and keeps Skyline rendering disabled in DevTools because Skyline does not currently support hot reload there.
|
|
41
|
+
|
|
42
|
+
You can run `dev:wx` and `dev:h5` in separate terminals to develop both targets at once.
|
|
20
43
|
|
|
21
|
-
|
|
22
|
-
|
|
44
|
+
## Start building
|
|
45
|
+
|
|
46
|
+
The default page is `src/pages/home/index.tsx`. Edit it while the counter is active to see React state survive a hot update.
|
|
47
|
+
|
|
48
|
+
Use VPT's virtual modules for Taro components and APIs:
|
|
49
|
+
|
|
50
|
+
```tsx
|
|
51
|
+
import Taro from 'virtual:taro/api'
|
|
52
|
+
import { Button, Text, View } from 'virtual:taro/components'
|
|
23
53
|
```
|
|
24
54
|
|
|
25
|
-
|
|
55
|
+
Do not install or import `@tarojs/*` packages directly. Add pages and change application or WeChat project settings in `vite.config.ts`.
|
|
56
|
+
|
|
57
|
+
The starter also demonstrates:
|
|
58
|
+
|
|
59
|
+
- shared React components across WeChat and Web;
|
|
60
|
+
- target-specific code with `// #ifdef wx` and `// #ifdef h5`;
|
|
61
|
+
- a typed native WeChat component with a Web counterpart;
|
|
62
|
+
- lazy-loaded React components;
|
|
63
|
+
- a custom navigation bar; and
|
|
64
|
+
- Tailwind CSS, CSS Modules, and global CSS.
|
|
65
|
+
|
|
66
|
+
Delete or replace any example code you do not need.
|
|
26
67
|
|
|
27
|
-
|
|
28
|
-
for Mini Program development. State-preserving hot reload requires `compileHotReLoad: true`; the generated project sets
|
|
29
|
-
it automatically and also disables Skyline rendering and URL checks by default.
|
|
68
|
+
## Styling
|
|
30
69
|
|
|
31
|
-
|
|
70
|
+
Global styles and Tailwind theme tokens live in `src/app.css`. Keep the Tailwind imports and `@source "./";` directive so classes used under `src` are discovered for both targets.
|
|
32
71
|
|
|
33
|
-
|
|
34
|
-
for both targets. Taro H5 component styles are injected by the plugin.
|
|
72
|
+
Use complete Tailwind class names in source code instead of constructing them from string fragments. For isolated component styles, create a `*.module.css` file and import it from the component.
|
|
35
73
|
|
|
36
|
-
For WeChat,
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
74
|
+
VPT hot-updates imported styles in both targets. For WeChat, it publishes generated WXSS together with the component update so the current page and React state remain intact.
|
|
75
|
+
|
|
76
|
+
## Hot reload
|
|
77
|
+
|
|
78
|
+
During normal WeChat updates, VPT preserves the running App, current page, compatible React Hook state, and native input values. A full reload is expected after changes to Vite configuration, incompatible component or Hook structure, or an update that cannot be applied safely.
|
|
79
|
+
|
|
80
|
+
See the [hot reload guide](https://vpt.js.org/guides/hot-module-replacement/) for configuration and troubleshooting details.
|
|
40
81
|
|
|
41
82
|
## Scripts
|
|
42
83
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
npm run dev:
|
|
46
|
-
npm run
|
|
47
|
-
npm run build:
|
|
48
|
-
npm run
|
|
49
|
-
npm run
|
|
84
|
+
| Command | Description | Output |
|
|
85
|
+
| --- | --- | --- |
|
|
86
|
+
| `npm run dev:wx` | Develop the WeChat Mini Program with hot reload | `dist/wx` |
|
|
87
|
+
| `npm run dev:h5` | Start the Web development server | — |
|
|
88
|
+
| `npm run build:wx` | Build the WeChat Mini Program | `dist/wx` |
|
|
89
|
+
| `npm run build:h5` | Build the Web app | `dist/h5` |
|
|
90
|
+
| `npm run preview:h5` | Preview the Web production build | — |
|
|
91
|
+
| `npm run typecheck` | Typecheck the project with TypeScript | — |
|
|
92
|
+
|
|
93
|
+
## Project structure
|
|
94
|
+
|
|
95
|
+
```text
|
|
96
|
+
.
|
|
97
|
+
├── .env.local # Local WeChat App ID (ignored by Git)
|
|
98
|
+
├── vite.config.ts # VPT, pages, and target configuration
|
|
99
|
+
└── src/
|
|
100
|
+
├── app.tsx # Shared application entry
|
|
101
|
+
├── app.css # Global styles and Tailwind theme
|
|
102
|
+
├── components/ # Shared and target-specific components
|
|
103
|
+
└── pages/home/index.tsx # Default page
|
|
50
104
|
```
|
|
51
105
|
|
|
52
106
|
## Troubleshooting
|
|
53
107
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
108
|
+
- **WeChat DevTools cannot open the app:** import `dist/wx` and verify that `.env.local` contains an App ID available to your WeChat account.
|
|
109
|
+
- **Changes do not appear in WeChat:** confirm `dev:wx` is still running, DevTools has the current `dist/wx` open, and the terminal has no build errors.
|
|
110
|
+
- **Tailwind classes are missing:** keep `@source "./";` in `src/app.css` and write each possible class name as a complete string.
|
|
111
|
+
- **pnpm reports ignored dependency build scripts:** run `pnpm approve-builds`, approve the requested scripts, and install again.
|
|
112
|
+
|
|
113
|
+
Continue with the [quick start guide](https://vpt.js.org/guides/quick-start/) or browse the [complete documentation](https://vpt.js.org).
|