vite-plugin-taro 0.7.0 → 0.7.1-beta.2

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.
@@ -1,6 +1,11 @@
1
- import { type Plugin } from 'vite';
1
+ import type { Plugin } from 'vite';
2
2
  import type { VptTarget } from '../../../options.ts';
3
- /** Public facade used by transformed application API imports. */
3
+ /** Public application facade: H5's static ESM namespace or Mini's shared Taro object. */
4
4
  export declare const clientTaroApiId = "virtual:taro/api";
5
- /** Creates the shared Taro facade backed by the selected target's API implementation. */
5
+ /**
6
+ * Resolves application imports without transforming either the facade or its consumers. Each physical facade imports its
7
+ * canonical backend directly, so upstream @tarojs/taro requests cannot recurse into the generic Mini implementation on H5.
8
+ * H5's optimizer separately resolves dependency-internal Taro requests to the backend, keeping framework initialization out
9
+ * of the components → APIs → components cycle. The public namespace shares those same API functions and state objects.
10
+ */
6
11
  export declare function createClientTaroPlugin(target: VptTarget): Plugin;
@@ -2,20 +2,5 @@ import type { PluginOption } from 'vite';
2
2
  import type { VptOptions } from '../../../options.ts';
3
3
  /** Creates the plugins that own the H5 target. */
4
4
  export declare function createH5TargetPlugins(options: VptOptions): PluginOption[];
5
- /**
6
- * Coarse source prefilter for the upstream Taro API transform.
7
- *
8
- * The plugin has two independent responsibilities: adapting imports from the compiler facade and normalizing camel-case
9
- * H5 ARIA attributes. Matching `aria` followed by any uppercase letter is intentionally broader than Taro's current
10
- * attribute table. A duplicated exact list would silently stop routing files through Babel when upstream adds another
11
- * attribute, while a broad false positive costs only one unnecessary transform. Ordinary application modules match
12
- * neither branch and remain entirely outside Babel's parser and generator.
13
- */
14
- export declare const h5TaroApiTransformCodeFilter: RegExp;
15
- /** Babel preset body shared by Rolldown's filtered adapter and direct semantic tests. */
16
- export declare function h5TaroApiPreset(): {
17
- plugins: [string, {
18
- packageName: string;
19
- definition: any;
20
- }][];
21
- };
5
+ /** Resolves only the Taro request that must remain within optimized component chunks. */
6
+ export declare function resolveH5OptimizerTaro(id: string): string | undefined;
@@ -1,4 +1,11 @@
1
1
  import { type Plugin } from 'vite';
2
+ /**
3
+ * Creates the serve-only Oxc substitution for React's free DevTools-hook references.
4
+ *
5
+ * Bundled Vite folds `define` into its existing native Oxc transform. Oxc rewrites only free references, preserving explicit
6
+ * members, property keys, string contents, and shadowed bindings without an all-module plugin filter or a second AST parse.
7
+ */
8
+ export declare function createMiniReactRefreshDefines(isDevelopment: boolean): Record<string, string>;
2
9
  /**
3
10
  * Creates the serve-only React Refresh adaptation transforms for a Mini Program target.
4
11
  *
@@ -9,16 +16,22 @@ import { type Plugin } from 'vite';
9
16
  * and injects its renderer hook at module evaluation, replacing the missing HTML preamble.
10
17
  * - React Reconciler is selected by exact physical ID. Its renderer injection receives a static dependency on the refresh
11
18
  * runtime, so hook installation cannot race renderer initialization during cold startup.
12
- * - React-family modules are selected by the reserved free DevTools-hook identifier. Their expression references are rewritten
13
- * as explicit `globalThis` members; an AST visitor edits only those identifier ranges after the filter admits the module.
14
- * - Refresh boundaries are selected by Vite's generated `$RefreshReg$` guard. The AST transform removes only that web-preamble
15
- * assertion because each boundary already owns local wrappers over the imported refresh runtime.
16
19
  *
17
- * These adaptations deliberately remain serve-only plugin transforms rather than target-wide `define` entries. That scope
18
- * prevents development protocol behavior from leaking into production or unrelated Mini Program modules. Plugin order also
19
- * matters: Reconciler receives its static refresh dependency before the later DevTools-hook transform lowers its free references.
20
+ * These adaptations deliberately remain serve-only plugin transforms rather than target-wide production behavior. Reconciler's
21
+ * static refresh dependency establishes hook installation order. The Mini config lowers React's free DevTools-hook protocol with
22
+ * a serve-only native Oxc define. A filtered post-transform removes the browser-preamble assertion before both complete chunk
23
+ * rendering and incremental factory generation. Removing it only during renderChunk leaves HMR patches unadapted.
20
24
  */
21
25
  export declare function createMiniReactRefreshTransforms(): Plugin[];
26
+ /**
27
+ * Removes only the generated browser assertion at the shared module-transform boundary.
28
+ * The native hook filter avoids parsing nonmatching modules. Matching modules cost O(n) time and memory; unchanged modules
29
+ * reuse the bundler's transform cache. Refresh registration and unrelated window expressions remain untouched.
30
+ */
31
+ export declare function removeRefreshPreambleGuard({ code, id }: {
32
+ code: string;
33
+ id: string;
34
+ }): import("../../../utils/transform.ts").AstTransformResult;
22
35
  /** Makes renderer hook injection statically depend on the refresh runtime. */
23
36
  export declare function injectReactRefreshRendererDependency(code: string): {
24
37
  code: string;
@@ -28,11 +41,3 @@ export declare function transformRefreshRuntime({ code, id }: {
28
41
  code: string;
29
42
  id: string;
30
43
  }): import("../../../utils/transform.ts").AstTransformResult;
31
- export declare function transformReactDevtoolsHook({ code, id }: {
32
- code: string;
33
- id: string;
34
- }): import("../../../utils/transform.ts").AstTransformResult;
35
- export declare function removeRefreshPreambleGuard({ code, id }: {
36
- code: string;
37
- id: string;
38
- }): import("../../../utils/transform.ts").AstTransformResult;
@@ -0,0 +1,3 @@
1
+ import { UnRecursiveTemplate } from '@tarojs/shared/dist/template.js';
2
+ /** Creates the Taro 4.2.1 WX template implementation without loading its CLI platform package. */
3
+ export declare function createWxTemplate(): UnRecursiveTemplate;
@@ -0,0 +1,3 @@
1
+ import { RecursiveTemplate } from '@tarojs/shared/dist/template.js';
2
+ /** Creates the Taro 4.2.1 Alipay template implementation without loading its CLI platform package. */
3
+ export declare function createZfbTemplate(): RecursiveTemplate;
@@ -0,0 +1,9 @@
1
+ type MergeRecord = Record<string, unknown>;
2
+ /**
3
+ * Recursively merges sources into the retained target used by Taro's template generator.
4
+ *
5
+ * The target and its existing nested records are intentionally mutated because Taro retains their references. Matching arrays
6
+ * are concatenated, matching records are merged recursively, and all other source values replace their target values.
7
+ */
8
+ export declare function recursiveMerge<T extends MergeRecord>(target: T, ...sources: ReadonlyArray<MergeRecord | undefined>): T;
9
+ export {};
@@ -0,0 +1,3 @@
1
+ /** Verifies that Vite uses the versions pinned by VPT. */
2
+ export declare function assertRuntimeVersions(): void;
3
+ export declare function assertRuntimeVersionValues(actualViteVersion: string, actualRolldownVersion: string): void;
@@ -1,3 +1,4 @@
1
- import taro from '@tarojs/taro';
2
- export * from '@tarojs/taro';
1
+ import taro from 'vite-plugin-taro-runtime/taro';
2
+ export * from 'vite-plugin-taro-runtime/taro';
3
+ export * from './framework-apis.ts';
3
4
  export default taro;
@@ -1,10 +1,11 @@
1
- /*
2
- * This physical module is the shared facade, not the generic Taro implementation. Its own `@tarojs/taro` request is
3
- * resolved by the client plugin to the selected platform APIs, while application requests resolve back to this facade.
4
- * React's API loader then extends this same object with framework lifecycle hooks.
1
+ import taro from 'vite-plugin-taro-runtime/taro';
2
+ import * as frameworkApis from './framework-apis.js';
3
+ /**
4
+ * Mini keeps Taro's shared mutable API object and bulk native initialization. This assignment preserves the upstream API
5
+ * loader's behavior after both dependencies have evaluated, regardless of when the framework's native hook was registered.
5
6
  */
6
- import taro from '@tarojs/taro';
7
- // Re-export platform APIs while preserving object identity for the framework loader's lifecycle assignments.
8
- // @ts-expect-error @tarojs/taro uses export= types while Rolldown exposes its runtime properties as named exports.
9
- export * from '@tarojs/taro';
7
+ Object.assign(taro, frameworkApis);
8
+ // @ts-expect-error Taro uses export= types; Rolldown exposes the CommonJS runtime properties as named exports.
9
+ export * from 'vite-plugin-taro-runtime/taro';
10
+ export * from './framework-apis.js';
10
11
  export default taro;
@@ -1 +1 @@
1
- export * from '@tarojs/components';
1
+ export * from 'vite-plugin-taro-runtime/components';
@@ -1 +1,2 @@
1
- export * from '@tarojs/components';
1
+ // The compiler maps this typed component slot to the active H5 or Mini implementation.
2
+ export * from 'vite-plugin-taro-runtime/components';
@@ -0,0 +1,2 @@
1
+ /** Lifecycle exports used by the H5 namespace and attached to the shared Taro object by the Mini facade. */
2
+ export { useAddToFavorites, useDidHide, useDidShow, useError, useKeyboardHeight, useLaunch, useLoad, useOptionMenuClick, usePageNotFound, usePageScroll, usePullDownRefresh, usePullIntercept, useReachBottom, useReady, useResize, useRouter, useSaveExitState, useScope, useShareAppMessage, useShareTimeline, useTabItemTap, useTitleClick, useUnhandledRejection, useUnload } from 'vite-plugin-taro-runtime/plugin-framework-react/runtime';
@@ -0,0 +1,2 @@
1
+ /** Lifecycle exports used by the H5 namespace and attached to the shared Taro object by the Mini facade. */
2
+ export { useAddToFavorites, useDidHide, useDidShow, useError, useKeyboardHeight, useLaunch, useLoad, useOptionMenuClick, usePageNotFound, usePageScroll, usePullDownRefresh, usePullIntercept, useReachBottom, useReady, useResize, useRouter, useSaveExitState, useScope, useShareAppMessage, useShareTimeline, useTabItemTap, useTitleClick, useUnhandledRejection, useUnload } from 'vite-plugin-taro-runtime/plugin-framework-react/runtime';
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Keep platform APIs and React hooks as static bindings. Importing the upstream default object or assigning hooks onto it
3
+ * would make the application facade escape into a mutable object and retain otherwise unused APIs.
4
+ */
5
+ export * from 'vite-plugin-taro-runtime/plugin-platform-h5/runtime/apis';
6
+ export * from '../client/taro/framework-apis.ts';
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Keep platform APIs and React hooks as static bindings. Importing the upstream default object or assigning hooks onto it
3
+ * would make the application facade escape into a mutable object and retain otherwise unused APIs.
4
+ */
5
+ export * from 'vite-plugin-taro-runtime/plugin-platform-h5/runtime/apis';
6
+ export * from '../client/taro/framework-apis.js';
@@ -0,0 +1,7 @@
1
+ /**
2
+ * The default export is an ESM namespace, not an assembled API object. Rolldown resolves static member reads directly to
3
+ * exports, so Taro.showToast(), Taro['showToast'](), and named imports all tree-shake without an application transform.
4
+ * The namespace is read-only; shared mutable runtime state remains inside exported objects such as options and eventCenter.
5
+ */
6
+ export * from './taro-api-exports.ts';
7
+ export * as default from './taro-api-exports.ts';
@@ -0,0 +1,7 @@
1
+ /**
2
+ * The default export is an ESM namespace, not an assembled API object. Rolldown resolves static member reads directly to
3
+ * exports, so Taro.showToast(), Taro['showToast'](), and named imports all tree-shake without an application transform.
4
+ * The namespace is read-only; shared mutable runtime state remains inside exported objects such as options and eventCenter.
5
+ */
6
+ export * from './taro-api-exports.js';
7
+ export * as default from './taro-api-exports.js';
@@ -1,6 +1,7 @@
1
+ /** biome-ignore-all assist/source/organizeImports: keep runtime side effect order */
1
2
  /** Runtime exports consumed by the generated H5 entry. */
2
- import '@tarojs/components/global.css';
3
- import '@tarojs/components/dist/taro-components/taro-components.css';
4
- export { createReactApp } from '@tarojs/plugin-framework-react/dist/runtime';
5
- export { createHashHistory, createRouter, handleAppMount } from '@tarojs/router';
6
- export { window } from '@tarojs/runtime';
3
+ import 'vite-plugin-taro-runtime/components/global.css';
4
+ import 'vite-plugin-taro-runtime/components/dist/taro-components/taro-components.css';
5
+ export { createReactApp } from 'vite-plugin-taro-runtime/plugin-framework-react/runtime';
6
+ export { createHashHistory, createRouter, handleAppMount } from 'vite-plugin-taro-runtime/router';
7
+ export { window } from 'vite-plugin-taro-runtime/runtime/h5';
@@ -1,6 +1,7 @@
1
+ /** biome-ignore-all assist/source/organizeImports: keep runtime side effect order */
1
2
  /** Runtime exports consumed by the generated H5 entry. */
2
- import '@tarojs/components/global.css';
3
- import '@tarojs/components/dist/taro-components/taro-components.css';
4
- export { createReactApp } from '@tarojs/plugin-framework-react/dist/runtime';
5
- export { createHashHistory, createRouter, handleAppMount } from '@tarojs/router';
6
- export { window } from '@tarojs/runtime';
3
+ import 'vite-plugin-taro-runtime/components/global.css';
4
+ import 'vite-plugin-taro-runtime/components/dist/taro-components/taro-components.css';
5
+ export { createReactApp } from 'vite-plugin-taro-runtime/plugin-framework-react/runtime';
6
+ export { createHashHistory, createRouter, handleAppMount } from 'vite-plugin-taro-runtime/router';
7
+ export { window } from 'vite-plugin-taro-runtime/runtime/h5';
@@ -1,3 +1,3 @@
1
1
  import './app.ts';
2
- declare const config: import("@tarojs/runtime").PageInstance;
2
+ declare const config: import("vite-plugin-taro-runtime/runtime/mini").PageInstance;
3
3
  export default config;
@@ -1,6 +1,6 @@
1
1
  /** biome-ignore-all assist/source/organizeImports: keep side effect order */
2
2
  /** Taro runtime exports shared by the App, Page, and generated recursive component capsules. */
3
3
  import '\0vpt:taro-platform-runtime';
4
- export { createReactApp } from '@tarojs/plugin-framework-react/dist/runtime';
5
- export { default as ReactDOM } from '@tarojs/react';
6
- export { createPageConfig, createRecursiveComponentConfig } from '@tarojs/runtime';
4
+ export { createReactApp } from 'vite-plugin-taro-runtime/plugin-framework-react/runtime';
5
+ export { default as ReactDOM } from 'vite-plugin-taro-runtime/react';
6
+ export { createPageConfig, createRecursiveComponentConfig } from 'vite-plugin-taro-runtime/runtime/mini';
@@ -2,10 +2,10 @@
2
2
  /** Taro runtime exports shared by the App, Page, and generated recursive component capsules. */
3
3
  // @ts-expect-error: The active Mini contract resolves its Taro platform initialization module.
4
4
  import '\0vpt:taro-platform-runtime';
5
- export { createReactApp } from '@tarojs/plugin-framework-react/dist/runtime';
6
- export { default as ReactDOM } from '@tarojs/react';
7
- export { createPageConfig, createRecursiveComponentConfig } from '@tarojs/runtime';
8
- import { customWrapperCache } from '@tarojs/runtime';
5
+ export { createReactApp } from 'vite-plugin-taro-runtime/plugin-framework-react/runtime';
6
+ export { default as ReactDOM } from 'vite-plugin-taro-runtime/react';
7
+ export { createPageConfig, createRecursiveComponentConfig } from 'vite-plugin-taro-runtime/runtime/mini';
8
+ import { customWrapperCache } from 'vite-plugin-taro-runtime/runtime/mini';
9
9
  // DevTools HMR runs in the bootstrap chunk, so publish the application graph's cache once on the language global.
10
10
  if (process.env.NODE_ENV === 'development') {
11
11
  Reflect.set(globalThis, Symbol.for('customWrapperCache'), customWrapperCache);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite-plugin-taro",
3
- "version": "0.7.0",
3
+ "version": "0.7.1-beta.2",
4
4
  "author": "sep2",
5
5
  "description": "Vite 8 plugin for building one React/Taro codebase for WeChat, Alipay, and H5 targets.",
6
6
  "type": "module",
@@ -57,21 +57,13 @@
57
57
  "@tailwindcss/node": "4.3.3",
58
58
  "@tailwindcss/oxide": "4.3.3",
59
59
  "@tailwindcss/vite": "4.3.3",
60
- "@tarojs/components": "4.2.1",
61
- "@tarojs/helper": "4.2.1",
62
- "@tarojs/plugin-framework-react": "npm:vite-plugin-taro-plugin-framework-react@0.7.0",
63
- "@tarojs/plugin-platform-alipay": "4.2.1",
64
- "@tarojs/plugin-platform-h5": "4.2.1",
65
- "@tarojs/plugin-platform-weapp": "4.2.1",
66
- "@tarojs/react": "npm:vite-plugin-taro-react@0.7.0",
67
- "@tarojs/router": "4.2.1",
68
- "@tarojs/runtime": "npm:vite-plugin-taro-runtime@0.7.0",
69
- "@tarojs/taro": "4.2.1",
60
+ "@tarojs/shared": "4.2.1",
70
61
  "@vitejs/plugin-react": "^6.1.1",
71
62
  "react-reconciler": "0.33.0",
72
63
  "rolldown": "1.2.7",
73
64
  "sval": "0.6.12",
74
- "tailwindcss": "^4.3.3"
65
+ "tailwindcss": "^4.3.3",
66
+ "vite-plugin-taro-runtime": "0.7.1-beta.2"
75
67
  },
76
68
  "peerDependencies": {
77
69
  "react": "^19.0.0",
@@ -86,7 +78,6 @@
86
78
  "@babel/plugin-transform-modules-systemjs": "^8.0.1",
87
79
  "@babel/types": "^8.0.4",
88
80
  "@oxc-project/types": "0.148.0",
89
- "@rolldown/plugin-babel": "^0.2.3",
90
81
  "@tailwindcss-mangle/engine": "0.2.0",
91
82
  "@types/node": "^26.3.0",
92
83
  "@types/react": "^19.2.18",
@@ -1,5 +0,0 @@
1
- /**
2
- * Applies Taro React's standard source-to-source API loader. It imports the framework lifecycle hooks, assigns them to
3
- * the facade's `taro` object, and emits matching named exports; keeping the hook inventory owned by Taro avoids drift.
4
- */
5
- export declare function injectTaroFrameworkApis(source: string): string;