vite-plugin-taro 0.5.10 → 0.5.12

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.en.md CHANGED
@@ -20,7 +20,7 @@ Continue with the [Quick Start guide](https://vpt.js.org/guides/quick-start/).
20
20
 
21
21
  ### React Hot Reload in WeChat DevTools
22
22
 
23
- <video src="https://github.com/user-attachments/assets/cd4e6d97-6bc7-40e0-9ba9-206c9fe369f1" controls autoplay muted loop playsinline width="100%"></video>
23
+ <video src="https://github.com/user-attachments/assets/cb93daf5-1827-496a-bb74-8397975accf6" controls autoplay muted loop playsinline width="100%"></video>
24
24
 
25
25
  - **Vite 8 + React 19** Build one codebase for WeChat Mini Program and Web with the Vite ecosystem.
26
26
  - **Hot reload** Preserve App data, the active page, React component state, and input state while editing.
package/README.md CHANGED
@@ -21,7 +21,7 @@ npm create vite-taro@latest my-app
21
21
 
22
22
  ### 已支持微信开发者工具的 React 热更新
23
23
 
24
- <video src="https://github.com/user-attachments/assets/cd4e6d97-6bc7-40e0-9ba9-206c9fe369f1" controls autoplay muted loop playsinline width="100%"></video>
24
+ <video src="https://github.com/user-attachments/assets/cb93daf5-1827-496a-bb74-8397975accf6" controls autoplay muted loop playsinline width="100%"></video>
25
25
 
26
26
  - **Vite 8 + React 19** 基于 Vite 生态,一份代码覆盖微信小程序与 Web。
27
27
  - **热更新** 编辑代码时保留 App 数据、当前页面、React 组件状态与输入状态。
@@ -185,11 +185,9 @@ async function publishBuildMetadata(server, buildId, port) {
185
185
  await writeHmrFile(server.config.build.outDir, hmrPatchesFileName, renderInitialHmrPatches());
186
186
  await writeHmrFile(server.config.build.outDir, hmrInfoFileName, renderHmrInfo(info));
187
187
  }
188
- /** Appends the physical project directory after Vite's normal server URLs. */
188
+ /** Replaces browser server URLs with the physical project directory consumed by WeChat DevTools. */
189
189
  function installDevToolsPrinter(server) {
190
- const originalPrintUrls = server.printUrls.bind(server);
191
190
  server.printUrls = () => {
192
- originalPrintUrls();
193
191
  server.config.logger.info(` ${colors.green('➜')} ${colors.bold('WeChat DevTools')}: ${colors.cyan(relativeToViteConfig(server.config.build.outDir, server.config.configFile, server.config.root))}`);
194
192
  };
195
193
  }
@@ -1,3 +1,4 @@
1
+ import path from 'node:path';
1
2
  import { getWxExecutionKind, isTransportModule } from '../module.js';
2
3
  import { createPlacementPlan, getSubpackageName, isGeneratedSubpackageFile, mainPackage } from './plan.js';
3
4
  /**
@@ -94,9 +95,9 @@ export function createPlacer() {
94
95
  if (location.kind === 'main') {
95
96
  return 'assets/[name]-[hash].js';
96
97
  }
97
- // The containing subpackage already supplies a stable identity. Do not leak the Rolldown group name
98
- // into every physical chunk filename; content identity alone is sufficient beneath that root.
99
- return `${location.root}/assets/[hash].js`;
98
+ // The package group replaces Rolldown's [name], so recover the first bundled source file's name from
99
+ // the final chunk module list instead of leaking the generated package hash into the filename.
100
+ return `${location.root}/assets/${getFirstModuleName(chunk)}-[hash].js`;
100
101
  },
101
102
  // Keep generic assets independent of native output identities assigned after bundling.
102
103
  assetFileNames: 'assets/[name]-[hash][extname]'
@@ -138,6 +139,19 @@ export function createPlacer() {
138
139
  }
139
140
  };
140
141
  }
142
+ /** Uses the first bundled source filename as the readable identity of a generated subpackage chunk. */
143
+ function getFirstModuleName(chunk) {
144
+ const firstModuleId = chunk.moduleIds[0];
145
+ if (!firstModuleId) {
146
+ throw new Error('wx subpackage chunk has no source modules');
147
+ }
148
+ const normalizedId = firstModuleId.replaceAll('\\', '/');
149
+ const suffixIndex = normalizedId.search(/[?#]/);
150
+ const cleanId = suffixIndex === -1 ? normalizedId : normalizedId.slice(0, suffixIndex);
151
+ const fileName = path.posix.basename(cleanId);
152
+ const extension = path.posix.extname(fileName);
153
+ return extension ? fileName.slice(0, -extension.length) : fileName;
154
+ }
141
155
  /** Compares main by discriminant and generated subpackages by their unique physical root. */
142
156
  function hasSameLocation(left, right) {
143
157
  return left.kind === 'main' ? right.kind === 'main' : right.kind === 'subpackage' && left.root === right.root;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite-plugin-taro",
3
- "version": "0.5.10",
3
+ "version": "0.5.12",
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",
@@ -75,8 +75,8 @@
75
75
  "rolldown": "1.2.3",
76
76
  "tailwindcss": "^4.3.3",
77
77
  "weapp-tailwindcss": "^5.2.11",
78
- "@tarojs/react": "npm:vite-plugin-taro-react@0.5.10",
79
- "@tarojs/plugin-framework-react": "npm:vite-plugin-taro-plugin-framework-react@0.5.10"
78
+ "@tarojs/plugin-framework-react": "npm:vite-plugin-taro-plugin-framework-react@0.5.12",
79
+ "@tarojs/react": "npm:vite-plugin-taro-react@0.5.12"
80
80
  },
81
81
  "peerDependencies": {
82
82
  "react": "^19.0.0",
@@ -256,11 +256,9 @@ async function publishBuildMetadata(server: ViteDevServer, buildId: string, port
256
256
  await writeHmrFile(server.config.build.outDir, hmrInfoFileName, renderHmrInfo(info))
257
257
  }
258
258
 
259
- /** Appends the physical project directory after Vite's normal server URLs. */
259
+ /** Replaces browser server URLs with the physical project directory consumed by WeChat DevTools. */
260
260
  function installDevToolsPrinter(server: ViteDevServer): void {
261
- const originalPrintUrls = server.printUrls.bind(server)
262
261
  server.printUrls = () => {
263
- originalPrintUrls()
264
262
  server.config.logger.info(
265
263
  ` ${colors.green('➜')} ${colors.bold('WeChat DevTools')}: ${colors.cyan(relativeToViteConfig(server.config.build.outDir, server.config.configFile, server.config.root))}`
266
264
  )
@@ -1,3 +1,4 @@
1
+ import path from 'node:path'
1
2
  import type { Rolldown } from 'vite'
2
3
  import { getWxExecutionKind, isTransportModule } from '../module.ts'
3
4
  import {
@@ -117,9 +118,9 @@ export function createPlacer() {
117
118
  if (location.kind === 'main') {
118
119
  return 'assets/[name]-[hash].js'
119
120
  }
120
- // The containing subpackage already supplies a stable identity. Do not leak the Rolldown group name
121
- // into every physical chunk filename; content identity alone is sufficient beneath that root.
122
- return `${location.root}/assets/[hash].js`
121
+ // The package group replaces Rolldown's [name], so recover the first bundled source file's name from
122
+ // the final chunk module list instead of leaking the generated package hash into the filename.
123
+ return `${location.root}/assets/${getFirstModuleName(chunk)}-[hash].js`
123
124
  },
124
125
  // Keep generic assets independent of native output identities assigned after bundling.
125
126
  assetFileNames: 'assets/[name]-[hash][extname]'
@@ -165,6 +166,21 @@ export function createPlacer() {
165
166
  }
166
167
  }
167
168
 
169
+ /** Uses the first bundled source filename as the readable identity of a generated subpackage chunk. */
170
+ function getFirstModuleName(chunk: Rolldown.PreRenderedChunk): string {
171
+ const firstModuleId = chunk.moduleIds[0]
172
+ if (!firstModuleId) {
173
+ throw new Error('wx subpackage chunk has no source modules')
174
+ }
175
+
176
+ const normalizedId = firstModuleId.replaceAll('\\', '/')
177
+ const suffixIndex = normalizedId.search(/[?#]/)
178
+ const cleanId = suffixIndex === -1 ? normalizedId : normalizedId.slice(0, suffixIndex)
179
+ const fileName = path.posix.basename(cleanId)
180
+ const extension = path.posix.extname(fileName)
181
+ return extension ? fileName.slice(0, -extension.length) : fileName
182
+ }
183
+
168
184
  /** Compares main by discriminant and generated subpackages by their unique physical root. */
169
185
  function hasSameLocation(left: PackageLocation, right: PackageLocation): boolean {
170
186
  return left.kind === 'main' ? right.kind === 'main' : right.kind === 'subpackage' && left.root === right.root