vite-plugin-taro 0.2.1 → 0.2.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.
@@ -0,0 +1,4 @@
1
+ import '@tarojs/plugin-platform-h5/dist/runtime';
2
+ export { createReactApp } from '@tarojs/plugin-framework-react/dist/runtime';
3
+ export { createBrowserHistory, createHashHistory, createRouter, handleAppMount } from '@tarojs/router';
4
+ export { window } from '@tarojs/runtime';
@@ -0,0 +1,4 @@
1
+ import '@tarojs/plugin-platform-weapp/dist/runtime.js';
2
+ export { createReactApp } from '@tarojs/plugin-framework-react/dist/runtime';
3
+ export { default as ReactDOM } from '@tarojs/react';
4
+ export { createPageConfig, createRecursiveComponentConfig } from '@tarojs/runtime';
@@ -0,0 +1,3 @@
1
+ import Taro from '@tarojs/taro';
2
+ export * from '@tarojs/taro';
3
+ export default Taro;
@@ -0,0 +1 @@
1
+ export * from '@tarojs/components';
@@ -0,0 +1,4 @@
1
+ export declare const isProd: boolean;
2
+ export declare const nodeRequire: NodeJS.Require;
3
+ export declare const h5ShimImportPath: string;
4
+ export declare const wxShimImportPath: string;
@@ -0,0 +1,8 @@
1
+ import type { Plugin } from 'vite';
2
+ import type { VitePluginTaroBuildContext } from './types.ts';
3
+ /**
4
+ * Applies Taro-style conditional compilation comments before Vite parses source files.
5
+ *
6
+ * Mirrors Taro's CSS #ifdef/#ifndef handling, generalized before Vite parses code.
7
+ */
8
+ export declare function createVitePluginTaroConditionalDirectivePlugin(context: VitePluginTaroBuildContext): Plugin;
@@ -0,0 +1,3 @@
1
+ import type { PluginOption } from 'vite';
2
+ import type { VitePluginTaroBuildContext } from './types.ts';
3
+ export declare function createTailwindcssPlugins(context: VitePluginTaroBuildContext): PluginOption[];
@@ -0,0 +1,31 @@
1
+ import type { HtmlTagDescriptor, PluginOption, UserConfig } from 'vite';
2
+ import type { VitePluginTaroBuildContext } from '../types.ts';
3
+ /**
4
+ * Checks whether an id belongs to an H5 virtual module.
5
+ */
6
+ export declare function isH5VirtualModuleId(id: string): boolean;
7
+ /**
8
+ * Loads generated source for H5 virtual modules.
9
+ */
10
+ export declare function loadH5VirtualModule(cleanId: string, context: VitePluginTaroBuildContext): string | undefined;
11
+ /**
12
+ * Configures the Vite pieces needed for Taro H5 resolve/runtime behavior.
13
+ */
14
+ export declare function createH5ViteConfig(): UserConfig;
15
+ /**
16
+ * Creates H5-only support plugins used before the target emitter runs.
17
+ *
18
+ * https://github.com/NervJS/taro/blob/f0e5c39d5f04290db975670411e23c3a396e15f8/packages/taro-platform-h5/src/program.ts#L219-L249
19
+ */
20
+ export declare function createH5SupportPlugins(): PluginOption[];
21
+ /**
22
+ * Injects vite-plugin-taro's generated Web entry into Vite's HTML shell.
23
+ */
24
+ export declare function createWebIndexHtmlTags(context: VitePluginTaroBuildContext): HtmlTagDescriptor[] | undefined;
25
+ /**
26
+ * Builds the generated Web entry around Taro's official Web router/runtime APIs.
27
+ * Base Taro CSS is imported before the app; component CSS order is handled by rewriteStencilStyleInsertion.
28
+ *
29
+ * https://github.com/NervJS/taro/blob/f0e5c39d5f04290db975670411e23c3a396e15f8/packages/taro-loader/src/h5.ts#L120-L150
30
+ */
31
+ export declare function createWebEntry(context: VitePluginTaroBuildContext): string;
@@ -119,8 +119,6 @@ function createH5TaroDefines() {
119
119
  'process.env.SUPPORT_TARO_POLYFILL': JSON.stringify('disabled'),
120
120
  'process.env.TARO_ENV': JSON.stringify('h5'),
121
121
  'process.env.TARO_PLATFORM': JSON.stringify('web'),
122
- IS_H5: 'true',
123
- IS_WEAPP: 'false',
124
122
  'process.env.SUPPORT_DINGTALK_NAVIGATE': JSON.stringify('disabled'),
125
123
  DEPRECATED_ADAPTER_COMPONENT: 'false'
126
124
  };
@@ -0,0 +1,74 @@
1
+ import type { UserConfig } from 'vite';
2
+ import type { VitePluginTaroBuildContext, VitePluginTaroPageOption } from '../types.ts';
3
+ /**
4
+ * Checks whether an id belongs to a wx virtual module.
5
+ */
6
+ export declare function isWxVirtualModuleId(id: string): boolean;
7
+ export declare function loadWxVirtualModule(cleanId: string, context: VitePluginTaroBuildContext): string | undefined;
8
+ /**
9
+ * Configures wx target entry, output, and chunk layout.
10
+ */
11
+ export declare function createWxViteConfig(context: VitePluginTaroBuildContext): UserConfig;
12
+ type WechatAssetSource = string | Uint8Array;
13
+ type WechatBundleModule = {
14
+ renderedExports?: string[];
15
+ };
16
+ type WechatBundleItem = {
17
+ type: 'asset' | 'chunk';
18
+ source?: WechatAssetSource;
19
+ modules?: Record<string, WechatBundleModule>;
20
+ };
21
+ type WechatBundle = Record<string, WechatBundleItem>;
22
+ type WechatChunkEmitter = {
23
+ emitFile(chunk: {
24
+ type: 'chunk';
25
+ id: string;
26
+ fileName: string;
27
+ implicitlyLoadedAfterOneOf: string[];
28
+ }): string;
29
+ };
30
+ type WechatAssetEmitter = {
31
+ emitFile(asset: {
32
+ type: 'asset';
33
+ fileName: string;
34
+ source: WechatAssetSource;
35
+ }): string;
36
+ };
37
+ /**
38
+ * Emits page and component chunks like Taro Webpack's MiniPlugin generated entries.
39
+ *
40
+ * https://github.com/NervJS/taro/blob/f0e5c39d5f04290db975670411e23c3a396e15f8/packages/taro-webpack5-runner/src/plugins/MiniPlugin.ts#L228-L243
41
+ * https://github.com/NervJS/taro/blob/f0e5c39d5f04290db975670411e23c3a396e15f8/packages/taro-webpack5-runner/src/plugins/MiniPlugin.ts#L743-L777
42
+ * https://github.com/NervJS/taro/blob/f0e5c39d5f04290db975670411e23c3a396e15f8/packages/taro-webpack5-runner/src/plugins/TaroSingleEntryPlugin.ts#L18-L38
43
+ */
44
+ export declare function emitWechatImplicitChunksForVirtualApp(emitter: WechatChunkEmitter, context: VitePluginTaroBuildContext, cleanId: string): void;
45
+ /**
46
+ * Builds the generated WeChat app entry that registers Taro's React App config.
47
+ * vite-plugin-taro omits Taro's generated pxTransform initialization because styles are handled by Tailwind.
48
+ *
49
+ * https://github.com/NervJS/taro/blob/f0e5c39d5f04290db975670411e23c3a396e15f8/packages/taro-loader/src/app.ts#L54-L63
50
+ */
51
+ export declare function createWxAppEntry(context: VitePluginTaroBuildContext): string;
52
+ /**
53
+ * Builds a generated WeChat page entry that registers Taro's Page config.
54
+ *
55
+ * https://github.com/NervJS/taro/blob/f0e5c39d5f04290db975670411e23c3a396e15f8/packages/taro-loader/src/page.ts#L52-L78
56
+ */
57
+ export declare function createWxPageEntry(pageOption: VitePluginTaroPageOption): string;
58
+ /**
59
+ * Builds the generated JS companion for comp.wxml/comp.json. Without it WeChat
60
+ * can load recursive markup, but it will not have Taro's properties or `eh` event
61
+ * dispatch method.
62
+ *
63
+ * https://github.com/NervJS/taro/blob/f0e5c39d5f04290db975670411e23c3a396e15f8/packages/taro-webpack5-runner/src/template/comp.ts#L1-L4
64
+ */
65
+ export declare function createWxCompEntry(): string;
66
+ /**
67
+ * Creates Taro-style Mini Program template/config/style companion files.
68
+ *
69
+ * https://github.com/NervJS/taro/blob/f0e5c39d5f04290db975670411e23c3a396e15f8/packages/taro-platform-weapp/src/program.ts#L33-L55
70
+ * https://github.com/NervJS/taro/blob/f0e5c39d5f04290db975670411e23c3a396e15f8/packages/taro-webpack5-runner/src/plugins/MiniPlugin.ts#L1198-L1311
71
+ * https://github.com/NervJS/taro/blob/f0e5c39d5f04290db975670411e23c3a396e15f8/packages/taro-webpack5-runner/src/plugins/MiniPlugin.ts#L1346-L1390
72
+ */
73
+ export declare function emitWechatAssets(emitter: WechatAssetEmitter, bundle: WechatBundle, context: VitePluginTaroBuildContext): void;
74
+ export {};
@@ -88,8 +88,6 @@ function createWechatTaroDefines() {
88
88
  'process.env.TARO_ENV': JSON.stringify('weapp'),
89
89
  'process.env.TARO_PLATFORM': JSON.stringify('mini'),
90
90
  'process.env.TARO_VERSION': JSON.stringify(taroVersion),
91
- IS_H5: 'false',
92
- IS_WEAPP: 'true',
93
91
  ENABLE_ADJACENT_HTML: 'false',
94
92
  ENABLE_CLONE_NODE: 'false',
95
93
  ENABLE_CONTAINS: 'false',
@@ -0,0 +1,38 @@
1
+ /** Plain JSON object emitted into Mini Program/Web config payloads. */
2
+ export type JsonObject = Record<string, unknown>;
3
+ /** Build target handled by this plugin. */
4
+ export type VitePluginTaroTarget = 'wx' | 'h5';
5
+ /** Describes one React-backed page shared by WeChat Mini Program and Web builds. */
6
+ export type VitePluginTaroPageOption = {
7
+ /**
8
+ * Page route and output path, without file extension.
9
+ * Example: "pages/index/index" emits pages/index/index.{js,json,wxml,wxss}
10
+ * for WeChat and becomes the Web router path.
11
+ */
12
+ path: string;
13
+ /** Page JSON config merged into WeChat JSON and Web route config. */
14
+ config: JsonObject;
15
+ };
16
+ /** Required build inputs for the custom Vite/Rolldown Taro renderer plugin. */
17
+ export interface VitePluginTaroOptions {
18
+ /** Active target for this Vite invocation. */
19
+ target: VitePluginTaroTarget;
20
+ /** Source file that default-exports the root React app component. */
21
+ app: string;
22
+ /** Ordered page list; also becomes app.json.pages and Web route order. */
23
+ pages: VitePluginTaroPageOption[];
24
+ /** Base app.json content. Its pages field is overwritten from options.pages. */
25
+ appJson: JsonObject;
26
+ /** project.config.json content emitted at the Mini Program root. */
27
+ projectConfigJson: JsonObject;
28
+ /** sitemap.json content emitted at the Mini Program root. */
29
+ sitemapJson: JsonObject;
30
+ }
31
+ export type VitePluginTaroBuildContext = {
32
+ target: VitePluginTaroTarget;
33
+ appComponentImport: string;
34
+ pages: VitePluginTaroPageOption[];
35
+ appConfig: JsonObject;
36
+ projectConfigJson: JsonObject;
37
+ sitemapJson: JsonObject;
38
+ };
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Derives a page component import from a Taro-style page path.
3
+ *
4
+ * https://github.com/NervJS/taro/blob/f0e5c39d5f04290db975670411e23c3a396e15f8/packages/taro-webpack5-runner/src/plugins/MiniPlugin.ts#L660-L668
5
+ * https://github.com/NervJS/taro/blob/f0e5c39d5f04290db975670411e23c3a396e15f8/packages/taro-webpack5-runner/src/utils/app.ts#L74-L90
6
+ * https://github.com/NervJS/taro/blob/f0e5c39d5f04290db975670411e23c3a396e15f8/packages/taro-loader/src/h5.ts#L12-L21
7
+ */
8
+ export declare function createPageComponentImport(pagePath: string): string;
9
+ /**
10
+ * Converts a local file path into a Vite file-system import specifier.
11
+ *
12
+ * Rolldown does not reliably resolve raw Windows absolute paths from virtual
13
+ * module source, so generated imports use Vite's /@fs/ prefix instead.
14
+ */
15
+ export declare function toImportPath(filePath: string): string;
16
+ /**
17
+ * Removes Rollup/Vite's internal virtual-module prefix before ID comparisons.
18
+ */
19
+ export declare function stripVirtualPrefix(id: string): string;
20
+ /**
21
+ * Uses Taro-style slash normalization, plus Vite query-string stripping for module IDs.
22
+ *
23
+ * https://github.com/NervJS/taro/blob/f0e5c39d5f04290db975670411e23c3a396e15f8/packages/taro-helper/src/utils.ts#L32-L34
24
+ */
25
+ export declare function normalizeModuleId(id: string): string;
@@ -0,0 +1,3 @@
1
+ export declare const virtualTaroApiId = "virtual:taro/api";
2
+ export declare const virtualTaroComponentsId = "virtual:taro/components";
3
+ export declare function resolvePublicVirtualModuleId(id: string): string | undefined;
@@ -0,0 +1,7 @@
1
+ import type { PluginOption } from 'vite';
2
+ import type { VitePluginTaroOptions } from './types.ts';
3
+ /**
4
+ * Creates the Vite/Rolldown plugin that emits either WeChat Mini Program files
5
+ * or a Taro Web app using the official Taro runtime packages.
6
+ */
7
+ export default function vitePluginTaro(options: VitePluginTaroOptions): PluginOption[];
package/dist/vite.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ export type { VitePluginTaroOptions, VitePluginTaroPageOption, VitePluginTaroTarget } from './vite/types.ts';
2
+ export { default } from './vite/vite-plugin-taro.ts';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite-plugin-taro",
3
- "version": "0.2.1",
3
+ "version": "0.2.2",
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",
@@ -15,9 +15,10 @@
15
15
  "homepage": "https://github.com/sep2/vite-plugin-taro/tree/main/packages/vite-plugin-taro#readme",
16
16
  "main": "./dist/vite.js",
17
17
  "module": "./dist/vite.js",
18
+ "types": "./dist/vite.d.ts",
18
19
  "exports": {
19
20
  ".": {
20
- "types": "./src/vite.ts",
21
+ "types": "./dist/vite.d.ts",
21
22
  "import": "./dist/vite.js",
22
23
  "default": "./dist/vite.js"
23
24
  },
@@ -64,8 +65,8 @@
64
65
  "babel-plugin-transform-taroapi": "^4.2.0",
65
66
  "tailwindcss": "^4.3.1",
66
67
  "weapp-tailwindcss": "^5.0.13",
67
- "@tarojs/react": "npm:vite-plugin-taro-react@0.2.1",
68
- "@tarojs/plugin-framework-react": "npm:vite-plugin-taro-plugin-framework-react@0.2.1"
68
+ "@tarojs/plugin-framework-react": "npm:vite-plugin-taro-plugin-framework-react@0.2.2",
69
+ "@tarojs/react": "npm:vite-plugin-taro-react@0.2.2"
69
70
  },
70
71
  "peerDependencies": {
71
72
  "react": "^19.0.0",
@@ -140,8 +140,6 @@ function createH5TaroDefines(): Record<string, string> {
140
140
  'process.env.SUPPORT_TARO_POLYFILL': JSON.stringify('disabled'),
141
141
  'process.env.TARO_ENV': JSON.stringify('h5'),
142
142
  'process.env.TARO_PLATFORM': JSON.stringify('web'),
143
- IS_H5: 'true',
144
- IS_WEAPP: 'false',
145
143
  'process.env.SUPPORT_DINGTALK_NAVIGATE': JSON.stringify('disabled'),
146
144
  DEPRECATED_ADAPTER_COMPONENT: 'false'
147
145
  }
@@ -99,8 +99,6 @@ function createWechatTaroDefines(): Record<string, string> {
99
99
  'process.env.TARO_ENV': JSON.stringify('weapp'),
100
100
  'process.env.TARO_PLATFORM': JSON.stringify('mini'),
101
101
  'process.env.TARO_VERSION': JSON.stringify(taroVersion),
102
- IS_H5: 'false',
103
- IS_WEAPP: 'true',
104
102
  ENABLE_ADJACENT_HTML: 'false',
105
103
  ENABLE_CLONE_NODE: 'false',
106
104
  ENABLE_CONTAINS: 'false',