vite-plugin-taro 0.3.2 → 0.4.1
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 +44 -0
- package/README.md +22 -497
- package/client.d.ts +9 -0
- package/dist/node/plugins/client/client-taro.d.ts +4 -0
- package/dist/node/plugins/client/client-taro.js +19 -0
- package/dist/node/plugins/client/constant.d.ts +4 -0
- package/dist/node/plugins/client/constant.js +4 -0
- package/dist/node/plugins/conditional/conditional-directives.d.ts +4 -0
- package/dist/node/plugins/{conditional-directives.js → conditional/conditional-directives.js} +27 -11
- package/dist/node/plugins/css/plugins.d.ts +4 -0
- package/dist/node/plugins/css/plugins.js +84 -0
- package/dist/node/plugins/h5/constant.d.ts +2 -0
- package/dist/node/plugins/h5/constant.js +3 -0
- package/dist/node/plugins/h5/plugins.d.ts +4 -0
- package/dist/node/plugins/h5/plugins.js +161 -0
- package/dist/node/plugins/h5/resolver/module-resolver.d.ts +14 -0
- package/dist/node/plugins/h5/resolver/module-resolver.js +19 -0
- package/dist/node/plugins/h5/transform-app.d.ts +10 -0
- package/dist/node/plugins/h5/transform-app.js +48 -0
- package/dist/node/plugins/wx/dev/dev-host.d.ts +15 -0
- package/dist/node/plugins/wx/dev/dev-host.js +352 -0
- package/dist/node/plugins/wx/dev/hmr-files.d.ts +28 -0
- package/dist/node/plugins/wx/dev/hmr-files.js +34 -0
- package/dist/node/plugins/wx/dev/patch-publisher.d.ts +22 -0
- package/dist/node/plugins/wx/dev/patch-publisher.js +40 -0
- package/dist/node/plugins/wx/dev/plugin.d.ts +7 -0
- package/dist/node/plugins/wx/dev/plugin.js +73 -0
- package/dist/node/plugins/wx/dev/react-refresh.d.ts +20 -0
- package/dist/node/plugins/wx/dev/react-refresh.js +198 -0
- package/dist/node/plugins/wx/module.d.ts +45 -0
- package/dist/node/plugins/wx/module.js +67 -0
- package/dist/node/plugins/wx/native/compile-native-component-interface.d.ts +21 -0
- package/dist/node/plugins/wx/native/compile-native-component-interface.js +29 -0
- package/dist/node/plugins/wx/native/create-native-component-output.d.ts +15 -0
- package/dist/node/plugins/wx/native/create-native-component-output.js +39 -0
- package/dist/node/plugins/wx/native/native-component-assets.d.ts +26 -0
- package/dist/node/plugins/wx/native/native-component-assets.js +76 -0
- package/dist/node/plugins/wx/native/native-component-interface.d.ts +12 -0
- package/dist/node/plugins/wx/native/native-component-interface.js +201 -0
- package/dist/node/plugins/wx/output/files.d.ts +12 -0
- package/dist/node/plugins/wx/output/files.js +12 -0
- package/dist/node/plugins/wx/output/json.d.ts +14 -0
- package/dist/node/plugins/wx/output/json.js +52 -0
- package/dist/node/plugins/wx/output/relative-root.d.ts +2 -0
- package/dist/node/plugins/wx/output/relative-root.js +6 -0
- package/dist/node/plugins/wx/output/templates.d.ts +7 -0
- package/dist/node/plugins/wx/output/templates.js +100 -0
- package/dist/node/plugins/wx/placement/placer.d.ts +78 -0
- package/dist/node/plugins/wx/placement/placer.js +145 -0
- package/dist/node/plugins/wx/placement/plan.d.ts +46 -0
- package/dist/node/plugins/wx/placement/plan.js +210 -0
- package/dist/node/plugins/wx/plugins.d.ts +4 -0
- package/dist/node/plugins/wx/plugins.js +137 -0
- package/dist/node/plugins/wx/render/capsule-wrapper.d.ts +3 -0
- package/dist/node/plugins/wx/render/capsule-wrapper.js +64 -0
- package/dist/node/plugins/wx/render/capsule.d.ts +4 -0
- package/dist/node/plugins/wx/render/capsule.js +13 -0
- package/dist/node/plugins/wx/render/native.d.ts +9 -0
- package/dist/node/plugins/wx/render/native.js +45 -0
- package/dist/node/plugins/wx/render/transport.d.ts +17 -0
- package/dist/node/plugins/wx/render/transport.js +94 -0
- package/dist/node/plugins/wx/resolve/resolver.d.ts +7 -0
- package/dist/node/plugins/wx/resolve/resolver.js +86 -0
- package/dist/node/plugins/wx/resolve/specialize-bootstrap.d.ts +9 -0
- package/dist/node/plugins/wx/resolve/specialize-bootstrap.js +9 -0
- package/dist/node/plugins/wx/resolve/specialize-page-capsule.d.ts +9 -0
- package/dist/node/plugins/wx/resolve/specialize-page-capsule.js +11 -0
- package/dist/node/utils/constant.d.ts +1 -0
- package/dist/node/utils/constant.js +1 -0
- package/dist/node/utils/memoize.d.ts +122 -0
- package/dist/node/utils/memoize.js +86 -0
- package/dist/node/utils/modules.d.ts +20 -24
- package/dist/node/utils/modules.js +21 -34
- package/dist/node/utils/once.d.ts +10 -0
- package/dist/node/utils/once.js +20 -0
- package/dist/node/utils/packages.d.ts +1 -0
- package/dist/node/utils/packages.js +3 -2
- package/dist/node/utils/project-config.d.ts +3 -0
- package/dist/node/utils/project-config.js +8 -0
- package/dist/node/utils/serialized-task-queue.d.ts +9 -0
- package/dist/node/utils/serialized-task-queue.js +17 -0
- package/dist/node/utils/transform.d.ts +11 -0
- package/dist/node/utils/transform.js +58 -0
- package/dist/node/vite-plugin.d.ts +1 -1
- package/dist/node/vite-plugin.js +11 -27
- package/dist/options.d.ts +3 -4
- package/dist/runtime/{taro → client/taro}/api.d.ts +0 -1
- package/dist/runtime/client/taro/api.js +9 -0
- package/dist/runtime/client/taro/component.d.ts +1 -0
- package/dist/runtime/client/taro/component.js +1 -0
- package/dist/runtime/client/taro/define-native-component.d.ts +7 -0
- package/dist/runtime/client/taro/define-native-component.js +4 -0
- package/dist/runtime/h5/app.d.ts +2 -0
- package/dist/runtime/h5/app.js +15 -0
- package/dist/runtime/h5/taro-runtime.d.ts +1 -1
- package/dist/runtime/h5/taro-runtime.js +1 -4
- package/dist/runtime/wx/amphibious/bootstrap.d.ts +4 -0
- package/dist/runtime/wx/amphibious/bootstrap.js +16 -0
- package/dist/runtime/wx/amphibious/transport.d.ts +2 -0
- package/dist/runtime/wx/amphibious/transport.js +4 -0
- package/dist/runtime/wx/capsule/app.d.ts +2 -0
- package/dist/runtime/wx/capsule/app.js +7 -0
- package/dist/runtime/wx/capsule/component.d.ts +3 -0
- package/dist/runtime/wx/capsule/component.js +4 -0
- package/dist/runtime/wx/capsule/page.d.ts +3 -0
- package/dist/runtime/wx/capsule/page.js +68 -0
- package/dist/runtime/wx/capsule/taro-runtime.d.ts +6 -0
- package/dist/runtime/wx/capsule/taro-runtime.js +6 -0
- package/dist/runtime/wx/dev/dev-runtime.d.ts +1 -0
- package/dist/runtime/wx/dev/dev-runtime.js +246 -0
- package/dist/runtime/wx/native/app.d.ts +1 -0
- package/dist/runtime/wx/native/app.js +3 -0
- package/dist/runtime/wx/native/component.d.ts +1 -0
- package/dist/runtime/wx/native/component.js +3 -0
- package/dist/runtime/wx/native/page.d.ts +1 -0
- package/dist/runtime/wx/native/page.js +4 -0
- package/dist/runtime/wx/systemjs/system-core.d.ts +4 -0
- package/dist/runtime/wx/systemjs/system-core.js +331 -0
- package/package.json +21 -14
- package/src/node/plugins/client/client-taro.ts +23 -0
- package/src/node/plugins/client/constant.ts +5 -0
- package/src/node/plugins/{conditional-directives.ts → conditional/conditional-directives.ts} +33 -13
- package/src/node/plugins/css/plugins.ts +96 -0
- package/src/node/plugins/h5/constant.ts +4 -0
- package/src/node/plugins/h5/plugins.ts +197 -0
- package/src/node/plugins/h5/resolver/module-resolver.ts +32 -0
- package/src/node/plugins/h5/transform-app.ts +90 -0
- package/src/node/plugins/wx/dev/dev-host.ts +448 -0
- package/src/node/plugins/wx/dev/hmr-files.ts +55 -0
- package/src/node/plugins/wx/dev/patch-publisher.ts +49 -0
- package/src/node/plugins/wx/dev/plugin.ts +82 -0
- package/src/node/plugins/wx/dev/react-refresh.ts +227 -0
- package/src/node/plugins/wx/module.ts +98 -0
- package/src/node/plugins/wx/native/compile-native-component-interface.ts +47 -0
- package/src/node/plugins/wx/native/create-native-component-output.ts +57 -0
- package/src/node/plugins/wx/native/native-component-assets.ts +114 -0
- package/src/node/plugins/wx/native/native-component-interface.ts +265 -0
- package/src/node/plugins/wx/output/files.ts +27 -0
- package/src/node/plugins/wx/output/json.ts +79 -0
- package/src/node/plugins/wx/output/relative-root.ts +7 -0
- package/src/node/plugins/wx/output/templates.ts +141 -0
- package/src/node/plugins/wx/placement/placer.ts +172 -0
- package/src/node/plugins/wx/placement/plan.ts +306 -0
- package/src/node/plugins/wx/plugins.ts +165 -0
- package/src/node/plugins/wx/render/capsule-wrapper.ts +86 -0
- package/src/node/plugins/wx/render/capsule.ts +21 -0
- package/src/node/plugins/wx/render/native.ts +84 -0
- package/src/node/plugins/wx/render/transport.ts +157 -0
- package/src/node/plugins/wx/resolve/resolver.ts +125 -0
- package/src/node/plugins/wx/resolve/specialize-bootstrap.ts +27 -0
- package/src/node/plugins/wx/resolve/specialize-page-capsule.ts +29 -0
- package/src/node/utils/constant.ts +1 -0
- package/src/node/utils/memoize.ts +149 -0
- package/src/node/utils/modules.ts +36 -38
- package/src/node/utils/once.ts +21 -0
- package/src/node/utils/packages.ts +3 -2
- package/src/node/utils/project-config.ts +10 -0
- package/src/node/utils/serialized-task-queue.ts +20 -0
- package/src/node/utils/transform.ts +82 -0
- package/src/node/vite-plugin.ts +12 -32
- package/src/options.ts +3 -4
- package/src/runtime/client/taro/api.ts +11 -0
- package/src/runtime/client/taro/component.ts +1 -0
- package/src/runtime/client/taro/define-native-component.ts +15 -0
- package/src/runtime/h5/app.ts +25 -0
- package/src/runtime/h5/taro-runtime.ts +1 -4
- package/src/runtime/wx/amphibious/bootstrap.ts +22 -0
- package/src/runtime/wx/amphibious/transport.ts +10 -0
- package/src/runtime/wx/capsule/app.ts +9 -0
- package/src/runtime/wx/capsule/component.ts +6 -0
- package/src/runtime/wx/capsule/page.ts +96 -0
- package/src/runtime/wx/capsule/taro-runtime.ts +14 -0
- package/src/runtime/wx/dev/dev-runtime.ts +317 -0
- package/src/runtime/wx/native/app.ts +4 -0
- package/src/runtime/wx/native/component.ts +4 -0
- package/src/runtime/wx/native/page.ts +6 -0
- package/src/runtime/wx/systemjs/LICENSE +10 -0
- package/src/runtime/wx/systemjs/system-core.js +370 -0
- package/src/runtime/wx/systemjs/system.d.ts +55 -0
- package/src/runtime/wx/wechat.d.ts +52 -0
- package/README.zh.md +0 -521
- package/dist/node/build-context.d.ts +0 -25
- package/dist/node/build-context.js +0 -47
- package/dist/node/css/css-pipeline.d.ts +0 -35
- package/dist/node/css/css-pipeline.js +0 -154
- package/dist/node/plugins/conditional-directives.d.ts +0 -3
- package/dist/node/plugins/taro-runtime.d.ts +0 -5
- package/dist/node/plugins/taro-runtime.js +0 -18
- package/dist/node/targets/h5/plugin.d.ts +0 -6
- package/dist/node/targets/h5/plugin.js +0 -117
- package/dist/node/targets/h5/virtual-modules.d.ts +0 -5
- package/dist/node/targets/h5/virtual-modules.js +0 -60
- package/dist/node/targets/wx/companion-assets.d.ts +0 -19
- package/dist/node/targets/wx/companion-assets.js +0 -129
- package/dist/node/targets/wx/dev-server/development-session.d.ts +0 -32
- package/dist/node/targets/wx/dev-server/development-session.js +0 -215
- package/dist/node/targets/wx/dev-server/full-build-scheduler.d.ts +0 -14
- package/dist/node/targets/wx/dev-server/full-build-scheduler.js +0 -60
- package/dist/node/targets/wx/dev-server/js-utils.d.ts +0 -5
- package/dist/node/targets/wx/dev-server/js-utils.js +0 -28
- package/dist/node/targets/wx/dev-server/output.d.ts +0 -19
- package/dist/node/targets/wx/dev-server/output.js +0 -44
- package/dist/node/targets/wx/dev-server/rolldown-runtime-source.d.ts +0 -8
- package/dist/node/targets/wx/dev-server/rolldown-runtime-source.js +0 -95
- package/dist/node/targets/wx/dev-server/update-server-state.d.ts +0 -65
- package/dist/node/targets/wx/dev-server/update-server-state.js +0 -116
- package/dist/node/targets/wx/dev-server/update-transport.d.ts +0 -28
- package/dist/node/targets/wx/dev-server/update-transport.js +0 -212
- package/dist/node/targets/wx/dev-server/vite-bundled-dev-adapter.d.ts +0 -44
- package/dist/node/targets/wx/dev-server/vite-bundled-dev-adapter.js +0 -145
- package/dist/node/targets/wx/development-files.d.ts +0 -8
- package/dist/node/targets/wx/development-files.js +0 -8
- package/dist/node/targets/wx/plugin.d.ts +0 -6
- package/dist/node/targets/wx/plugin.js +0 -144
- package/dist/node/targets/wx/react-refresh.d.ts +0 -4
- package/dist/node/targets/wx/react-refresh.js +0 -38
- package/dist/node/targets/wx/virtual-modules.d.ts +0 -16
- package/dist/node/targets/wx/virtual-modules.js +0 -120
- package/dist/node/utils/async.d.ts +0 -8
- package/dist/node/utils/async.js +0 -16
- package/dist/node/utils/filesystem.d.ts +0 -13
- package/dist/node/utils/filesystem.js +0 -43
- package/dist/runtime/taro/api.js +0 -11
- package/dist/runtime/taro/components.d.ts +0 -2
- package/dist/runtime/taro/components.js +0 -2
- package/dist/runtime/wx/page-update.d.ts +0 -6
- package/dist/runtime/wx/page-update.js +0 -157
- package/dist/runtime/wx/taro-runtime.d.ts +0 -5
- package/dist/runtime/wx/taro-runtime.js +0 -6
- package/dist/runtime/wx/update-client-state.d.ts +0 -68
- package/dist/runtime/wx/update-client-state.js +0 -84
- package/dist/runtime/wx/update-client.d.ts +0 -1
- package/dist/runtime/wx/update-client.js +0 -171
- package/src/node/build-context.ts +0 -62
- package/src/node/css/css-pipeline.ts +0 -171
- package/src/node/plugins/taro-runtime.ts +0 -22
- package/src/node/targets/h5/plugin.ts +0 -135
- package/src/node/targets/h5/virtual-modules.ts +0 -71
- package/src/node/targets/wx/companion-assets.ts +0 -174
- package/src/node/targets/wx/dev-server/development-session.ts +0 -271
- package/src/node/targets/wx/dev-server/full-build-scheduler.ts +0 -62
- package/src/node/targets/wx/dev-server/js-utils.ts +0 -33
- package/src/node/targets/wx/dev-server/output.ts +0 -56
- package/src/node/targets/wx/dev-server/rolldown-runtime-source.ts +0 -95
- package/src/node/targets/wx/dev-server/update-server-state.ts +0 -183
- package/src/node/targets/wx/dev-server/update-transport.ts +0 -261
- package/src/node/targets/wx/dev-server/vite-bundled-dev-adapter.ts +0 -203
- package/src/node/targets/wx/development-files.ts +0 -11
- package/src/node/targets/wx/plugin.ts +0 -164
- package/src/node/targets/wx/react-refresh.ts +0 -51
- package/src/node/targets/wx/virtual-modules.ts +0 -152
- package/src/node/utils/async.ts +0 -19
- package/src/node/utils/filesystem.ts +0 -45
- package/src/runtime/taro/api.ts +0 -13
- package/src/runtime/taro/components.ts +0 -2
- package/src/runtime/wx/page-update.ts +0 -230
- package/src/runtime/wx/react-refresh.d.ts +0 -20
- package/src/runtime/wx/taro-runtime.ts +0 -7
- package/src/runtime/wx/update-client-state.ts +0 -138
- package/src/runtime/wx/update-client.ts +0 -223
package/dist/node/vite-plugin.js
CHANGED
|
@@ -1,33 +1,17 @@
|
|
|
1
1
|
import react from '@vitejs/plugin-react';
|
|
2
|
-
import {
|
|
3
|
-
import { createConditionalDirectivePlugin } from './plugins/conditional-directives.js';
|
|
4
|
-
import {
|
|
5
|
-
import { createH5TargetPlugins
|
|
6
|
-
import { createWxTargetPlugins
|
|
7
|
-
/** Creates the Vite plugins for
|
|
2
|
+
import { createClientTaroPlugin } from './plugins/client/client-taro.js';
|
|
3
|
+
import { createConditionalDirectivePlugin } from './plugins/conditional/conditional-directives.js';
|
|
4
|
+
import { createCssPlugins } from './plugins/css/plugins.js';
|
|
5
|
+
import { createH5TargetPlugins } from './plugins/h5/plugins.js';
|
|
6
|
+
import { createWxTargetPlugins } from './plugins/wx/plugins.js';
|
|
7
|
+
/** Creates the Vite plugins for one Taro target. */
|
|
8
8
|
export default function vitePluginTaro(options) {
|
|
9
|
-
const context = new BuildContext(options);
|
|
10
9
|
return [
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
...context.css.plugins,
|
|
10
|
+
createConditionalDirectivePlugin(options.target),
|
|
11
|
+
createClientTaroPlugin(),
|
|
12
|
+
...createCssPlugins(options.target),
|
|
15
13
|
...react(),
|
|
16
|
-
...(
|
|
17
|
-
...(
|
|
14
|
+
...(options.target === 'wx' ? createWxTargetPlugins(options) : []),
|
|
15
|
+
...(options.target === 'h5' ? createH5TargetPlugins(options) : [])
|
|
18
16
|
];
|
|
19
17
|
}
|
|
20
|
-
/** Establishes build mode and resolved Vite state before target hooks consume the context. */
|
|
21
|
-
function createBuildCoordinator(context) {
|
|
22
|
-
return {
|
|
23
|
-
name: 'vite-plugin-taro:build',
|
|
24
|
-
enforce: 'pre',
|
|
25
|
-
config(_, environment) {
|
|
26
|
-
context.configure(environment);
|
|
27
|
-
return context.project.target === 'wx' ? createWxViteConfig(context) : createH5ViteConfig(context);
|
|
28
|
-
},
|
|
29
|
-
configResolved(config) {
|
|
30
|
-
context.resolve(config);
|
|
31
|
-
}
|
|
32
|
-
};
|
|
33
|
-
}
|
package/dist/options.d.ts
CHANGED
|
@@ -1,15 +1,14 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/** A JSON object used by generated target configs. */
|
|
2
2
|
export type JsonObject = Record<string, unknown>;
|
|
3
3
|
/** Build target handled by this plugin. */
|
|
4
4
|
export type VitePluginTaroTarget = 'wx' | 'h5';
|
|
5
|
-
/**
|
|
5
|
+
/** Configures one Taro page. */
|
|
6
6
|
export type VitePluginTaroPageOption = {
|
|
7
7
|
/** Taro route and output path without a file extension. */
|
|
8
8
|
path: string;
|
|
9
|
-
/** Page config merged into the generated target config. */
|
|
10
9
|
config: JsonObject;
|
|
11
10
|
};
|
|
12
|
-
/**
|
|
11
|
+
/** Configures the Vite Taro plugin. */
|
|
13
12
|
export interface VitePluginTaroOptions {
|
|
14
13
|
target: VitePluginTaroTarget;
|
|
15
14
|
app: string;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import '@tarojs/plugin-framework-react/dist/runtime';
|
|
2
|
+
import { hooks } from '@tarojs/runtime';
|
|
3
|
+
import Taro from '@tarojs/taro';
|
|
4
|
+
if (hooks.isExist('initNativeApi')) {
|
|
5
|
+
hooks.call('initNativeApi', Taro);
|
|
6
|
+
}
|
|
7
|
+
// @ts-expect-error @tarojs/taro declares export= types, but the facade also exposes its runtime named exports.
|
|
8
|
+
export * from '@tarojs/taro';
|
|
9
|
+
export default Taro;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '@tarojs/components';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '@tarojs/components';
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { ComponentType, PropsWithChildren } from 'react';
|
|
2
|
+
export type NativeComponentEvent<Detail> = {
|
|
3
|
+
readonly detail: Detail;
|
|
4
|
+
};
|
|
5
|
+
/** Defines a typed JSX interface from a static `() => import('./relative-entry.js')` reference. */
|
|
6
|
+
export declare function defineNativeComponent(loadEntry: () => Promise<unknown>): ComponentType<PropsWithChildren>;
|
|
7
|
+
export declare function defineNativeComponent<const Props extends object>(loadEntry: () => Promise<unknown>): ComponentType<PropsWithChildren<Props>>;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/** biome-ignore-all assist/source/organizeImports: keep side effect orders */
|
|
2
|
+
import { createHashHistory, createReactApp, createRouter, handleAppMount, window } from './taro-runtime.js';
|
|
3
|
+
import React from 'react';
|
|
4
|
+
import ReactDOM from 'react-dom/client';
|
|
5
|
+
// @ts-expect-error: The H5 build resolves this private App component.
|
|
6
|
+
import AppComponent from '\0vpt:app-component';
|
|
7
|
+
const browserWindow = window;
|
|
8
|
+
const config = __VITE_PLUGIN_TARO_H5_APP_CONFIG__;
|
|
9
|
+
browserWindow.__taroAppConfig = config;
|
|
10
|
+
config.routes = __VITE_PLUGIN_TARO_H5_ROUTES__;
|
|
11
|
+
const app = createReactApp(AppComponent, React, ReactDOM, config);
|
|
12
|
+
const history = createHashHistory({ window: browserWindow });
|
|
13
|
+
handleAppMount(config, history);
|
|
14
|
+
// @ts-expect-error Taro's implementation receives the React adapter object despite declaring a string.
|
|
15
|
+
createRouter(history, app, config, React);
|
|
@@ -2,5 +2,5 @@
|
|
|
2
2
|
import '@tarojs/components/global.css';
|
|
3
3
|
import '@tarojs/components/dist/taro-components/taro-components.css';
|
|
4
4
|
export { createReactApp } from '@tarojs/plugin-framework-react/dist/runtime';
|
|
5
|
-
export {
|
|
5
|
+
export { createHashHistory, createRouter, handleAppMount } from '@tarojs/router';
|
|
6
6
|
export { window } from '@tarojs/runtime';
|
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
/** Runtime exports consumed by the generated H5 entry. */
|
|
2
2
|
import '@tarojs/components/global.css';
|
|
3
3
|
import '@tarojs/components/dist/taro-components/taro-components.css';
|
|
4
|
-
// Import the CSS files directly instead of @tarojs/plugin-platform-h5/dist/runtime:
|
|
5
|
-
// that runtime adds only taro-components.css plus optional polyfills, while generated H5 entries also need global.css.
|
|
6
|
-
// @ts-expect-error Taro exposes createReactApp from this runtime-only deep entry without types.
|
|
7
4
|
export { createReactApp } from '@tarojs/plugin-framework-react/dist/runtime';
|
|
8
|
-
export {
|
|
5
|
+
export { createHashHistory, createRouter, handleAppMount } from '@tarojs/router';
|
|
9
6
|
export { window } from '@tarojs/runtime';
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// Install the minimal SystemJS loader and its synchronous-import extension before any native entry requests a capsule.
|
|
2
|
+
import '../systemjs/system-core.js';
|
|
3
|
+
import { transport } from './transport.js';
|
|
4
|
+
/** Shares one App configuration object between the specialized bootstrap and App capsule. */
|
|
5
|
+
export const appConfig = __VITE_PLUGIN_TARO_APP_CONFIG__;
|
|
6
|
+
// WX has no modulepreload transport. Genuine application import() boundaries retain System.import() and may load
|
|
7
|
+
// asynchronous subpackage or top-level-await graphs through this identity wrapper.
|
|
8
|
+
export const __vitePreload = (load) => load();
|
|
9
|
+
// SystemJS installs on WeChat's `global` object; its properties are not lexical bindings.
|
|
10
|
+
const installedSystem = global.System;
|
|
11
|
+
if (!installedSystem) {
|
|
12
|
+
throw new Error('SystemJS failed to initialize in the WeChat runtime');
|
|
13
|
+
}
|
|
14
|
+
// Transport returns synchronous registrations for main-package capsules and amphibious modules, and promise-like
|
|
15
|
+
// registrations only for capsules that physically live in generated subpackages.
|
|
16
|
+
installedSystem.instantiate = transport;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
// Transport itself executes only as native CommonJS. It lives beside bootstrap because together they implement the
|
|
2
|
+
// amphibious boundary that publishes native namespaces to SystemJS without re-evaluating their module bodies.
|
|
3
|
+
/** Dispatches to one generated literal require and bridges amphibious CommonJS namespaces inline. */
|
|
4
|
+
export const transport = __VITE_PLUGIN_TARO_TRANSPORT__;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
// biome-ignore assist/source/organizeImports: Taro must initialize before the App component.
|
|
2
|
+
import { createReactApp, ReactDOM } from './taro-runtime.js';
|
|
3
|
+
import React from 'react';
|
|
4
|
+
import { appConfig } from '../amphibious/bootstrap.js';
|
|
5
|
+
// @ts-expect-error: The wx build resolves this private App component.
|
|
6
|
+
import AppComponent from '\0vpt:app-component';
|
|
7
|
+
export default createReactApp(AppComponent, React, ReactDOM, appConfig);
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
// App and Page shells activate independently; make Current.app initialization an explicit prerequisite for Page mount.
|
|
2
|
+
import './app.js';
|
|
3
|
+
// @ts-expect-error: The wx build replaces this private import with the configured Page component.
|
|
4
|
+
import PageComponent from '\0vpt:page-component';
|
|
5
|
+
import { Current, createPageConfig, document, injectPageInstance } from './taro-runtime.js';
|
|
6
|
+
const config = createPageConfig(PageComponent, __VITE_PLUGIN_TARO_PAGE_PATH__, { root: { cn: [] } }, __VITE_PLUGIN_TARO_PAGE_CONFIG__);
|
|
7
|
+
export default config;
|
|
8
|
+
/** Forwards a call with the native page instance as `this`, matching Taro's invocation. */
|
|
9
|
+
function forward(handler, receiver, args) {
|
|
10
|
+
;
|
|
11
|
+
handler?.apply(receiver, args);
|
|
12
|
+
}
|
|
13
|
+
// DevTools re-executes the page and replays the replacement lifecycle on every edit. Taro's
|
|
14
|
+
// onUnload unmounts the React tree and onLoad mounts a fresh one, destroying state. While
|
|
15
|
+
// the runtime says a patch was just delivered, the pair is intercepted instead: onUnload
|
|
16
|
+
// captures the surviving page identity, and onLoad restores it onto the replacement native
|
|
17
|
+
// instance and rebinds the retained tree to it (pageElement.ctx + a full re-render). The
|
|
18
|
+
// capsule module is cached across re-executions, so this closure holds the capture.
|
|
19
|
+
// Ordinary navigation (no patch) passes through unchanged. The wrappers are regular
|
|
20
|
+
// functions so the native page instance (`this`) reaches the original handlers.
|
|
21
|
+
if (typeof __rolldown_runtime__ !== 'undefined') {
|
|
22
|
+
const originalOnUnload = config.onUnload;
|
|
23
|
+
const originalOnLoad = config.onLoad;
|
|
24
|
+
const originalOnShow = config.onShow;
|
|
25
|
+
let captured;
|
|
26
|
+
config.onUnload = function (...args) {
|
|
27
|
+
if (__rolldown_runtime__.isHotReloading()) {
|
|
28
|
+
const instance = this;
|
|
29
|
+
captured = {
|
|
30
|
+
$taroPath: instance.$taroPath,
|
|
31
|
+
$taroParams: instance.$taroParams
|
|
32
|
+
};
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
forward(originalOnUnload, this, args);
|
|
36
|
+
};
|
|
37
|
+
config.onLoad = function (...args) {
|
|
38
|
+
if (__rolldown_runtime__.isHotReloading() && captured) {
|
|
39
|
+
// Restore the surviving page identity onto the replacement native instance: the
|
|
40
|
+
// re-loaded $taroPath embeds a fresh timestamp, so without this the tree and the
|
|
41
|
+
// native side would disagree on the page key.
|
|
42
|
+
const instance = this;
|
|
43
|
+
instance.$taroPath = captured.$taroPath;
|
|
44
|
+
instance.$taroParams = captured.$taroParams;
|
|
45
|
+
// Rebind the retained tree to the replacement receiver and resync the native
|
|
46
|
+
// data: updateChildNodes enqueues the full hydrated node tree (root.cn) — the
|
|
47
|
+
// surviving tree's mutations were consumed long ago, so without it the payload
|
|
48
|
+
// queue is empty and the new receiver renders nothing.
|
|
49
|
+
injectPageInstance(instance, captured.$taroPath);
|
|
50
|
+
Current.page = instance;
|
|
51
|
+
const pageElement = document.getElementById(captured.$taroPath);
|
|
52
|
+
pageElement.ctx = instance;
|
|
53
|
+
pageElement.updateChildNodes();
|
|
54
|
+
pageElement.performUpdate(true);
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
forward(originalOnLoad, this, args);
|
|
58
|
+
};
|
|
59
|
+
config.onShow = function (...args) {
|
|
60
|
+
if (__rolldown_runtime__.isHotReloading()) {
|
|
61
|
+
// The window ends at the first show; the user's onShow must not re-run on a
|
|
62
|
+
// synthetic re-execution (it could reset state).
|
|
63
|
+
__rolldown_runtime__.clearHotReloading();
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
forward(originalOnShow, this, args);
|
|
67
|
+
};
|
|
68
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/** biome-ignore-all assist/source/organizeImports: keep side effect orders */
|
|
2
|
+
/** Taro runtime exports shared by the App, Page, and recursive Component capsules. */
|
|
3
|
+
import '@tarojs/plugin-platform-weapp/dist/runtime.js';
|
|
4
|
+
export { createReactApp } from '@tarojs/plugin-framework-react/dist/runtime';
|
|
5
|
+
export { default as ReactDOM } from '@tarojs/react';
|
|
6
|
+
export { createPageConfig, createRecursiveComponentConfig, Current, document, injectPageInstance } from '@tarojs/runtime';
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/** biome-ignore-all assist/source/organizeImports: keep side effect orders */
|
|
2
|
+
/** Taro runtime exports shared by the App, Page, and recursive Component capsules. */
|
|
3
|
+
import '@tarojs/plugin-platform-weapp/dist/runtime.js';
|
|
4
|
+
export { createReactApp } from '@tarojs/plugin-framework-react/dist/runtime';
|
|
5
|
+
export { default as ReactDOM } from '@tarojs/react';
|
|
6
|
+
export { createPageConfig, createRecursiveComponentConfig, Current, document, injectPageInstance } from '@tarojs/runtime';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
// WX dev runtime — bundled and injected verbatim at the end of the shared Rolldown
|
|
2
|
+
// runtime chunk (`assets/rolldown-runtime.js`, required first by every chunk). Defines the
|
|
3
|
+
// App-global `__rolldown_runtime__` that generated modules call.
|
|
4
|
+
//
|
|
5
|
+
// The `DevRuntime` base class is injected into the chunk by Rolldown's dev-mode
|
|
6
|
+
// transform, so the WX host only extends it.
|
|
7
|
+
//
|
|
8
|
+
// Delivery is passive: every valid hmr/patches.js suffix is acknowledged by Rolldown
|
|
9
|
+
// sequence, then applied synchronously before the Page continues evaluating. Already-applied
|
|
10
|
+
// sequences are ignored when another Page requires the same physical file.
|
|
11
|
+
/**
|
|
12
|
+
* Per-module hot state, mirroring Rolldown's web runtime: accept is a passive registration;
|
|
13
|
+
* the propagation invokes the previous execution's callbacks with the fresh exports.
|
|
14
|
+
*/
|
|
15
|
+
class WxHotContext {
|
|
16
|
+
_internal = {
|
|
17
|
+
updateStyle() { },
|
|
18
|
+
removeStyle() { }
|
|
19
|
+
};
|
|
20
|
+
/** Registered self-accept callbacks; a bare accept is represented by a no-op callback. */
|
|
21
|
+
acceptCallbacks = [];
|
|
22
|
+
/** Set when a callback rejects a Refresh boundary; the current update then rebuilds. */
|
|
23
|
+
invalidationReason;
|
|
24
|
+
accept(callback) {
|
|
25
|
+
this.acceptCallbacks.push(callback ?? (() => { }));
|
|
26
|
+
}
|
|
27
|
+
hasAccepts() {
|
|
28
|
+
return this.acceptCallbacks.length > 0;
|
|
29
|
+
}
|
|
30
|
+
/** Invokes this old context's callbacks and returns any requested invalidation. */
|
|
31
|
+
runAccept(moduleExports) {
|
|
32
|
+
for (const callback of this.acceptCallbacks) {
|
|
33
|
+
callback(moduleExports);
|
|
34
|
+
}
|
|
35
|
+
return this.invalidationReason;
|
|
36
|
+
}
|
|
37
|
+
invalidate(reason) {
|
|
38
|
+
this.invalidationReason = reason ?? 'the accepting module invalidated the update';
|
|
39
|
+
}
|
|
40
|
+
// Vite's generated CSS module calls hot.prune with its style teardown; the physical
|
|
41
|
+
// rebuild replaces styles wholesale, so it is a no-op.
|
|
42
|
+
prune(_callback) { }
|
|
43
|
+
}
|
|
44
|
+
/** The WX host: extends the Rolldown contract instead of reimplementing it. */
|
|
45
|
+
class WxDevRuntime extends DevRuntime {
|
|
46
|
+
hmrInfo;
|
|
47
|
+
/** Highest Rolldown sequence successfully applied. */
|
|
48
|
+
appliedSeq = 0;
|
|
49
|
+
/** Active hot contexts per module id; the propagation invokes their callbacks. */
|
|
50
|
+
moduleHotContexts = new Map();
|
|
51
|
+
constructor() {
|
|
52
|
+
// The base has no messenger: the engine tracks per-client shipped payloads instead
|
|
53
|
+
// of executed module ids, so the wx host registers the client session itself.
|
|
54
|
+
super('');
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Generated code always calls this before registerModule and reads `_internal` from the
|
|
58
|
+
* return value. Mirrors Rolldown's web runtime: each execution immediately replaces the
|
|
59
|
+
* module's hot context; the apply plan has already captured the previous callbacks.
|
|
60
|
+
*/
|
|
61
|
+
createModuleHotContext(moduleId) {
|
|
62
|
+
const hotContext = new WxHotContext();
|
|
63
|
+
this.moduleHotContexts.set(moduleId, hotContext);
|
|
64
|
+
return hotContext;
|
|
65
|
+
}
|
|
66
|
+
/** Computes accepting boundaries and every executed module that must be re-armed. */
|
|
67
|
+
computeHmrUpdate(changedIds) {
|
|
68
|
+
// Mutable traversal accumulators are confined to one synchronous update plan.
|
|
69
|
+
const boundaries = [];
|
|
70
|
+
const updateSet = new Set();
|
|
71
|
+
for (const changedId of changedIds) {
|
|
72
|
+
if (!this.isExecuted(changedId))
|
|
73
|
+
continue;
|
|
74
|
+
// Mutable only for the current DFS path, providing O(1) cycle checks.
|
|
75
|
+
const path = new Set([changedId]);
|
|
76
|
+
const fullReloadReason = this.bubble(changedId, path, updateSet, boundaries);
|
|
77
|
+
if (fullReloadReason) {
|
|
78
|
+
throw new Error(fullReloadReason);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
return boundaries.length > 0 ? { boundaries, updateSet } : undefined;
|
|
82
|
+
}
|
|
83
|
+
/** Walks executed importers until an accepting boundary is found. */
|
|
84
|
+
bubble(moduleId, path, updateSet, boundaries) {
|
|
85
|
+
if (updateSet.has(moduleId))
|
|
86
|
+
return undefined;
|
|
87
|
+
updateSet.add(moduleId);
|
|
88
|
+
if (this.moduleHotContexts.get(moduleId)?.hasAccepts()) {
|
|
89
|
+
boundaries.push(moduleId);
|
|
90
|
+
return undefined;
|
|
91
|
+
}
|
|
92
|
+
const importers = this.getImporters(moduleId).filter((importer) => this.isExecuted(importer));
|
|
93
|
+
if (importers.length === 0) {
|
|
94
|
+
return `no HMR boundary found for module ${moduleId}`;
|
|
95
|
+
}
|
|
96
|
+
for (const importer of importers) {
|
|
97
|
+
if (path.has(importer)) {
|
|
98
|
+
return `circular HMR propagation between ${moduleId} and ${importer}`;
|
|
99
|
+
}
|
|
100
|
+
path.add(importer);
|
|
101
|
+
const fullReloadReason = this.bubble(importer, path, updateSet, boundaries);
|
|
102
|
+
path.delete(importer);
|
|
103
|
+
if (fullReloadReason)
|
|
104
|
+
return fullReloadReason;
|
|
105
|
+
}
|
|
106
|
+
return undefined;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Applies one patch in three phases: capture old contexts, evict the whole update set,
|
|
110
|
+
* then re-run accepting modules and pass their fresh exports to the old contexts.
|
|
111
|
+
*/
|
|
112
|
+
applyHmrUpdate(changedIds) {
|
|
113
|
+
const update = this.computeHmrUpdate(changedIds);
|
|
114
|
+
if (!update)
|
|
115
|
+
return;
|
|
116
|
+
for (const moduleId of update.updateSet) {
|
|
117
|
+
if (!this.hasFactory(moduleId)) {
|
|
118
|
+
throw new Error(`no HMR factory for module ${moduleId}`);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
const applies = update.boundaries.map((moduleId) => ({
|
|
122
|
+
moduleId,
|
|
123
|
+
hotContext: this.moduleHotContexts.get(moduleId)
|
|
124
|
+
}));
|
|
125
|
+
// This eviction must happen before initModule: otherwise its cache gate returns the
|
|
126
|
+
// old exports and the freshly registered factory never executes.
|
|
127
|
+
for (const moduleId of update.updateSet) {
|
|
128
|
+
this.removeModuleCache(moduleId);
|
|
129
|
+
}
|
|
130
|
+
for (const { moduleId, hotContext } of applies) {
|
|
131
|
+
const invalidationReason = hotContext?.runAccept(this.initModule(moduleId));
|
|
132
|
+
if (invalidationReason) {
|
|
133
|
+
throw new Error(`${moduleId}: ${invalidationReason}`);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
/** Consumed once per App heap from hmr/info.js; the host buildId is the delivery identity. */
|
|
138
|
+
initialize(info) {
|
|
139
|
+
if (this.hmrInfo) {
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
this.hmrInfo = info;
|
|
143
|
+
// Anchor: the host publishes only after the runtime reports its delivery position.
|
|
144
|
+
void this.sendReport({ kind: 'delivery', seq: this.appliedSeq });
|
|
145
|
+
}
|
|
146
|
+
/** True between a patch delivery and the next page show: a hot reload is in progress. */
|
|
147
|
+
hotReloading = false;
|
|
148
|
+
/** The capsule wrapper asks this during the synthetic lifecycle of a hot reload. */
|
|
149
|
+
isHotReloading() {
|
|
150
|
+
return this.hotReloading;
|
|
151
|
+
}
|
|
152
|
+
/** The wrapped onShow ends the hot reload after the replacement cycle. */
|
|
153
|
+
clearHotReloading() {
|
|
154
|
+
this.hotReloading = false;
|
|
155
|
+
}
|
|
156
|
+
/** The only direct effect of hmr/patches.js: validate, store, acknowledge, and apply. */
|
|
157
|
+
storePatches(payload) {
|
|
158
|
+
const info = this.hmrInfo;
|
|
159
|
+
if (!info || payload.buildId !== info.buildId) {
|
|
160
|
+
console.warn('[vpt] patches for a stale build');
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
const deliveredSeq = Math.max(this.appliedSeq, payload.patches.at(-1)?.seq ?? 0);
|
|
164
|
+
void this.sendReport({ kind: 'delivery', seq: deliveredSeq });
|
|
165
|
+
// A delivered patch means DevTools is about to replay the page lifecycle on the
|
|
166
|
+
// re-executing Pages; the capsule wrapper suppresses the synthetic unmount/mount so
|
|
167
|
+
// the React tree survives and Refresh swaps the code in place.
|
|
168
|
+
this.hotReloading = true;
|
|
169
|
+
// Apply synchronously: the page's imports below the require resolve against the
|
|
170
|
+
// freshly registered modules, so the re-executed Page evaluates with the new code.
|
|
171
|
+
this.applyPatches(payload.patches);
|
|
172
|
+
}
|
|
173
|
+
/** Applies one physical suffix in Rolldown sequence order. */
|
|
174
|
+
applyPatches(patches) {
|
|
175
|
+
for (const patch of patches) {
|
|
176
|
+
if (patch.seq <= this.appliedSeq)
|
|
177
|
+
continue;
|
|
178
|
+
try {
|
|
179
|
+
const expectedSeq = this.appliedSeq + 1;
|
|
180
|
+
if (patch.seq !== expectedSeq) {
|
|
181
|
+
throw new Error(`missing patch sequence ${expectedSeq}`);
|
|
182
|
+
}
|
|
183
|
+
patch.factory();
|
|
184
|
+
this.applyHmrUpdate(patch.changedIds);
|
|
185
|
+
this.appliedSeq = patch.seq;
|
|
186
|
+
}
|
|
187
|
+
catch (error) {
|
|
188
|
+
console.warn(`[vpt] patch sequence ${patch.seq} failed; apply stopped`, error);
|
|
189
|
+
void this.sendReport({ kind: 'rebuild' });
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
/** Sends one metadata-only report to the host; executable code never travels over HTTP. */
|
|
195
|
+
sendReport(data) {
|
|
196
|
+
const info = this.hmrInfo;
|
|
197
|
+
if (!info) {
|
|
198
|
+
// A report without initialize is a programming error; fail loudly instead of
|
|
199
|
+
// silently dropping the sync traffic.
|
|
200
|
+
throw new Error('WX dev runtime is not initialized');
|
|
201
|
+
}
|
|
202
|
+
return new Promise((resolve, reject) => {
|
|
203
|
+
wx.request({
|
|
204
|
+
url: info.endpoint,
|
|
205
|
+
method: 'POST',
|
|
206
|
+
data: { buildId: info.buildId, ...data },
|
|
207
|
+
header: { 'content-type': 'application/json' },
|
|
208
|
+
success() {
|
|
209
|
+
resolve();
|
|
210
|
+
},
|
|
211
|
+
fail(error) {
|
|
212
|
+
reject(error);
|
|
213
|
+
}
|
|
214
|
+
});
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
const runtime = new WxDevRuntime();
|
|
219
|
+
globalThis.__rolldown_runtime__ = runtime;
|
|
220
|
+
// Install the React DevTools hook before the Taro renderer injects itself: the runtime chunk
|
|
221
|
+
// is the first module of the App heap, and the renderer checks the hook when it evaluates at
|
|
222
|
+
// App mount. The refresh runtime's own injection (see react-refresh.ts) replays this hook's
|
|
223
|
+
// renderers, so the hook must store what inject receives — a real DevTools hook keeps the
|
|
224
|
+
// renderer in the renderers Map; without the stored renderer the replay captures nothing and
|
|
225
|
+
// Refresh has no renderer helpers to schedule re-renders on.
|
|
226
|
+
//
|
|
227
|
+
// The hook lives on `global`, and every free `__REACT_DEVTOOLS_GLOBAL_HOOK__` reference in
|
|
228
|
+
// react-family modules is rewritten to `global.__REACT_DEVTOOLS_GLOBAL_HOOK__`: the
|
|
229
|
+
// The WeChat runtime scope does not resolve free variables against `global` (verified: the free
|
|
230
|
+
// lookup is undefined while the member access exists), so the renderer would never inject
|
|
231
|
+
// otherwise. `??=` keeps a pre-installed hook (e.g. a real DevTools integration) intact; the
|
|
232
|
+
// runtime chunk's own lowering keeps the operator es2018-compatible.
|
|
233
|
+
const reactDevtoolsHook = {
|
|
234
|
+
renderers: new Map(),
|
|
235
|
+
supportsFiber: true,
|
|
236
|
+
inject: (injected) => {
|
|
237
|
+
const id = reactDevtoolsHook.renderers.size;
|
|
238
|
+
reactDevtoolsHook.renderers.set(id, injected);
|
|
239
|
+
return id;
|
|
240
|
+
},
|
|
241
|
+
onScheduleFiberRoot: () => { },
|
|
242
|
+
onCommitFiberRoot: () => { },
|
|
243
|
+
onCommitFiberUnmount: () => { }
|
|
244
|
+
};
|
|
245
|
+
global.__REACT_DEVTOOLS_GLOBAL_HOOK__ ??= reactDevtoolsHook;
|
|
246
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import '../amphibious/bootstrap.ts';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import '../amphibious/bootstrap.ts';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import '../amphibious/bootstrap.ts';
|