vite-plugin-taro 0.5.16 → 0.6.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.
Files changed (56) hide show
  1. package/dist/node/plugins/client/client-taro.d.ts +2 -2
  2. package/dist/node/plugins/conditional/conditional-directives.d.ts +2 -2
  3. package/dist/node/plugins/h5/plugins.d.ts +2 -2
  4. package/dist/node/plugins/h5/resolver/module-resolver.d.ts +2 -2
  5. package/dist/node/plugins/h5/transform-app.d.ts +2 -2
  6. package/dist/node/plugins/h5/transform-app.js +2 -2
  7. package/dist/node/plugins/wx/dev/dev-host.d.ts +2 -2
  8. package/dist/node/plugins/wx/dev/plugins.d.ts +2 -2
  9. package/dist/node/plugins/wx/dev/wx-dev-options.d.ts +2 -2
  10. package/dist/node/plugins/wx/output/files.d.ts +2 -2
  11. package/dist/node/plugins/wx/output/json.d.ts +3 -3
  12. package/dist/node/plugins/wx/output/json.js +1 -1
  13. package/dist/node/plugins/wx/output/templates.d.ts +2 -2
  14. package/dist/node/plugins/wx/plugins.d.ts +2 -2
  15. package/dist/node/plugins/wx/render/transport.js +1 -1
  16. package/dist/node/plugins/wx/resolve/resolver.d.ts +2 -2
  17. package/dist/node/plugins/wx/resolve/specialize-bootstrap.d.ts +2 -2
  18. package/dist/node/plugins/wx/resolve/specialize-bootstrap.js +1 -1
  19. package/dist/node/plugins/wx/resolve/specialize-page-capsule.d.ts +2 -2
  20. package/dist/node/plugins/wx/resolve/specialize-page-capsule.js +2 -2
  21. package/dist/node/utils/project-config.d.ts +2 -2
  22. package/dist/node/vpt.d.ts +4 -0
  23. package/dist/node/{vite-plugin.js → vpt.js} +1 -1
  24. package/dist/options.d.ts +65 -13
  25. package/dist/runtime/h5/app.js +2 -2
  26. package/dist/runtime/wx/amphibious/bootstrap.js +1 -1
  27. package/dist/runtime/wx/amphibious/transport.js +1 -1
  28. package/dist/runtime/wx/capsule/page.js +1 -1
  29. package/dist/vite.d.ts +2 -2
  30. package/dist/vite.js +1 -1
  31. package/package.json +3 -3
  32. package/src/node/plugins/client/client-taro.ts +3 -3
  33. package/src/node/plugins/conditional/conditional-directives.ts +3 -3
  34. package/src/node/plugins/h5/plugins.ts +3 -3
  35. package/src/node/plugins/h5/resolver/module-resolver.ts +2 -2
  36. package/src/node/plugins/h5/transform-app.ts +5 -5
  37. package/src/node/plugins/wx/dev/dev-host.ts +2 -2
  38. package/src/node/plugins/wx/dev/plugins.ts +2 -5
  39. package/src/node/plugins/wx/dev/wx-dev-options.ts +2 -2
  40. package/src/node/plugins/wx/output/files.ts +2 -2
  41. package/src/node/plugins/wx/output/json.ts +8 -8
  42. package/src/node/plugins/wx/output/templates.ts +3 -3
  43. package/src/node/plugins/wx/plugins.ts +3 -3
  44. package/src/node/plugins/wx/render/transport.ts +1 -1
  45. package/src/node/plugins/wx/resolve/resolver.ts +5 -5
  46. package/src/node/plugins/wx/resolve/specialize-bootstrap.ts +3 -3
  47. package/src/node/plugins/wx/resolve/specialize-page-capsule.ts +4 -4
  48. package/src/node/utils/project-config.ts +2 -2
  49. package/src/node/{vite-plugin.ts → vpt.ts} +2 -2
  50. package/src/options.ts +71 -13
  51. package/src/runtime/h5/app.ts +4 -4
  52. package/src/runtime/wx/amphibious/bootstrap.ts +2 -2
  53. package/src/runtime/wx/amphibious/transport.ts +2 -4
  54. package/src/runtime/wx/capsule/page.ts +3 -8
  55. package/src/vite.ts +2 -2
  56. package/dist/node/vite-plugin.d.ts +0 -4
@@ -1,6 +1,6 @@
1
1
  import { type Plugin } from 'vite';
2
- import type { VitePluginTaroTarget } from '../../../options.ts';
2
+ import type { VptTarget } from '../../../options.ts';
3
3
  /** Public facade used by transformed application API imports. */
4
4
  export declare const clientTaroApiId = "virtual:taro/api";
5
5
  /** Creates the shared Taro facade backed by the selected target's API implementation. */
6
- export declare function createClientTaroPlugin(target: VitePluginTaroTarget): Plugin;
6
+ export declare function createClientTaroPlugin(target: VptTarget): Plugin;
@@ -1,4 +1,4 @@
1
1
  import type { Plugin } from 'vite';
2
- import type { VitePluginTaroTarget } from '../../../options.ts';
2
+ import type { VptTarget } from '../../../options.ts';
3
3
  /** Creates source-level target conditional handling shared by H5 and WX. */
4
- export declare function createConditionalDirectivePlugin(target: VitePluginTaroTarget): Plugin;
4
+ export declare function createConditionalDirectivePlugin(target: VptTarget): Plugin;
@@ -1,7 +1,7 @@
1
1
  import type { PluginOption } from 'vite';
2
- import type { VitePluginTaroOptions } from '../../../options.ts';
2
+ import type { VptOptions } from '../../../options.ts';
3
3
  /** Creates the plugins that own the H5 target. */
4
- export declare function createH5TargetPlugins(options: VitePluginTaroOptions): PluginOption[];
4
+ export declare function createH5TargetPlugins(options: VptOptions): PluginOption[];
5
5
  /**
6
6
  * Coarse source prefilter for the upstream Taro API transform.
7
7
  *
@@ -1,6 +1,6 @@
1
- import type { VitePluginTaroOptions } from '../../../../options.ts';
1
+ import type { VptOptions } from '../../../../options.ts';
2
2
  /** Creates H5 application module resolution and specialization. */
3
- export declare function createModuleResolver(options: VitePluginTaroOptions): {
3
+ export declare function createModuleResolver(options: VptOptions): {
4
4
  resolveId({ id, projectRoot }: {
5
5
  id: string;
6
6
  projectRoot: string;
@@ -1,10 +1,10 @@
1
- import type { VitePluginTaroOptions } from '../../../options.ts';
1
+ import type { VptOptions } from '../../../options.ts';
2
2
  import { type AstTransformResult } from '../../utils/transform.ts';
3
3
  /** Specializes the physical H5 App for one configured project. */
4
4
  export declare function transformH5App({ code, id, options, projectRoot, sourcemap }: {
5
5
  code: string;
6
6
  id: string;
7
- options: VitePluginTaroOptions;
7
+ options: VptOptions;
8
8
  projectRoot: string;
9
9
  sourcemap?: boolean;
10
10
  }): Promise<AstTransformResult>;
@@ -2,8 +2,8 @@ import { types } from '@babel/core';
2
2
  import { createPageComponentImportPath } from '../../utils/modules.js';
3
3
  import { createAppConfig } from '../../utils/project-config.js';
4
4
  import { replaceWithAst } from '../../utils/transform.js';
5
- const appConfigPlaceholder = '__VITE_PLUGIN_TARO_H5_APP_CONFIG__';
6
- const routesPlaceholder = '__VITE_PLUGIN_TARO_H5_ROUTES__';
5
+ const appConfigPlaceholder = '__VPT_H5_APP_CONFIG__';
6
+ const routesPlaceholder = '__VPT_H5_ROUTES__';
7
7
  /** Specializes the physical H5 App for one configured project. */
8
8
  export async function transformH5App({ code, id, options, projectRoot, sourcemap = true }) {
9
9
  const transformed = await replaceWithAst(code, id, {
@@ -1,5 +1,5 @@
1
1
  import type { ViteDevServer } from 'vite';
2
- import type { VitePluginTaroOptions } from '../../../../options.ts';
2
+ import type { VptOptions } from '../../../../options.ts';
3
3
  export type WxDevHost = Readonly<{
4
4
  close: () => Promise<void>;
5
5
  }>;
@@ -14,6 +14,6 @@ export type WxDevHost = Readonly<{
14
14
  */
15
15
  export declare function createWxDevHost({ server, options, applicationEntryIds }: {
16
16
  server: ViteDevServer;
17
- options: VitePluginTaroOptions;
17
+ options: VptOptions;
18
18
  applicationEntryIds: readonly string[];
19
19
  }): Promise<WxDevHost>;
@@ -1,5 +1,5 @@
1
1
  import { type PluginOption } from 'vite';
2
- import type { VitePluginTaroOptions } from '../../../../options.ts';
2
+ import type { VptOptions } from '../../../../options.ts';
3
3
  /** Selects the sole Vite environment that owns the physical Mini Program development project. */
4
4
  export declare function isWxClientEnvironment(environment: Readonly<{
5
5
  name: string;
@@ -11,7 +11,7 @@ export declare function isWxClientEnvironment(environment: Readonly<{
11
11
  * The ordered application entries cross this configuration boundary unchanged so the host can compose global CSS without
12
12
  * reconstructing the resolver's App/Page ownership policy from unrelated Rolldown shell and transport entries.
13
13
  */
14
- export declare function createWxDevelopmentPlugin(options: VitePluginTaroOptions, applicationEntryIds: readonly string[]): PluginOption[];
14
+ export declare function createWxDevelopmentPlugin(options: VptOptions, applicationEntryIds: readonly string[]): PluginOption[];
15
15
  /**
16
16
  * Transfers development ownership of `app.wxss` from complete output to the dev host.
17
17
  *
@@ -1,7 +1,7 @@
1
1
  import type { InputOptions, OutputOptions, Plugin } from 'rolldown';
2
2
  import { type DevEngine } from 'rolldown/experimental';
3
3
  import type { ViteDevServer } from 'vite';
4
- import type { VitePluginTaroOptions } from '../../../../options.ts';
4
+ import type { VptOptions } from '../../../../options.ts';
5
5
  type BundledDevRolldownOptions = InputOptions & {
6
6
  experimental?: {
7
7
  [key: string]: unknown;
@@ -22,7 +22,7 @@ export type BundledDev = {
22
22
  export declare function installWxDevOptions({ bundledDev, server, options, hostPlugins }: {
23
23
  bundledDev: BundledDev;
24
24
  server: ViteDevServer;
25
- options: VitePluginTaroOptions;
25
+ options: VptOptions;
26
26
  hostPlugins: Plugin[];
27
27
  }): void;
28
28
  /** Returns the configured output after rejecting states unsupported by the physical WX engine. */
@@ -1,10 +1,10 @@
1
1
  import type { Rolldown } from 'vite';
2
- import type { VitePluginTaroOptions } from '../../../../options.ts';
2
+ import type { VptOptions } from '../../../../options.ts';
3
3
  import type { GeneratedSubpackage } from '../placement/placer.ts';
4
4
  /** Creates every compiler-owned WX file derived from the final Rolldown bundle. */
5
5
  export declare function createOutputFiles({ bundle, options, subpackages, getModuleInfo }: {
6
6
  bundle: Rolldown.OutputBundle;
7
- options: VitePluginTaroOptions;
7
+ options: VptOptions;
8
8
  subpackages: readonly GeneratedSubpackage[];
9
9
  getModuleInfo: (moduleId: string) => {
10
10
  meta: Rolldown.CustomPluginOptions;
@@ -1,9 +1,9 @@
1
1
  import type { Rolldown } from 'vite';
2
- import type { JsonObject, VitePluginTaroOptions } from '../../../../options.ts';
2
+ import type { VptJsonObject, VptOptions } from '../../../../options.ts';
3
3
  import type { GeneratedSubpackage } from '../placement/placer.ts';
4
4
  /** Creates every configured native JSON asset. */
5
5
  export declare function createJsonAssets({ options, subpackages, nativeComponents }: {
6
- options: VitePluginTaroOptions;
6
+ options: VptOptions;
7
7
  subpackages: readonly GeneratedSubpackage[];
8
8
  nativeComponents: readonly {
9
9
  name: string;
@@ -11,4 +11,4 @@ export declare function createJsonAssets({ options, subpackages, nativeComponent
11
11
  }[];
12
12
  }): Rolldown.EmittedAsset[];
13
13
  /** Serializes one native JSON object with stable formatting. */
14
- export declare function renderJson(value: JsonObject): string;
14
+ export declare function renderJson(value: VptJsonObject): string;
@@ -13,7 +13,7 @@ export function createJsonAssets({ options, subpackages, nativeComponents }) {
13
13
  ...(options.projectPrivateConfigJson
14
14
  ? [createJsonAsset('project.private.config.json', options.projectPrivateConfigJson)]
15
15
  : []),
16
- createJsonAsset('sitemap.json', options.sitemapJson)
16
+ ...(options.sitemapJson ? [createJsonAsset('sitemap.json', options.sitemapJson)] : [])
17
17
  ];
18
18
  }
19
19
  /** Creates Page JSON with generated Taro and native component registrations. */
@@ -1,7 +1,7 @@
1
1
  import type { Rolldown } from 'vite';
2
- import type { VitePluginTaroOptions } from '../../../../options.ts';
2
+ import type { VptOptions } from '../../../../options.ts';
3
3
  /** Creates Taro's shared WeChat templates and native WXML/WXSS companions for every Page. */
4
- export declare function createTemplateAssets(bundle: Rolldown.OutputBundle, options: VitePluginTaroOptions, nativeComponents: readonly {
4
+ export declare function createTemplateAssets(bundle: Rolldown.OutputBundle, options: VptOptions, nativeComponents: readonly {
5
5
  name: string;
6
6
  fields: readonly string[];
7
7
  }[]): Rolldown.EmittedAsset[];
@@ -1,4 +1,4 @@
1
1
  import type { PluginOption } from 'vite';
2
- import type { VitePluginTaroOptions } from '../../../options.ts';
2
+ import type { VptOptions } from '../../../options.ts';
3
3
  /** Creates the complete plugin set for the wx target. */
4
- export declare function createWxTargetPlugins(options: VitePluginTaroOptions): PluginOption[];
4
+ export declare function createWxTargetPlugins(options: VptOptions): PluginOption[];
@@ -2,7 +2,7 @@ import path from 'node:path';
2
2
  import { types } from '@babel/core';
3
3
  import { replaceWithAst } from '../../../utils/transform.js';
4
4
  import { getWxExecutionKind } from '../module.js';
5
- const transportPlaceholder = '__VITE_PLUGIN_TARO_TRANSPORT__';
5
+ const transportPlaceholder = '__VPT_TRANSPORT__';
6
6
  const moduleIdParameter = 'moduleId';
7
7
  const exportBindingParameter = 'exportBinding';
8
8
  /**
@@ -1,6 +1,6 @@
1
- import type { VitePluginTaroOptions } from '../../../../options.ts';
1
+ import type { VptOptions } from '../../../../options.ts';
2
2
  /** Creates the resolver and source specializer for the wx module graph. */
3
- export declare function createResolver(options: VitePluginTaroOptions): {
3
+ export declare function createResolver(options: VptOptions): {
4
4
  resolveId(id: string, importer: string | undefined, projectRoot: string): string | undefined;
5
5
  specialize(code: string, id: string, sourcemap?: boolean): Promise<import("../../../utils/transform.ts").AstTransformResult> | undefined;
6
6
  applicationEntryIds: string[];
@@ -1,9 +1,9 @@
1
- import type { JsonObject } from '../../../../options.ts';
1
+ import type { VptJsonObject } from '../../../../options.ts';
2
2
  import { type AstTransformResult } from '../../../utils/transform.ts';
3
3
  /** Specializes the amphibious bootstrap with the shared App configuration. */
4
4
  export declare function specializeBootstrap({ code, id, appConfig, sourcemap }: {
5
5
  code: string;
6
6
  id: string;
7
- appConfig: JsonObject;
7
+ appConfig: VptJsonObject;
8
8
  sourcemap?: boolean;
9
9
  }): Promise<AstTransformResult>;
@@ -1,6 +1,6 @@
1
1
  import { types } from '@babel/core';
2
2
  import { replaceWithAst } from '../../../utils/transform.js';
3
- const appConfigPlaceholder = '__VITE_PLUGIN_TARO_APP_CONFIG__';
3
+ const appConfigPlaceholder = '__VPT_APP_CONFIG__';
4
4
  /** Specializes the amphibious bootstrap with the shared App configuration. */
5
5
  export function specializeBootstrap({ code, id, appConfig, sourcemap = true }) {
6
6
  return replaceWithAst(code, id, {
@@ -1,9 +1,9 @@
1
- import type { VitePluginTaroPageOption } from '../../../../options.ts';
1
+ import type { VptPageOption } from '../../../../options.ts';
2
2
  import { type AstTransformResult } from '../../../utils/transform.ts';
3
3
  /** Specializes the Page capsule for one configured route. */
4
4
  export declare function specializePageCapsule({ code, id, page, sourcemap }: {
5
5
  code: string;
6
6
  id: string;
7
- page: VitePluginTaroPageOption;
7
+ page: VptPageOption;
8
8
  sourcemap?: boolean;
9
9
  }): Promise<AstTransformResult>;
@@ -1,7 +1,7 @@
1
1
  import { types } from '@babel/core';
2
2
  import { replaceWithAst } from '../../../utils/transform.js';
3
- const pagePathPlaceholder = '__VITE_PLUGIN_TARO_PAGE_PATH__';
4
- const pageConfigPlaceholder = '__VITE_PLUGIN_TARO_PAGE_CONFIG__';
3
+ const pagePathPlaceholder = '__VPT_PAGE_PATH__';
4
+ const pageConfigPlaceholder = '__VPT_PAGE_CONFIG__';
5
5
  /** Specializes the Page capsule for one configured route. */
6
6
  export function specializePageCapsule({ code, id, page, sourcemap = true }) {
7
7
  return replaceWithAst(code, id, {
@@ -1,3 +1,3 @@
1
- import type { JsonObject, VitePluginTaroOptions } from '../../options.ts';
1
+ import type { VptJsonObject, VptOptions } from '../../options.ts';
2
2
  /** Creates shared App configuration with configured Page order as the authoritative value. */
3
- export declare function createAppConfig(options: VitePluginTaroOptions): JsonObject;
3
+ export declare function createAppConfig(options: VptOptions): VptJsonObject;
@@ -0,0 +1,4 @@
1
+ import type { PluginOption } from 'vite';
2
+ import type { VptOptions } from '../options.ts';
3
+ /** Creates the Vite plugins for one Taro target. */
4
+ export default function vpt(options: VptOptions): PluginOption[];
@@ -4,7 +4,7 @@ import { createConditionalDirectivePlugin } from './plugins/conditional/conditio
4
4
  import { createH5TargetPlugins } from './plugins/h5/plugins.js';
5
5
  import { createWxTargetPlugins } from './plugins/wx/plugins.js';
6
6
  /** Creates the Vite plugins for one Taro target. */
7
- export default function vitePluginTaro(options) {
7
+ export default function vpt(options) {
8
8
  return [
9
9
  createConditionalDirectivePlugin(options.target),
10
10
  createClientTaroPlugin(options.target),
package/dist/options.d.ts CHANGED
@@ -1,20 +1,72 @@
1
1
  /** A JSON object used by generated target configs. */
2
- export type JsonObject = Record<string, unknown>;
2
+ export type VptJsonObject = Record<string, unknown>;
3
3
  /** Build target handled by this plugin. */
4
- export type VitePluginTaroTarget = 'wx' | 'h5';
4
+ export type VptTarget = 'wx' | 'h5';
5
5
  /** Configures one Taro page. */
6
- export type VitePluginTaroPageOption = {
7
- /** Taro route and output path without a file extension. */
6
+ export type VptPageOption = {
7
+ /**
8
+ * Taro route and output path without a file extension.
9
+ *
10
+ * The plugin resolves the page component from `src/${path}.tsx`, relative to the Vite project root. For example,
11
+ * `pages/home/index` resolves to `src/pages/home/index.tsx` and is emitted under `pages/home/index` for `wx`.
12
+ */
8
13
  path: string;
9
- config: JsonObject;
14
+ /**
15
+ * Target-independent Taro page configuration.
16
+ *
17
+ * For `wx`, these values form the generated `<path>.json`; the plugin augments `usingComponents` with its generated
18
+ * component registrations. For `h5`, the values are added to the corresponding Taro router entry.
19
+ */
20
+ config: VptJsonObject;
10
21
  };
11
- /** Configures the Vite Taro plugin. */
12
- export interface VitePluginTaroOptions {
13
- target: VitePluginTaroTarget;
22
+ /** Configures vpt for one build target. */
23
+ export interface VptOptions {
24
+ /**
25
+ * Platform produced by the current Vite invocation.
26
+ *
27
+ * Use `wx` to emit a WeChat Mini Program or `h5` to emit a browser application. The selected target controls Taro
28
+ * module resolution, conditional compilation, runtime bootstrapping, style processing, and output generation.
29
+ */
30
+ target: VptTarget;
31
+ /**
32
+ * Source module that default-exports the root React application component.
33
+ *
34
+ * Relative paths are resolved from Vite's project root, for example `src/app.tsx`. The component wraps the active
35
+ * page through its `children` prop and is the appropriate place to import application-wide styles.
36
+ */
14
37
  app: string;
15
- pages: VitePluginTaroPageOption[];
16
- appJson: JsonObject;
17
- projectConfigJson: JsonObject;
18
- projectPrivateConfigJson?: JsonObject;
19
- sitemapJson: JsonObject;
38
+ /**
39
+ * Complete ordered list of application pages.
40
+ *
41
+ * The declared order becomes the `pages` order in the generated `app.json`, the H5 route order, and the Page order
42
+ * in the application style cascade. Each Page source is resolved according to its `path`.
43
+ */
44
+ pages: VptPageOption[];
45
+ /**
46
+ * Target-independent Taro application configuration.
47
+ *
48
+ * For `wx`, these values form the generated `app.json`. For `h5`, they configure the Taro application and router.
49
+ * The plugin always derives `pages` from {@link pages}; caller-provided `pages`, `subPackages`, and `subpackages`
50
+ * values are discarded because the build pipeline owns page order and generated package placement.
51
+ */
52
+ appJson: VptJsonObject;
53
+ /**
54
+ * WeChat DevTools project configuration written to `project.config.json` without merging.
55
+ *
56
+ * This option is required so one configuration shape can be shared between targets, but it is only emitted for a
57
+ * `wx` build and is ignored for `h5`.
58
+ */
59
+ projectConfigJson: VptJsonObject;
60
+ /**
61
+ * Local WeChat DevTools overrides written to `project.private.config.json` without merging.
62
+ *
63
+ * The file is emitted only when this value is provided for a `wx` build. It is ignored for `h5`.
64
+ */
65
+ projectPrivateConfigJson?: VptJsonObject;
66
+ /**
67
+ * WeChat Mini Program indexing rules written to `sitemap.json` without merging.
68
+ *
69
+ * The file is emitted only when this value is provided for a `wx` build. It is ignored for `h5`.
70
+ */
71
+ sitemapJson?: VptJsonObject;
20
72
  }
@@ -5,9 +5,9 @@ import ReactDOM from 'react-dom/client';
5
5
  // @ts-expect-error: The H5 build resolves this private App component.
6
6
  import AppComponent from '\0vpt:app-component';
7
7
  const browserWindow = window;
8
- const config = __VITE_PLUGIN_TARO_H5_APP_CONFIG__;
8
+ const config = __VPT_H5_APP_CONFIG__;
9
9
  browserWindow.__taroAppConfig = config;
10
- config.routes = __VITE_PLUGIN_TARO_H5_ROUTES__;
10
+ config.routes = __VPT_H5_ROUTES__;
11
11
  const app = createReactApp(AppComponent, React, ReactDOM, config);
12
12
  const history = createHashHistory({ window: browserWindow });
13
13
  handleAppMount(config, history);
@@ -2,7 +2,7 @@
2
2
  import '../systemjs/system-core.js';
3
3
  import { transport } from './transport.js';
4
4
  /** Shares one App configuration object between the specialized bootstrap and App capsule. */
5
- export const appConfig = __VITE_PLUGIN_TARO_APP_CONFIG__;
5
+ export const appConfig = __VPT_APP_CONFIG__;
6
6
  // WX has no modulepreload transport. Genuine application import() boundaries retain System.import() and may load
7
7
  // asynchronous subpackage or top-level-await graphs through this identity wrapper.
8
8
  export const __vitePreload = (load) => load();
@@ -1,4 +1,4 @@
1
1
  // Transport itself executes only as native CommonJS. It lives beside bootstrap because together they implement the
2
2
  // amphibious boundary that publishes native namespaces to SystemJS without re-evaluating their module bodies.
3
3
  /** Dispatches to one generated literal require and bridges amphibious CommonJS namespaces inline. */
4
- export const transport = __VITE_PLUGIN_TARO_TRANSPORT__;
4
+ export const transport = __VPT_TRANSPORT__;
@@ -3,5 +3,5 @@ import './app.js';
3
3
  // @ts-expect-error: The wx build replaces this private import with the configured Page component.
4
4
  import PageComponent from '\0vpt:page-component';
5
5
  import { createPageConfig } from './taro-runtime.js';
6
- const config = createPageConfig(PageComponent, __VITE_PLUGIN_TARO_PAGE_PATH__, { root: { cn: [] } }, __VITE_PLUGIN_TARO_PAGE_CONFIG__);
6
+ const config = createPageConfig(PageComponent, __VPT_PAGE_PATH__, { root: { cn: [] } }, __VPT_PAGE_CONFIG__);
7
7
  export default config;
package/dist/vite.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- export { default } from './node/vite-plugin.ts';
2
- export type { VitePluginTaroOptions, VitePluginTaroPageOption, VitePluginTaroTarget } from './options.ts';
1
+ export { default } from './node/vpt.ts';
2
+ export type { VptJsonObject, VptOptions, VptPageOption, VptTarget } from './options.ts';
package/dist/vite.js CHANGED
@@ -1 +1 @@
1
- export { default } from './node/vite-plugin.js';
1
+ export { default } from './node/vpt.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite-plugin-taro",
3
- "version": "0.5.16",
3
+ "version": "0.6.0",
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",
@@ -76,8 +76,8 @@
76
76
  "rxjs": "^7.8.2",
77
77
  "tailwindcss": "^4.3.3",
78
78
  "weapp-tailwindcss": "^5.2.11",
79
- "@tarojs/plugin-framework-react": "npm:vite-plugin-taro-plugin-framework-react@0.5.16",
80
- "@tarojs/react": "npm:vite-plugin-taro-react@0.5.16"
79
+ "@tarojs/react": "npm:vite-plugin-taro-react@0.6.0",
80
+ "@tarojs/plugin-framework-react": "npm:vite-plugin-taro-plugin-framework-react@0.6.0"
81
81
  },
82
82
  "peerDependencies": {
83
83
  "react": "^19.0.0",
@@ -1,5 +1,5 @@
1
1
  import { normalizePath, type Plugin } from 'vite'
2
- import type { VitePluginTaroTarget } from '../../../options.ts'
2
+ import type { VptTarget } from '../../../options.ts'
3
3
  import { normalizeModuleId } from '../../utils/modules.ts'
4
4
  import { resolvePackageFile } from '../../utils/packages.ts'
5
5
  import { clientTaroNativeId } from './constant.ts'
@@ -32,7 +32,7 @@ const clientTaroModules = new Map([
32
32
  ])
33
33
 
34
34
  /** Creates the shared Taro facade backed by the selected target's API implementation. */
35
- export function createClientTaroPlugin(target: VitePluginTaroTarget): Plugin {
35
+ export function createClientTaroPlugin(target: VptTarget): Plugin {
36
36
  const platformTaroId = resolvePlatformTaroId(target)
37
37
 
38
38
  return {
@@ -62,7 +62,7 @@ export function createClientTaroPlugin(target: VitePluginTaroTarget): Plugin {
62
62
  }
63
63
  }
64
64
 
65
- function resolvePlatformTaroId(target: VitePluginTaroTarget): string {
65
+ function resolvePlatformTaroId(target: VptTarget): string {
66
66
  return target === 'h5' ? '@tarojs/plugin-platform-h5/dist/runtime/apis' : '@tarojs/taro'
67
67
  }
68
68
 
@@ -1,9 +1,9 @@
1
1
  import type { Plugin } from 'vite'
2
- import type { VitePluginTaroTarget } from '../../../options.ts'
2
+ import type { VptTarget } from '../../../options.ts'
3
3
  import { normalizeModuleId } from '../../utils/modules.ts'
4
4
 
5
5
  /** Creates source-level target conditional handling shared by H5 and WX. */
6
- export function createConditionalDirectivePlugin(target: VitePluginTaroTarget): Plugin {
6
+ export function createConditionalDirectivePlugin(target: VptTarget): Plugin {
7
7
  return {
8
8
  name: 'vpt:conditional-directives',
9
9
  enforce: 'pre',
@@ -37,7 +37,7 @@ type DirectiveFrame = {
37
37
  }
38
38
 
39
39
  /** Keeps only the source branches active for one build target. */
40
- function transformConditionalDirectives(code: string, target: VitePluginTaroTarget): string {
40
+ function transformConditionalDirectives(code: string, target: VptTarget): string {
41
41
  const lines = code.match(/[^\n]*(?:\n|$)/g) ?? []
42
42
  const frames: DirectiveFrame[] = []
43
43
  let transformed = ''
@@ -1,7 +1,7 @@
1
1
  import babel, { defineRolldownBabelPreset } from '@rolldown/plugin-babel'
2
2
  import type { HtmlTagDescriptor, Plugin, PluginOption } from 'vite'
3
3
  import { WeappTailwindcss } from 'weapp-tailwindcss/vite'
4
- import type { VitePluginTaroOptions } from '../../../options.ts'
4
+ import type { VptOptions } from '../../../options.ts'
5
5
  import { esTarget } from '../../utils/constant.ts'
6
6
  import { toViteFileImportPath } from '../../utils/modules.ts'
7
7
  import { packageRequire } from '../../utils/packages.ts'
@@ -12,7 +12,7 @@ import { createStencilClientAdapter } from './create-stencil-client-adapter.ts'
12
12
  import { createModuleResolver } from './resolver/module-resolver.ts'
13
13
 
14
14
  /** Creates the plugins that own the H5 target. */
15
- export function createH5TargetPlugins(options: VitePluginTaroOptions): PluginOption[] {
15
+ export function createH5TargetPlugins(options: VptOptions): PluginOption[] {
16
16
  return [
17
17
  WeappTailwindcss({
18
18
  appType: 'weapp-vite',
@@ -36,7 +36,7 @@ export function createH5TargetPlugins(options: VitePluginTaroOptions): PluginOpt
36
36
  }
37
37
 
38
38
  /** Configures H5 resolution and supplies the specialized physical application entry. */
39
- function createH5TargetPlugin(options: VitePluginTaroOptions): Plugin {
39
+ function createH5TargetPlugin(options: VptOptions): Plugin {
40
40
  const moduleResolver = createModuleResolver(options)
41
41
 
42
42
  return {
@@ -1,12 +1,12 @@
1
1
  import { normalizePath } from 'vite'
2
- import type { VitePluginTaroOptions } from '../../../../options.ts'
2
+ import type { VptOptions } from '../../../../options.ts'
3
3
  import { normalizeModuleId, resolveAppComponentPath } from '../../../utils/modules.ts'
4
4
  import { appComponentId } from '../../client/constant.ts'
5
5
  import { h5AppPath } from '../constant.ts'
6
6
  import { transformH5App } from '../transform-app.ts'
7
7
 
8
8
  /** Creates H5 application module resolution and specialization. */
9
- export function createModuleResolver(options: VitePluginTaroOptions) {
9
+ export function createModuleResolver(options: VptOptions) {
10
10
  return {
11
11
  resolveId({ id, projectRoot }: { id: string; projectRoot: string }): string | undefined {
12
12
  if (id === appComponentId) {
@@ -1,11 +1,11 @@
1
1
  import { types } from '@babel/core'
2
- import type { VitePluginTaroOptions, VitePluginTaroPageOption } from '../../../options.ts'
2
+ import type { VptOptions, VptPageOption } from '../../../options.ts'
3
3
  import { createPageComponentImportPath } from '../../utils/modules.ts'
4
4
  import { createAppConfig } from '../../utils/project-config.ts'
5
5
  import { type AstTransformResult, replaceWithAst } from '../../utils/transform.ts'
6
6
 
7
- const appConfigPlaceholder = '__VITE_PLUGIN_TARO_H5_APP_CONFIG__'
8
- const routesPlaceholder = '__VITE_PLUGIN_TARO_H5_ROUTES__'
7
+ const appConfigPlaceholder = '__VPT_H5_APP_CONFIG__'
8
+ const routesPlaceholder = '__VPT_H5_ROUTES__'
9
9
 
10
10
  /** Specializes the physical H5 App for one configured project. */
11
11
  export async function transformH5App({
@@ -17,7 +17,7 @@ export async function transformH5App({
17
17
  }: {
18
18
  code: string
19
19
  id: string
20
- options: VitePluginTaroOptions
20
+ options: VptOptions
21
21
  projectRoot: string
22
22
  sourcemap?: boolean
23
23
  }): Promise<AstTransformResult> {
@@ -56,7 +56,7 @@ function createRoute({
56
56
  page,
57
57
  projectRoot
58
58
  }: {
59
- page: VitePluginTaroPageOption
59
+ page: VptPageOption
60
60
  projectRoot: string
61
61
  }): ReturnType<typeof types.objectExpression> {
62
62
  const pageComponentPath = createPageComponentImportPath({ pagePath: page.path, projectRoot })
@@ -5,7 +5,7 @@ import colors from 'picocolors'
5
5
  import { type DevEngine, type DevOptions, dev } from 'rolldown/experimental'
6
6
  import { asyncScheduler } from 'rxjs'
7
7
  import type { Connect, ViteDevServer } from 'vite'
8
- import type { VitePluginTaroOptions } from '../../../../options.ts'
8
+ import type { VptOptions } from '../../../../options.ts'
9
9
  import { createHmrResultsStream } from './create-hmr-results-stream.ts'
10
10
  import { createStyleCapture, type StyleCaptureAction } from './create-style-capture.ts'
11
11
  import {
@@ -61,7 +61,7 @@ export async function createWxDevHost({
61
61
  applicationEntryIds
62
62
  }: {
63
63
  server: ViteDevServer
64
- options: VitePluginTaroOptions
64
+ options: VptOptions
65
65
  applicationEntryIds: readonly string[]
66
66
  }): Promise<WxDevHost> {
67
67
  const bundledDev = getBundledDev(server)
@@ -1,5 +1,5 @@
1
1
  import { normalizePath, type PluginOption, transformWithOxc } from 'vite'
2
- import type { VitePluginTaroOptions } from '../../../../options.ts'
2
+ import type { VptOptions } from '../../../../options.ts'
3
3
  import { esTarget } from '../../../utils/constant.ts'
4
4
  import { memoize } from '../../../utils/memoize.ts'
5
5
  import { normalizeModuleId } from '../../../utils/modules.ts'
@@ -22,10 +22,7 @@ export function isWxClientEnvironment(environment: Readonly<{ name: string }>):
22
22
  * The ordered application entries cross this configuration boundary unchanged so the host can compose global CSS without
23
23
  * reconstructing the resolver's App/Page ownership policy from unrelated Rolldown shell and transport entries.
24
24
  */
25
- export function createWxDevelopmentPlugin(
26
- options: VitePluginTaroOptions,
27
- applicationEntryIds: readonly string[]
28
- ): PluginOption[] {
25
+ export function createWxDevelopmentPlugin(options: VptOptions, applicationEntryIds: readonly string[]): PluginOption[] {
29
26
  /*
30
27
  * Vite creates this plugin descriptor before a server or DevEngine exists, then invokes configureServer and closeBundle on
31
28
  * different lifecycle stacks. This mutable handle transfers the one client-owned host between those hooks: configureServer
@@ -3,7 +3,7 @@ import type { InputOptions, OutputOptions, Plugin } from 'rolldown'
3
3
  import { build } from 'rolldown'
4
4
  import { type DevEngine, viteReporterPlugin } from 'rolldown/experimental'
5
5
  import type { ViteDevServer } from 'vite'
6
- import type { VitePluginTaroOptions } from '../../../../options.ts'
6
+ import type { VptOptions } from '../../../../options.ts'
7
7
  import { once } from '../../../utils/once.ts'
8
8
  import { resolvePackageFile } from '../../../utils/packages.ts'
9
9
  import { appShellFileName } from '../module.ts'
@@ -35,7 +35,7 @@ export function installWxDevOptions({
35
35
  }: {
36
36
  bundledDev: BundledDev
37
37
  server: ViteDevServer
38
- options: VitePluginTaroOptions
38
+ options: VptOptions
39
39
  hostPlugins: Plugin[]
40
40
  }): void {
41
41
  /*
@@ -1,5 +1,5 @@
1
1
  import type { Rolldown } from 'vite'
2
- import type { VitePluginTaroOptions } from '../../../../options.ts'
2
+ import type { VptOptions } from '../../../../options.ts'
3
3
  import { createNativeComponentOutput } from '../native/create-native-component-output.ts'
4
4
  import type { GeneratedSubpackage } from '../placement/placer.ts'
5
5
  import { createJsonAssets } from './json.ts'
@@ -13,7 +13,7 @@ export async function createOutputFiles({
13
13
  getModuleInfo
14
14
  }: {
15
15
  bundle: Rolldown.OutputBundle
16
- options: VitePluginTaroOptions
16
+ options: VptOptions
17
17
  subpackages: readonly GeneratedSubpackage[]
18
18
  getModuleInfo: (moduleId: string) => { meta: Rolldown.CustomPluginOptions } | null
19
19
  }): Promise<Rolldown.EmittedFile[]> {
@@ -1,5 +1,5 @@
1
1
  import type { Rolldown } from 'vite'
2
- import type { JsonObject, VitePluginTaroOptions, VitePluginTaroPageOption } from '../../../../options.ts'
2
+ import type { VptJsonObject, VptOptions, VptPageOption } from '../../../../options.ts'
3
3
  import { createAppConfig } from '../../../utils/project-config.ts'
4
4
  import type { GeneratedSubpackage } from '../placement/placer.ts'
5
5
  import { isGeneratedSubpackageFile } from '../placement/plan.ts'
@@ -11,7 +11,7 @@ export function createJsonAssets({
11
11
  subpackages,
12
12
  nativeComponents
13
13
  }: {
14
- options: VitePluginTaroOptions
14
+ options: VptOptions
15
15
  subpackages: readonly GeneratedSubpackage[]
16
16
  nativeComponents: readonly { name: string; componentPath: string }[]
17
17
  }): Rolldown.EmittedAsset[] {
@@ -29,15 +29,15 @@ export function createJsonAssets({
29
29
  ? [createJsonAsset('project.private.config.json', options.projectPrivateConfigJson)]
30
30
  : []),
31
31
 
32
- createJsonAsset('sitemap.json', options.sitemapJson)
32
+ ...(options.sitemapJson ? [createJsonAsset('sitemap.json', options.sitemapJson)] : [])
33
33
  ]
34
34
  }
35
35
 
36
36
  /** Creates Page JSON with generated Taro and native component registrations. */
37
37
  function createPageJson(
38
- page: VitePluginTaroPageOption,
38
+ page: VptPageOption,
39
39
  nativeComponents: readonly { name: string; componentPath: string }[]
40
- ): JsonObject {
40
+ ): VptJsonObject {
41
41
  const usingComponents = isJsonObject(page.config.usingComponents) ? page.config.usingComponents : {}
42
42
 
43
43
  // Cross-package components require a placeholder while WeChat downloads their generated subpackage. Paths are
@@ -60,17 +60,17 @@ function createPageJson(
60
60
  }
61
61
 
62
62
  /** Tests whether a configured JSON value can be merged as an object. */
63
- function isJsonObject(value: unknown): value is JsonObject {
63
+ function isJsonObject(value: unknown): value is VptJsonObject {
64
64
  return typeof value === 'object' && value !== null && !Array.isArray(value)
65
65
  }
66
66
 
67
67
  /** Serializes one native JSON object with stable formatting. */
68
- export function renderJson(value: JsonObject): string {
68
+ export function renderJson(value: VptJsonObject): string {
69
69
  return `${JSON.stringify(value, null, 4)}\n`
70
70
  }
71
71
 
72
72
  /** Creates one native JSON asset. */
73
- function createJsonAsset(fileName: string, value: JsonObject): Rolldown.EmittedAsset {
73
+ function createJsonAsset(fileName: string, value: VptJsonObject): Rolldown.EmittedAsset {
74
74
  return {
75
75
  type: 'asset',
76
76
  fileName,
@@ -1,7 +1,7 @@
1
1
  import { recursiveMerge } from '@tarojs/helper'
2
2
  import { Weapp as WxPlatform } from '@tarojs/plugin-platform-weapp'
3
3
  import type { Rolldown } from 'vite'
4
- import type { JsonObject, VitePluginTaroOptions } from '../../../../options.ts'
4
+ import type { VptJsonObject, VptOptions } from '../../../../options.ts'
5
5
  import { normalizeModuleId } from '../../../utils/modules.ts'
6
6
  import { packageRequire } from '../../../utils/packages.ts'
7
7
  import { renderJson } from './json.ts'
@@ -19,7 +19,7 @@ const taroComponentsModulePath = packageRequire.resolve('@tarojs/plugin-platform
19
19
  /** Creates Taro's shared WeChat templates and native WXML/WXSS companions for every Page. */
20
20
  export function createTemplateAssets(
21
21
  bundle: Rolldown.OutputBundle,
22
- options: VitePluginTaroOptions,
22
+ options: VptOptions,
23
23
  nativeComponents: readonly {
24
24
  name: string
25
25
  fields: readonly string[]
@@ -121,7 +121,7 @@ function toDashed(value: string): string {
121
121
  }
122
122
 
123
123
  /** Creates the recursive component configuration expected by Taro's templates. */
124
- function createComponentJson(): JsonObject {
124
+ function createComponentJson(): VptJsonObject {
125
125
  return {
126
126
  component: true,
127
127
  styleIsolation: 'apply-shared',
@@ -1,5 +1,5 @@
1
1
  import type { Plugin, PluginOption } from 'vite'
2
- import type { VitePluginTaroOptions } from '../../../options.ts'
2
+ import type { VptOptions } from '../../../options.ts'
3
3
  import { esTarget } from '../../utils/constant.ts'
4
4
  import { packageRequire } from '../../utils/packages.ts'
5
5
  import { clientTaroNativeId } from '../client/constant.ts'
@@ -18,7 +18,7 @@ import { createWxStylePlugins } from './styles/plugins.ts'
18
18
  type WxResolver = ReturnType<typeof createResolver>
19
19
 
20
20
  /** Creates the complete plugin set for the wx target. */
21
- export function createWxTargetPlugins(options: VitePluginTaroOptions): PluginOption[] {
21
+ export function createWxTargetPlugins(options: VptOptions): PluginOption[] {
22
22
  const resolver = createResolver(options)
23
23
 
24
24
  // Reuse the resolver instance's ordered application subset. Rolldown's complete input also contains bootstrap, transport,
@@ -31,7 +31,7 @@ export function createWxTargetPlugins(options: VitePluginTaroOptions): PluginOpt
31
31
  }
32
32
 
33
33
  /** Configures the complete wx target build pipeline. */
34
- function createWxPlugin(options: VitePluginTaroOptions, resolver: WxResolver): Plugin {
34
+ function createWxPlugin(options: VptOptions, resolver: WxResolver): Plugin {
35
35
  const placer = createPlacer()
36
36
 
37
37
  return {
@@ -4,7 +4,7 @@ import type { Rolldown } from 'vite'
4
4
  import { type AstTransformResult, replaceWithAst } from '../../../utils/transform.ts'
5
5
  import { getWxExecutionKind } from '../module.ts'
6
6
 
7
- const transportPlaceholder = '__VITE_PLUGIN_TARO_TRANSPORT__'
7
+ const transportPlaceholder = '__VPT_TRANSPORT__'
8
8
  const moduleIdParameter = 'moduleId'
9
9
  const exportBindingParameter = 'exportBinding'
10
10
 
@@ -1,5 +1,5 @@
1
1
  import { normalizePath } from 'vite'
2
- import type { VitePluginTaroOptions, VitePluginTaroPageOption } from '../../../../options.ts'
2
+ import type { VptOptions, VptPageOption } from '../../../../options.ts'
3
3
  import { normalizeModuleId, resolveAppComponentPath, resolvePageComponentPath } from '../../../utils/modules.ts'
4
4
  import { createAppConfig } from '../../../utils/project-config.ts'
5
5
  import { appComponentId } from '../../client/constant.ts'
@@ -25,7 +25,7 @@ import { specializePageCapsule } from './specialize-page-capsule.ts'
25
25
  type PrivateIdResolver = (importer: string | undefined, projectRoot: string) => string
26
26
 
27
27
  /** Creates the resolver and source specializer for the wx module graph. */
28
- export function createResolver(options: VitePluginTaroOptions) {
28
+ export function createResolver(options: VptOptions) {
29
29
  const normalizedBootstrapPath = normalizePath(bootstrapPath)
30
30
  const normalizedPageCapsulePath = normalizePath(pageCapsulePath)
31
31
 
@@ -87,7 +87,7 @@ export function createResolver(options: VitePluginTaroOptions) {
87
87
  }
88
88
 
89
89
  /** Declares output entries and the ordered application subset that can own user styles. */
90
- function createEntryGraph(pages: readonly VitePluginTaroPageOption[]) {
90
+ function createEntryGraph(pages: readonly VptPageOption[]) {
91
91
  const pageEntries = pages.map((page) => {
92
92
  return {
93
93
  capsuleId: createRouteModuleId({ moduleId: pageCapsulePath, pagePath: page.path }),
@@ -128,8 +128,8 @@ function requireConfiguredPage({
128
128
  pageByPath
129
129
  }: {
130
130
  moduleId: string | undefined
131
- pageByPath: ReadonlyMap<string, VitePluginTaroPageOption>
132
- }): VitePluginTaroPageOption {
131
+ pageByPath: ReadonlyMap<string, VptPageOption>
132
+ }): VptPageOption {
133
133
  const queryIndex = moduleId?.indexOf('?') ?? -1
134
134
  const pagePath = queryIndex === -1 ? undefined : new URLSearchParams(moduleId?.slice(queryIndex + 1)).get('route')
135
135
  const page = pagePath ? pageByPath.get(pagePath) : undefined
@@ -1,8 +1,8 @@
1
1
  import { types } from '@babel/core'
2
- import type { JsonObject } from '../../../../options.ts'
2
+ import type { VptJsonObject } from '../../../../options.ts'
3
3
  import { type AstTransformResult, replaceWithAst } from '../../../utils/transform.ts'
4
4
 
5
- const appConfigPlaceholder = '__VITE_PLUGIN_TARO_APP_CONFIG__'
5
+ const appConfigPlaceholder = '__VPT_APP_CONFIG__'
6
6
 
7
7
  /** Specializes the amphibious bootstrap with the shared App configuration. */
8
8
  export function specializeBootstrap({
@@ -13,7 +13,7 @@ export function specializeBootstrap({
13
13
  }: {
14
14
  code: string
15
15
  id: string
16
- appConfig: JsonObject
16
+ appConfig: VptJsonObject
17
17
  sourcemap?: boolean
18
18
  }): Promise<AstTransformResult> {
19
19
  return replaceWithAst(
@@ -1,9 +1,9 @@
1
1
  import { types } from '@babel/core'
2
- import type { VitePluginTaroPageOption } from '../../../../options.ts'
2
+ import type { VptPageOption } from '../../../../options.ts'
3
3
  import { type AstTransformResult, replaceWithAst } from '../../../utils/transform.ts'
4
4
 
5
- const pagePathPlaceholder = '__VITE_PLUGIN_TARO_PAGE_PATH__'
6
- const pageConfigPlaceholder = '__VITE_PLUGIN_TARO_PAGE_CONFIG__'
5
+ const pagePathPlaceholder = '__VPT_PAGE_PATH__'
6
+ const pageConfigPlaceholder = '__VPT_PAGE_CONFIG__'
7
7
 
8
8
  /** Specializes the Page capsule for one configured route. */
9
9
  export function specializePageCapsule({
@@ -14,7 +14,7 @@ export function specializePageCapsule({
14
14
  }: {
15
15
  code: string
16
16
  id: string
17
- page: VitePluginTaroPageOption
17
+ page: VptPageOption
18
18
  sourcemap?: boolean
19
19
  }): Promise<AstTransformResult> {
20
20
  return replaceWithAst(
@@ -1,7 +1,7 @@
1
- import type { JsonObject, VitePluginTaroOptions } from '../../options.ts'
1
+ import type { VptJsonObject, VptOptions } from '../../options.ts'
2
2
 
3
3
  /** Creates shared App configuration with configured Page order as the authoritative value. */
4
- export function createAppConfig(options: VitePluginTaroOptions): JsonObject {
4
+ export function createAppConfig(options: VptOptions): VptJsonObject {
5
5
  const { subPackages: _subPackages, subpackages: _subpackages, ...appJson } = options.appJson
6
6
  return {
7
7
  ...appJson,
@@ -1,13 +1,13 @@
1
1
  import react from '@vitejs/plugin-react'
2
2
  import type { PluginOption } from 'vite'
3
- import type { VitePluginTaroOptions } from '../options.ts'
3
+ import type { VptOptions } from '../options.ts'
4
4
  import { createClientTaroPlugin } from './plugins/client/client-taro.ts'
5
5
  import { createConditionalDirectivePlugin } from './plugins/conditional/conditional-directives.ts'
6
6
  import { createH5TargetPlugins } from './plugins/h5/plugins.ts'
7
7
  import { createWxTargetPlugins } from './plugins/wx/plugins.ts'
8
8
 
9
9
  /** Creates the Vite plugins for one Taro target. */
10
- export default function vitePluginTaro(options: VitePluginTaroOptions): PluginOption[] {
10
+ export default function vpt(options: VptOptions): PluginOption[] {
11
11
  return [
12
12
  createConditionalDirectivePlugin(options.target),
13
13
  createClientTaroPlugin(options.target),
package/src/options.ts CHANGED
@@ -1,24 +1,82 @@
1
1
  /** A JSON object used by generated target configs. */
2
- export type JsonObject = Record<string, unknown>
2
+ export type VptJsonObject = Record<string, unknown>
3
3
 
4
4
  /** Build target handled by this plugin. */
5
- export type VitePluginTaroTarget = 'wx' | 'h5'
5
+ export type VptTarget = 'wx' | 'h5'
6
6
 
7
7
  /** Configures one Taro page. */
8
- export type VitePluginTaroPageOption = {
9
- /** Taro route and output path without a file extension. */
8
+ export type VptPageOption = {
9
+ /**
10
+ * Taro route and output path without a file extension.
11
+ *
12
+ * The plugin resolves the page component from `src/${path}.tsx`, relative to the Vite project root. For example,
13
+ * `pages/home/index` resolves to `src/pages/home/index.tsx` and is emitted under `pages/home/index` for `wx`.
14
+ */
10
15
  path: string
11
16
 
12
- config: JsonObject
17
+ /**
18
+ * Target-independent Taro page configuration.
19
+ *
20
+ * For `wx`, these values form the generated `<path>.json`; the plugin augments `usingComponents` with its generated
21
+ * component registrations. For `h5`, the values are added to the corresponding Taro router entry.
22
+ */
23
+ config: VptJsonObject
13
24
  }
14
25
 
15
- /** Configures the Vite Taro plugin. */
16
- export interface VitePluginTaroOptions {
17
- target: VitePluginTaroTarget
26
+ /** Configures vpt for one build target. */
27
+ export interface VptOptions {
28
+ /**
29
+ * Platform produced by the current Vite invocation.
30
+ *
31
+ * Use `wx` to emit a WeChat Mini Program or `h5` to emit a browser application. The selected target controls Taro
32
+ * module resolution, conditional compilation, runtime bootstrapping, style processing, and output generation.
33
+ */
34
+ target: VptTarget
35
+
36
+ /**
37
+ * Source module that default-exports the root React application component.
38
+ *
39
+ * Relative paths are resolved from Vite's project root, for example `src/app.tsx`. The component wraps the active
40
+ * page through its `children` prop and is the appropriate place to import application-wide styles.
41
+ */
18
42
  app: string
19
- pages: VitePluginTaroPageOption[]
20
- appJson: JsonObject
21
- projectConfigJson: JsonObject
22
- projectPrivateConfigJson?: JsonObject
23
- sitemapJson: JsonObject
43
+
44
+ /**
45
+ * Complete ordered list of application pages.
46
+ *
47
+ * The declared order becomes the `pages` order in the generated `app.json`, the H5 route order, and the Page order
48
+ * in the application style cascade. Each Page source is resolved according to its `path`.
49
+ */
50
+ pages: VptPageOption[]
51
+
52
+ /**
53
+ * Target-independent Taro application configuration.
54
+ *
55
+ * For `wx`, these values form the generated `app.json`. For `h5`, they configure the Taro application and router.
56
+ * The plugin always derives `pages` from {@link pages}; caller-provided `pages`, `subPackages`, and `subpackages`
57
+ * values are discarded because the build pipeline owns page order and generated package placement.
58
+ */
59
+ appJson: VptJsonObject
60
+
61
+ /**
62
+ * WeChat DevTools project configuration written to `project.config.json` without merging.
63
+ *
64
+ * This option is required so one configuration shape can be shared between targets, but it is only emitted for a
65
+ * `wx` build and is ignored for `h5`.
66
+ */
67
+ projectConfigJson: VptJsonObject
68
+
69
+ /**
70
+ * Local WeChat DevTools overrides written to `project.private.config.json` without merging.
71
+ *
72
+ * The file is emitted only when this value is provided for a `wx` build. It is ignored for `h5`.
73
+ */
74
+ projectPrivateConfigJson?: VptJsonObject
75
+
76
+ /**
77
+ * WeChat Mini Program indexing rules written to `sitemap.json` without merging.
78
+ *
79
+ * The file is emitted only when this value is provided for a `wx` build. It is ignored for `h5`.
80
+ */
81
+ sitemapJson?: VptJsonObject
24
82
  }
@@ -8,16 +8,16 @@ import ReactDOM from 'react-dom/client'
8
8
  // @ts-expect-error: The H5 build resolves this private App component.
9
9
  import AppComponent from '\0vpt:app-component'
10
10
 
11
- declare const __VITE_PLUGIN_TARO_H5_APP_CONFIG__: SpaRouterConfig
12
- declare const __VITE_PLUGIN_TARO_H5_ROUTES__: Route[]
11
+ declare const __VPT_H5_APP_CONFIG__: SpaRouterConfig
12
+ declare const __VPT_H5_ROUTES__: Route[]
13
13
 
14
14
  const browserWindow = window as unknown as Window &
15
15
  typeof window & {
16
16
  __taroAppConfig: SpaRouterConfig
17
17
  }
18
- const config = __VITE_PLUGIN_TARO_H5_APP_CONFIG__
18
+ const config = __VPT_H5_APP_CONFIG__
19
19
  browserWindow.__taroAppConfig = config
20
- config.routes = __VITE_PLUGIN_TARO_H5_ROUTES__
20
+ config.routes = __VPT_H5_ROUTES__
21
21
  const app = createReactApp(AppComponent, React, ReactDOM, config)
22
22
  const history = createHashHistory({ window: browserWindow })
23
23
  handleAppMount(config, history)
@@ -2,10 +2,10 @@
2
2
  import '../systemjs/system-core.js'
3
3
  import { transport } from './transport.ts'
4
4
 
5
- declare const __VITE_PLUGIN_TARO_APP_CONFIG__: Record<string, unknown>
5
+ declare const __VPT_APP_CONFIG__: Record<string, unknown>
6
6
 
7
7
  /** Shares one App configuration object between the specialized bootstrap and App capsule. */
8
- export const appConfig = __VITE_PLUGIN_TARO_APP_CONFIG__
8
+ export const appConfig = __VPT_APP_CONFIG__
9
9
 
10
10
  // WX has no modulepreload transport. Genuine application import() boundaries retain System.import() and may load
11
11
  // asynchronous subpackage or top-level-await graphs through this identity wrapper.
@@ -2,9 +2,7 @@
2
2
  // amphibious boundary that publishes native namespaces to SystemJS without re-evaluating their module bodies.
3
3
 
4
4
  /** Materialized from the preliminary output graph before Rolldown finalizes content hashes. */
5
- declare const __VITE_PLUGIN_TARO_TRANSPORT__: (
6
- moduleId: string
7
- ) => System.Registration | PromiseLike<System.Registration>
5
+ declare const __VPT_TRANSPORT__: (moduleId: string) => System.Registration | PromiseLike<System.Registration>
8
6
 
9
7
  /** Dispatches to one generated literal require and bridges amphibious CommonJS namespaces inline. */
10
- export const transport = __VITE_PLUGIN_TARO_TRANSPORT__
8
+ export const transport = __VPT_TRANSPORT__
@@ -5,14 +5,9 @@ import './app.ts'
5
5
  import PageComponent from '\0vpt:page-component'
6
6
  import { createPageConfig } from './taro-runtime.ts'
7
7
 
8
- declare const __VITE_PLUGIN_TARO_PAGE_PATH__: string
9
- declare const __VITE_PLUGIN_TARO_PAGE_CONFIG__: Record<string, unknown>
8
+ declare const __VPT_PAGE_PATH__: string
9
+ declare const __VPT_PAGE_CONFIG__: Record<string, unknown>
10
10
 
11
- const config = createPageConfig(
12
- PageComponent,
13
- __VITE_PLUGIN_TARO_PAGE_PATH__,
14
- { root: { cn: [] } },
15
- __VITE_PLUGIN_TARO_PAGE_CONFIG__
16
- )
11
+ const config = createPageConfig(PageComponent, __VPT_PAGE_PATH__, { root: { cn: [] } }, __VPT_PAGE_CONFIG__)
17
12
 
18
13
  export default config
package/src/vite.ts CHANGED
@@ -1,2 +1,2 @@
1
- export { default } from './node/vite-plugin.ts'
2
- export type { VitePluginTaroOptions, VitePluginTaroPageOption, VitePluginTaroTarget } from './options.ts'
1
+ export { default } from './node/vpt.ts'
2
+ export type { VptJsonObject, VptOptions, VptPageOption, VptTarget } from './options.ts'
@@ -1,4 +0,0 @@
1
- import type { PluginOption } from 'vite';
2
- import type { VitePluginTaroOptions } from '../options.ts';
3
- /** Creates the Vite plugins for one Taro target. */
4
- export default function vitePluginTaro(options: VitePluginTaroOptions): PluginOption[];