vite-plugin-taro 0.3.2 → 0.4.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.
- 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 +66 -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 +1 -1
- 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 +97 -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 +1 -1
- 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
|
@@ -1,144 +0,0 @@
|
|
|
1
|
-
import path from 'node:path';
|
|
2
|
-
import { normalizeModuleId, stripVirtualPrefix } from '../../utils/modules.js';
|
|
3
|
-
import { packageRequire } from '../../utils/packages.js';
|
|
4
|
-
import { emitWxCompanionAssets } from './companion-assets.js';
|
|
5
|
-
import { WxDevelopmentSession } from './dev-server/development-session.js';
|
|
6
|
-
import { transformWxReactRefreshModule } from './react-refresh.js';
|
|
7
|
-
import { emitWxEntryChunks, isWxVirtualModuleId, loadWxVirtualModule, virtualWxAppId } from './virtual-modules.js';
|
|
8
|
-
const taroWxComponentsPath = packageRequire.resolve('@tarojs/plugin-platform-weapp/dist/components-react');
|
|
9
|
-
const vitePluginTaroSourcePath = normalizeModuleId(path.dirname(packageRequire.resolve('vite-plugin-taro')));
|
|
10
|
-
const taroVersion = String(packageRequire('@tarojs/runtime/package.json').version);
|
|
11
|
-
/** Creates the plugins that own the complete WX build and development lifecycle. */
|
|
12
|
-
export function createWxTargetPlugins(context) {
|
|
13
|
-
return [createWxTargetPlugin(context)];
|
|
14
|
-
}
|
|
15
|
-
function createWxTargetPlugin(context) {
|
|
16
|
-
let developmentSession;
|
|
17
|
-
return {
|
|
18
|
-
name: 'vite-plugin-taro:wx',
|
|
19
|
-
resolveId: {
|
|
20
|
-
order: 'pre',
|
|
21
|
-
handler(id) {
|
|
22
|
-
return isWxVirtualModuleId(id) ? `\0${id}` : undefined;
|
|
23
|
-
}
|
|
24
|
-
},
|
|
25
|
-
load: {
|
|
26
|
-
order: 'post',
|
|
27
|
-
handler(id) {
|
|
28
|
-
const cleanId = stripVirtualPrefix(id);
|
|
29
|
-
emitWxEntryChunks(this, context, cleanId);
|
|
30
|
-
return loadWxVirtualModule(cleanId, context);
|
|
31
|
-
}
|
|
32
|
-
},
|
|
33
|
-
transform: {
|
|
34
|
-
order: 'post',
|
|
35
|
-
async handler(code, id) {
|
|
36
|
-
if (!context.development)
|
|
37
|
-
return;
|
|
38
|
-
const transformed = await transformWxReactRefreshModule(code, id, context.project.appComponentFile);
|
|
39
|
-
return transformed === code ? undefined : transformed;
|
|
40
|
-
}
|
|
41
|
-
},
|
|
42
|
-
generateBundle: {
|
|
43
|
-
order: 'post',
|
|
44
|
-
async handler(_, bundle) {
|
|
45
|
-
await emitWxCompanionAssets(this, bundle, context);
|
|
46
|
-
}
|
|
47
|
-
},
|
|
48
|
-
configureServer: {
|
|
49
|
-
order: 'post',
|
|
50
|
-
handler(server) {
|
|
51
|
-
developmentSession = new WxDevelopmentSession(context, server);
|
|
52
|
-
developmentSession.install();
|
|
53
|
-
}
|
|
54
|
-
},
|
|
55
|
-
closeBundle() {
|
|
56
|
-
return developmentSession?.close();
|
|
57
|
-
}
|
|
58
|
-
};
|
|
59
|
-
}
|
|
60
|
-
/** Supplies the complete WX target configuration from the same target owner as its plugin. */
|
|
61
|
-
export function createWxViteConfig(context) {
|
|
62
|
-
return {
|
|
63
|
-
define: createWxTaroDefines(),
|
|
64
|
-
experimental: context.development ? { bundledDev: true } : undefined,
|
|
65
|
-
css: {
|
|
66
|
-
lightningcss: {
|
|
67
|
-
visitor: {
|
|
68
|
-
// keep CSS3 style single colon :before, :after
|
|
69
|
-
// while WeChat Mini Program does not support the double colons versions
|
|
70
|
-
Selector(selector) {
|
|
71
|
-
return selector.map((component) => {
|
|
72
|
-
if (component.type === 'pseudo-element' &&
|
|
73
|
-
(component.kind === 'before' || component.kind === 'after')) {
|
|
74
|
-
return {
|
|
75
|
-
type: 'pseudo-element',
|
|
76
|
-
kind: 'custom',
|
|
77
|
-
name: component.kind
|
|
78
|
-
};
|
|
79
|
-
}
|
|
80
|
-
return component;
|
|
81
|
-
});
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
},
|
|
86
|
-
resolve: {
|
|
87
|
-
alias: [{ find: /^@tarojs\/components$/, replacement: taroWxComponentsPath }]
|
|
88
|
-
},
|
|
89
|
-
build: {
|
|
90
|
-
target: 'es2018',
|
|
91
|
-
assetsInlineLimit: 1024,
|
|
92
|
-
cssCodeSplit: false,
|
|
93
|
-
// weapp-tailwindcss has no minifier setting; retain Vite's production CSS minification.
|
|
94
|
-
cssMinify: context.development ? false : 'lightningcss',
|
|
95
|
-
minify: !context.development,
|
|
96
|
-
rolldownOptions: {
|
|
97
|
-
input: { app: virtualWxAppId },
|
|
98
|
-
experimental: {
|
|
99
|
-
// remove vite virtual module \0 in comments, which causes WeChat DevTools failed to compile
|
|
100
|
-
attachDebugInfo: 'none'
|
|
101
|
-
},
|
|
102
|
-
output: {
|
|
103
|
-
format: 'cjs',
|
|
104
|
-
entryFileNames: '[name].js',
|
|
105
|
-
assetFileNames: 'assets/[name][extname]',
|
|
106
|
-
chunkFileNames: ({ name }) => `${name === 'rolldown-runtime' ? 'runtime' : name}.js`,
|
|
107
|
-
strictExecutionOrder: true,
|
|
108
|
-
codeSplitting: {
|
|
109
|
-
includeDependenciesRecursively: false,
|
|
110
|
-
minSize: 0,
|
|
111
|
-
groups: [
|
|
112
|
-
{ name: 'taro', test: isWxTaroChunkModule, priority: 100 },
|
|
113
|
-
{ name: 'vendors', test: isNodeModule, priority: 10 },
|
|
114
|
-
{ name: 'common', minShareCount: 2, minModuleSize: 1, priority: 1 }
|
|
115
|
-
]
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
};
|
|
121
|
-
}
|
|
122
|
-
function createWxTaroDefines() {
|
|
123
|
-
return {
|
|
124
|
-
'process.env.FRAMEWORK': JSON.stringify('react'),
|
|
125
|
-
'process.env.SUPPORT_TARO_POLYFILL': JSON.stringify('disabled'),
|
|
126
|
-
'process.env.TARO_ENV': JSON.stringify('weapp'),
|
|
127
|
-
'process.env.TARO_PLATFORM': JSON.stringify('mini'),
|
|
128
|
-
'process.env.TARO_VERSION': JSON.stringify(taroVersion),
|
|
129
|
-
ENABLE_ADJACENT_HTML: 'false',
|
|
130
|
-
ENABLE_CLONE_NODE: 'false',
|
|
131
|
-
ENABLE_CONTAINS: 'false',
|
|
132
|
-
ENABLE_INNER_HTML: 'false',
|
|
133
|
-
ENABLE_MUTATION_OBSERVER: 'false',
|
|
134
|
-
ENABLE_SIZE_APIS: 'false',
|
|
135
|
-
ENABLE_TEMPLATE_CONTENT: 'false'
|
|
136
|
-
};
|
|
137
|
-
}
|
|
138
|
-
function isWxTaroChunkModule(id) {
|
|
139
|
-
const normalizedId = normalizeModuleId(id);
|
|
140
|
-
return normalizedId.includes('/node_modules/@tarojs/') || normalizedId.startsWith(`${vitePluginTaroSourcePath}/`);
|
|
141
|
-
}
|
|
142
|
-
function isNodeModule(id) {
|
|
143
|
-
return normalizeModuleId(id).includes('/node_modules/');
|
|
144
|
-
}
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
/** Rewrites Vite's browser-oriented Refresh output for the WX App Service global environment. */
|
|
2
|
-
export declare function transformWxReactRefreshModule(code: string, id: string, appComponentFile: string): Promise<string>;
|
|
3
|
-
/** Creates the virtual preamble that installs React Refresh before the generated WX App entry executes. */
|
|
4
|
-
export declare function createWxReactRefreshPreambleSource(): string;
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { transformWithOxc } from 'vite';
|
|
2
|
-
import { normalizeModuleId } from '../../utils/modules.js';
|
|
3
|
-
/** Rewrites Vite's browser-oriented Refresh output for the WX App Service global environment. */
|
|
4
|
-
export async function transformWxReactRefreshModule(code, id, appComponentFile) {
|
|
5
|
-
const appFile = normalizeModuleId(appComponentFile);
|
|
6
|
-
const instrumented = normalizeModuleId(id) === appFile ? await instrumentWxAppComponent(code, appFile) : code;
|
|
7
|
-
return instrumented
|
|
8
|
-
.replaceAll('window.$Refresh', 'globalThis.$Refresh')
|
|
9
|
-
.replaceAll('window.__registerBeforePerformReactRefresh', 'globalThis.__registerBeforePerformReactRefresh')
|
|
10
|
-
.replaceAll('window.__getReactRefreshIgnoredExports', 'globalThis.__getReactRefreshIgnoredExports')
|
|
11
|
-
.replace('export function register(type, id) {', 'export function register(type, id) {\n if (globalThis.__VITE_PLUGIN_TARO_WX_PAGE_UPDATE__?.blockRefreshRegistration) return')
|
|
12
|
-
.replace('\n performReactRefresh()\n', '\n globalThis.__VITE_PLUGIN_TARO_WX_PAGE_UPDATE__?.afterRefresh?.(performReactRefresh())\n');
|
|
13
|
-
}
|
|
14
|
-
/** Creates the virtual preamble that installs React Refresh before the generated WX App entry executes. */
|
|
15
|
-
export function createWxReactRefreshPreambleSource() {
|
|
16
|
-
return `import RefreshRuntime from '/@react-refresh'
|
|
17
|
-
RefreshRuntime.injectIntoGlobalHook(globalThis)
|
|
18
|
-
globalThis.$RefreshReg$ = () => {}
|
|
19
|
-
globalThis.$RefreshSig$ = () => (type) => type
|
|
20
|
-
`;
|
|
21
|
-
}
|
|
22
|
-
/** Adds Refresh registration to JSX-free App modules that Vite's normal JSX transform would otherwise skip. */
|
|
23
|
-
async function instrumentWxAppComponent(code, appFile) {
|
|
24
|
-
const transformed = await transformWithOxc(code, appFile, {
|
|
25
|
-
lang: 'js',
|
|
26
|
-
sourcemap: false,
|
|
27
|
-
jsx: { refresh: true }
|
|
28
|
-
});
|
|
29
|
-
return `import {
|
|
30
|
-
createSignatureFunctionForTransform as __wxCreateRefreshSignature,
|
|
31
|
-
register as __wxRegisterRefreshType
|
|
32
|
-
} from '/@react-refresh'
|
|
33
|
-
const $RefreshReg$ = (type, id) => __wxRegisterRefreshType(type, ${JSON.stringify(`${appFile} `)} + id)
|
|
34
|
-
const $RefreshSig$ = __wxCreateRefreshSignature
|
|
35
|
-
${transformed.code}
|
|
36
|
-
if (import.meta.hot) import.meta.hot.accept()
|
|
37
|
-
`;
|
|
38
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import type { BuildContext } from '../../build-context.ts';
|
|
2
|
-
/** Generated native App entry. */
|
|
3
|
-
export declare const virtualWxAppId = "virtual:vite-plugin-taro/wx/app";
|
|
4
|
-
type WxChunkEmitter = {
|
|
5
|
-
emitFile(chunk: {
|
|
6
|
-
type: 'chunk';
|
|
7
|
-
id: string;
|
|
8
|
-
fileName: string;
|
|
9
|
-
implicitlyLoadedAfterOneOf: string[];
|
|
10
|
-
}): string;
|
|
11
|
-
};
|
|
12
|
-
export declare function isWxVirtualModuleId(id: string): boolean;
|
|
13
|
-
export declare function loadWxVirtualModule(id: string, context: BuildContext): string | undefined;
|
|
14
|
-
/** Registers every configured page and the shared recursive component as eager WX entry chunks. */
|
|
15
|
-
export declare function emitWxEntryChunks(emitter: WxChunkEmitter, context: BuildContext, id: string): void;
|
|
16
|
-
export {};
|
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
import { createPageComponentImportPath, toViteFileImportPath } from '../../utils/modules.js';
|
|
2
|
-
import { resolvePackageFile } from '../../utils/packages.js';
|
|
3
|
-
import { wxPagePreloadFile } from './development-files.js';
|
|
4
|
-
import { createWxReactRefreshPreambleSource } from './react-refresh.js';
|
|
5
|
-
const wxTaroRuntimeImportPath = runtimeImportPath('taro-runtime.js');
|
|
6
|
-
const wxPageUpdateImportPath = runtimeImportPath('page-update.js');
|
|
7
|
-
const wxUpdateClientImportPath = runtimeImportPath('update-client.js');
|
|
8
|
-
/** Generated native App entry. */
|
|
9
|
-
export const virtualWxAppId = 'virtual:vite-plugin-taro/wx/app';
|
|
10
|
-
/** Generated recursive Taro component entry. */
|
|
11
|
-
const virtualWxComponentId = 'virtual:vite-plugin-taro/wx/component';
|
|
12
|
-
/** Prefix for one generated native entry per configured page route. */
|
|
13
|
-
const virtualWxPageIdPrefix = 'virtual:vite-plugin-taro/wx/page/';
|
|
14
|
-
/** App bootstrap module that installs React Refresh globals before application modules execute. */
|
|
15
|
-
const virtualWxRefreshPreambleId = 'virtual:vite-plugin-taro/wx/refresh-preamble';
|
|
16
|
-
/** Development-only entry that initializes all configured page components before update replay. */
|
|
17
|
-
const virtualWxPagePreloadId = 'virtual:vite-plugin-taro/wx/page-preload';
|
|
18
|
-
export function isWxVirtualModuleId(id) {
|
|
19
|
-
return (id === virtualWxAppId ||
|
|
20
|
-
id === virtualWxComponentId ||
|
|
21
|
-
id === virtualWxRefreshPreambleId ||
|
|
22
|
-
id === virtualWxPagePreloadId ||
|
|
23
|
-
id.startsWith(virtualWxPageIdPrefix));
|
|
24
|
-
}
|
|
25
|
-
export function loadWxVirtualModule(id, context) {
|
|
26
|
-
if (id === virtualWxRefreshPreambleId) {
|
|
27
|
-
return createWxReactRefreshPreambleSource();
|
|
28
|
-
}
|
|
29
|
-
if (id === virtualWxAppId) {
|
|
30
|
-
return createWxAppEntrySource(context);
|
|
31
|
-
}
|
|
32
|
-
if (id === virtualWxComponentId) {
|
|
33
|
-
return createWxComponentEntrySource();
|
|
34
|
-
}
|
|
35
|
-
if (id === virtualWxPagePreloadId) {
|
|
36
|
-
return createWxPagePreloadSource(context);
|
|
37
|
-
}
|
|
38
|
-
if (id.startsWith(virtualWxPageIdPrefix)) {
|
|
39
|
-
const pagePath = id.slice(virtualWxPageIdPrefix.length);
|
|
40
|
-
const page = context.project.pages.find((candidate) => candidate.path === pagePath);
|
|
41
|
-
if (page) {
|
|
42
|
-
return createWxPageEntrySource(page, context);
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
/** Registers every configured page and the shared recursive component as eager WX entry chunks. */
|
|
47
|
-
export function emitWxEntryChunks(emitter, context, id) {
|
|
48
|
-
if (id !== virtualWxAppId)
|
|
49
|
-
return;
|
|
50
|
-
for (const page of context.project.pages) {
|
|
51
|
-
emitter.emitFile({
|
|
52
|
-
type: 'chunk',
|
|
53
|
-
id: `${virtualWxPageIdPrefix}${page.path}`,
|
|
54
|
-
fileName: `${page.path}.js`,
|
|
55
|
-
implicitlyLoadedAfterOneOf: [id]
|
|
56
|
-
});
|
|
57
|
-
}
|
|
58
|
-
emitter.emitFile({
|
|
59
|
-
type: 'chunk',
|
|
60
|
-
id: virtualWxComponentId,
|
|
61
|
-
fileName: 'comp.js',
|
|
62
|
-
implicitlyLoadedAfterOneOf: [id]
|
|
63
|
-
});
|
|
64
|
-
if (context.development) {
|
|
65
|
-
emitter.emitFile({
|
|
66
|
-
type: 'chunk',
|
|
67
|
-
id: virtualWxPagePreloadId,
|
|
68
|
-
fileName: wxPagePreloadFile,
|
|
69
|
-
implicitlyLoadedAfterOneOf: [id]
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
function createWxAppEntrySource(context) {
|
|
74
|
-
const refreshPreamble = context.development ? `import ${JSON.stringify(virtualWxRefreshPreambleId)}\n` : '';
|
|
75
|
-
const updateClient = context.development
|
|
76
|
-
? `import { startWxUpdateClient } from ${JSON.stringify(wxUpdateClientImportPath)}\n`
|
|
77
|
-
: '';
|
|
78
|
-
return `${refreshPreamble}${updateClient}import { createReactApp, ReactDOM } from ${JSON.stringify(wxTaroRuntimeImportPath)}
|
|
79
|
-
import React from 'react'
|
|
80
|
-
import AppComponent from ${JSON.stringify(toViteFileImportPath(context.project.appComponentFile))}
|
|
81
|
-
|
|
82
|
-
const appConfig = ${JSON.stringify(context.project.appConfig)}
|
|
83
|
-
App(createReactApp(AppComponent, React, ReactDOM, appConfig))
|
|
84
|
-
${context.development ? 'startWxUpdateClient()' : ''}
|
|
85
|
-
`;
|
|
86
|
-
}
|
|
87
|
-
function createWxPageEntrySource(page, context) {
|
|
88
|
-
const hotUpdateImport = context.development
|
|
89
|
-
? `import { decorateWxPageConfig, registerWxPage } from ${JSON.stringify(wxPageUpdateImportPath)}\n`
|
|
90
|
-
: '';
|
|
91
|
-
const createConfig = `createPageConfig(PageComponent, '${page.path}', { root: { cn: [] } }, pageConfig)`;
|
|
92
|
-
const pageRegistration = context.development
|
|
93
|
-
? `registerWxPage(${JSON.stringify(page.path)}, () => Page(taroPageConfig))`
|
|
94
|
-
: 'Page(taroPageConfig)';
|
|
95
|
-
return `${hotUpdateImport}import { createPageConfig } from ${JSON.stringify(wxTaroRuntimeImportPath)}
|
|
96
|
-
import PageComponent from ${JSON.stringify(createPageComponentImportPath(page.path))}
|
|
97
|
-
|
|
98
|
-
const pageConfig = ${JSON.stringify(page.config)}
|
|
99
|
-
const taroPageConfig = ${context.development ? `decorateWxPageConfig(${createConfig})` : createConfig}
|
|
100
|
-
if (PageComponent && PageComponent.behaviors) {
|
|
101
|
-
taroPageConfig.behaviors = (taroPageConfig.behaviors || []).concat(PageComponent.behaviors)
|
|
102
|
-
}
|
|
103
|
-
${pageRegistration}
|
|
104
|
-
`;
|
|
105
|
-
}
|
|
106
|
-
function createWxPagePreloadSource(context) {
|
|
107
|
-
const imports = context.project.pages.map((page, index) => {
|
|
108
|
-
return `import Page${index} from ${JSON.stringify(createPageComponentImportPath(page.path))}`;
|
|
109
|
-
});
|
|
110
|
-
return `${imports.join('\n')}\nvoid [${context.project.pages.map((_, index) => `Page${index}`).join(', ')}]\n`;
|
|
111
|
-
}
|
|
112
|
-
function runtimeImportPath(fileName) {
|
|
113
|
-
return toViteFileImportPath(resolvePackageFile('dist/runtime/wx', fileName));
|
|
114
|
-
}
|
|
115
|
-
function createWxComponentEntrySource() {
|
|
116
|
-
return `import { createRecursiveComponentConfig } from ${JSON.stringify(wxTaroRuntimeImportPath)}
|
|
117
|
-
|
|
118
|
-
Component(createRecursiveComponentConfig())
|
|
119
|
-
`;
|
|
120
|
-
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
/** Generic asynchronous coordination helpers for Node-side plugin services. */
|
|
2
|
-
export declare class SerializedTaskQueue {
|
|
3
|
-
private readonly reportError;
|
|
4
|
-
private tail;
|
|
5
|
-
constructor(reportError: (error: unknown) => void);
|
|
6
|
-
enqueue(task: () => Promise<void>): Promise<void>;
|
|
7
|
-
waitForIdle(): Promise<void>;
|
|
8
|
-
}
|
package/dist/node/utils/async.js
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
/** Generic asynchronous coordination helpers for Node-side plugin services. */
|
|
2
|
-
export class SerializedTaskQueue {
|
|
3
|
-
reportError;
|
|
4
|
-
tail = Promise.resolve();
|
|
5
|
-
constructor(reportError) {
|
|
6
|
-
this.reportError = reportError;
|
|
7
|
-
}
|
|
8
|
-
enqueue(task) {
|
|
9
|
-
const work = this.tail.then(task);
|
|
10
|
-
this.tail = work.catch(this.reportError);
|
|
11
|
-
return work;
|
|
12
|
-
}
|
|
13
|
-
async waitForIdle() {
|
|
14
|
-
await this.tail;
|
|
15
|
-
}
|
|
16
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
type FileSource = string | Uint8Array;
|
|
2
|
-
type FileWrite = {
|
|
3
|
-
file: string;
|
|
4
|
-
source: FileSource;
|
|
5
|
-
};
|
|
6
|
-
/** Writes through a sibling temporary file so observers never read partial contents. */
|
|
7
|
-
export declare function writeFileAtomically(file: string, source: FileSource): Promise<void>;
|
|
8
|
-
export declare function writeFilesAtomically(files: FileWrite[]): Promise<void>;
|
|
9
|
-
/** Copies a directory when present and treats a missing optional source as empty. */
|
|
10
|
-
export declare function copyDirectoryIfExists(source: string, destination: string): Promise<void>;
|
|
11
|
-
/** Mirrors one optional file: copy existing files, ignore directories, and remove a missing source's destination. */
|
|
12
|
-
export declare function copyFileOrRemove(source: string, destination: string): Promise<void>;
|
|
13
|
-
export {};
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
/** Node-only filesystem helpers shared by build targets and development services. */
|
|
2
|
-
import fs from 'node:fs/promises';
|
|
3
|
-
import path from 'node:path';
|
|
4
|
-
/** Writes through a sibling temporary file so observers never read partial contents. */
|
|
5
|
-
export async function writeFileAtomically(file, source) {
|
|
6
|
-
await fs.mkdir(path.dirname(file), { recursive: true });
|
|
7
|
-
const temporaryFile = `${file}.tmp`;
|
|
8
|
-
await fs.writeFile(temporaryFile, source);
|
|
9
|
-
await fs.rename(temporaryFile, file);
|
|
10
|
-
}
|
|
11
|
-
export async function writeFilesAtomically(files) {
|
|
12
|
-
await Promise.all(files.map(({ file, source }) => writeFileAtomically(file, source)));
|
|
13
|
-
}
|
|
14
|
-
/** Copies a directory when present and treats a missing optional source as empty. */
|
|
15
|
-
export async function copyDirectoryIfExists(source, destination) {
|
|
16
|
-
if (!source)
|
|
17
|
-
return;
|
|
18
|
-
try {
|
|
19
|
-
await fs.cp(source, destination, { recursive: true, force: true });
|
|
20
|
-
}
|
|
21
|
-
catch (error) {
|
|
22
|
-
if (!isMissingFileError(error))
|
|
23
|
-
throw error;
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
/** Mirrors one optional file: copy existing files, ignore directories, and remove a missing source's destination. */
|
|
27
|
-
export async function copyFileOrRemove(source, destination) {
|
|
28
|
-
try {
|
|
29
|
-
const stat = await fs.stat(source);
|
|
30
|
-
if (stat.isDirectory())
|
|
31
|
-
return;
|
|
32
|
-
await fs.mkdir(path.dirname(destination), { recursive: true });
|
|
33
|
-
await fs.copyFile(source, destination);
|
|
34
|
-
}
|
|
35
|
-
catch (error) {
|
|
36
|
-
if (!isMissingFileError(error))
|
|
37
|
-
throw error;
|
|
38
|
-
await fs.rm(destination, { recursive: true, force: true });
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
function isMissingFileError(error) {
|
|
42
|
-
return error instanceof Error && 'code' in error && error.code === 'ENOENT';
|
|
43
|
-
}
|
package/dist/runtime/taro/api.js
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
/** Physical runtime module backing the public `virtual:taro/api` facade. */
|
|
2
|
-
// Ensure Taro's React runtime registers its `initNativeApi` hook before @tarojs/taro is initialized.
|
|
3
|
-
import '@tarojs/plugin-framework-react/dist/runtime';
|
|
4
|
-
import { hooks } from '@tarojs/runtime';
|
|
5
|
-
import Taro from '@tarojs/taro';
|
|
6
|
-
if (hooks.isExist('initNativeApi')) {
|
|
7
|
-
hooks.call('initNativeApi', Taro);
|
|
8
|
-
}
|
|
9
|
-
// @ts-expect-error @tarojs/taro declares export= types, but vite-plugin-taro target aliases expose runtime named exports.
|
|
10
|
-
export * from '@tarojs/taro';
|
|
11
|
-
export default Taro;
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
type WxPageConfig = Record<string, unknown>;
|
|
2
|
-
/** Registers a native route once per App Service runtime generation. */
|
|
3
|
-
export declare function registerWxPage(route: string, register: () => void): void;
|
|
4
|
-
/** Retains Taro's live root while filtering DevTools' synthetic update lifecycles. */
|
|
5
|
-
export declare function decorateWxPageConfig(config: WxPageConfig): WxPageConfig;
|
|
6
|
-
export {};
|
|
@@ -1,157 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Coordinates page-side update execution after the Rolldown and Taro runtimes exist.
|
|
3
|
-
*
|
|
4
|
-
* This module is intentionally page-only: it suppresses DevTools' synthetic lifecycles, preserves the Taro root,
|
|
5
|
-
* commits React Refresh, and relaunches stale component families. HTTP transport remains in update-client.ts.
|
|
6
|
-
*/
|
|
7
|
-
import { document } from '@tarojs/runtime';
|
|
8
|
-
import { validateRefreshBoundaryAndEnqueueUpdate } from '/@react-refresh';
|
|
9
|
-
const wxRuntimeGlobal = globalThis;
|
|
10
|
-
wxRuntimeGlobal.__VITE_PLUGIN_TARO_WX_PAGE_UPDATE__ ??= { ready: false };
|
|
11
|
-
const bridge = wxRuntimeGlobal.__VITE_PLUGIN_TARO_WX_PAGE_UPDATE__;
|
|
12
|
-
const refreshBoundary = { default: function WxRefreshBoundary() { } };
|
|
13
|
-
const registeredRoutes = new Set();
|
|
14
|
-
const ignoredPages = new WeakSet();
|
|
15
|
-
let pageRuntimeState = { suppressLifecycles: false };
|
|
16
|
-
/** Registers a native route once per App Service runtime generation. */
|
|
17
|
-
export function registerWxPage(route, register) {
|
|
18
|
-
if (registeredRoutes.has(route))
|
|
19
|
-
return;
|
|
20
|
-
register();
|
|
21
|
-
registeredRoutes.add(route);
|
|
22
|
-
}
|
|
23
|
-
/** Retains Taro's live root while filtering DevTools' synthetic update lifecycles. */
|
|
24
|
-
export function decorateWxPageConfig(config) {
|
|
25
|
-
const onLoad = getLifecycle(config, 'onLoad');
|
|
26
|
-
config.onLoad = function (...args) {
|
|
27
|
-
if (pageRuntimeState.suppressLifecycles) {
|
|
28
|
-
ignoredPages.add(this);
|
|
29
|
-
this.$taroPath = pageRuntimeState.activePage?.$taroPath;
|
|
30
|
-
this.$taroParams = pageRuntimeState.activePage?.$taroParams;
|
|
31
|
-
dispatchPageRuntime({ type: 'page-activated', page: this });
|
|
32
|
-
return;
|
|
33
|
-
}
|
|
34
|
-
const result = onLoad?.apply(this, args);
|
|
35
|
-
dispatchPageRuntime({ type: 'page-activated', page: this });
|
|
36
|
-
return result;
|
|
37
|
-
};
|
|
38
|
-
wrapLifecycle(config, 'onReady', applyPendingPageUpdate);
|
|
39
|
-
wrapLifecycle(config, 'onShow', function () {
|
|
40
|
-
dispatchPageRuntime({ type: 'page-activated', page: this });
|
|
41
|
-
});
|
|
42
|
-
wrapLifecycle(config, 'onHide');
|
|
43
|
-
wrapLifecycle(config, 'onUnload', function () {
|
|
44
|
-
dispatchPageRuntime({ type: 'page-unloaded', page: this });
|
|
45
|
-
});
|
|
46
|
-
return config;
|
|
47
|
-
}
|
|
48
|
-
function wrapLifecycle(config, name, after) {
|
|
49
|
-
const original = getLifecycle(config, name);
|
|
50
|
-
config[name] = function (...args) {
|
|
51
|
-
if (pageRuntimeState.suppressLifecycles)
|
|
52
|
-
return;
|
|
53
|
-
if (ignoredPages.has(this)) {
|
|
54
|
-
if (name === 'onUnload')
|
|
55
|
-
ignoredPages.delete(this);
|
|
56
|
-
return;
|
|
57
|
-
}
|
|
58
|
-
const result = original?.apply(this, args);
|
|
59
|
-
after?.apply(this, args);
|
|
60
|
-
return result;
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
function getLifecycle(config, name) {
|
|
64
|
-
return typeof config[name] === 'function' ? config[name] : undefined;
|
|
65
|
-
}
|
|
66
|
-
function applyPendingPageUpdate() {
|
|
67
|
-
bridge.ready = true;
|
|
68
|
-
const pendingUpdate = bridge.pendingUpdate;
|
|
69
|
-
if (pendingUpdate) {
|
|
70
|
-
delete bridge.pendingUpdate;
|
|
71
|
-
pendingUpdate();
|
|
72
|
-
}
|
|
73
|
-
wxRuntimeGlobal.__VITE_PLUGIN_TARO_WX_UPDATE_CLIENT__?.routeReady();
|
|
74
|
-
}
|
|
75
|
-
function getActiveTaroRoot() {
|
|
76
|
-
const page = pageRuntimeState.activePage;
|
|
77
|
-
if (!page?.$taroPath)
|
|
78
|
-
return;
|
|
79
|
-
return document.getElementById(page.$taroPath) ?? undefined;
|
|
80
|
-
}
|
|
81
|
-
bridge.enqueueRefresh = () => {
|
|
82
|
-
validateRefreshBoundaryAndEnqueueUpdate('vite-plugin-taro-wx', refreshBoundary, refreshBoundary);
|
|
83
|
-
};
|
|
84
|
-
bridge.beginUpdate = () => {
|
|
85
|
-
bridge.blockRefreshRegistration = false;
|
|
86
|
-
wxRuntimeGlobal.__rolldown_runtime__?.beginPatch?.();
|
|
87
|
-
dispatchPageRuntime({ type: 'update-started', root: getActiveTaroRoot() });
|
|
88
|
-
refreshTaroRoot(pageRuntimeState.pendingUpdate?.root, pageRuntimeState.pendingUpdate?.page);
|
|
89
|
-
runInNextNativeTask(() => dispatchPageRuntime({ type: 'suppression-ended' }));
|
|
90
|
-
};
|
|
91
|
-
bridge.endUpdate = () => {
|
|
92
|
-
wxRuntimeGlobal.__rolldown_runtime__?.endPatch?.();
|
|
93
|
-
bridge.blockRefreshRegistration = true;
|
|
94
|
-
bridge.enqueueRefresh?.();
|
|
95
|
-
};
|
|
96
|
-
bridge.afterRefresh = (update) => {
|
|
97
|
-
bridge.blockRefreshRegistration = false;
|
|
98
|
-
const pendingUpdate = pageRuntimeState.pendingUpdate;
|
|
99
|
-
dispatchPageRuntime({ type: 'refresh-finished' });
|
|
100
|
-
const page = pendingUpdate?.page;
|
|
101
|
-
const root = pendingUpdate?.root;
|
|
102
|
-
const stale = Boolean(update?.staleFamilies?.size);
|
|
103
|
-
if (stale) {
|
|
104
|
-
wxRuntimeGlobal.__VITE_PLUGIN_TARO_WX_UPDATE_CLIENT__?.refreshCompleted(true);
|
|
105
|
-
relaunchActiveRoute(page);
|
|
106
|
-
return;
|
|
107
|
-
}
|
|
108
|
-
runInNextNativeTask(() => {
|
|
109
|
-
refreshTaroRoot(root, pageRuntimeState.activePage ?? page);
|
|
110
|
-
wxRuntimeGlobal.__VITE_PLUGIN_TARO_WX_UPDATE_CLIENT__?.refreshCompleted(false);
|
|
111
|
-
});
|
|
112
|
-
};
|
|
113
|
-
function dispatchPageRuntime(event) {
|
|
114
|
-
pageRuntimeState = transitionPageRuntime(pageRuntimeState, event);
|
|
115
|
-
}
|
|
116
|
-
function transitionPageRuntime(state, event) {
|
|
117
|
-
switch (event.type) {
|
|
118
|
-
case 'page-activated':
|
|
119
|
-
return { ...state, activePage: event.page };
|
|
120
|
-
case 'page-unloaded':
|
|
121
|
-
return state.activePage === event.page ? { ...state, activePage: undefined } : state;
|
|
122
|
-
case 'update-started':
|
|
123
|
-
return {
|
|
124
|
-
...state,
|
|
125
|
-
pendingUpdate: { page: state.activePage, root: event.root },
|
|
126
|
-
suppressLifecycles: true
|
|
127
|
-
};
|
|
128
|
-
case 'suppression-ended':
|
|
129
|
-
return { ...state, suppressLifecycles: false };
|
|
130
|
-
case 'refresh-finished':
|
|
131
|
-
return { ...state, pendingUpdate: undefined };
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
function refreshTaroRoot(root, page) {
|
|
135
|
-
if (!root)
|
|
136
|
-
return;
|
|
137
|
-
root.ctx = page ?? null;
|
|
138
|
-
root.updateChildNodes();
|
|
139
|
-
root.performUpdate(true);
|
|
140
|
-
}
|
|
141
|
-
function relaunchActiveRoute(page) {
|
|
142
|
-
const route = wxRuntimeGlobal.getCurrentPages().at(-1)?.route;
|
|
143
|
-
if (!route)
|
|
144
|
-
return;
|
|
145
|
-
const query = Object.entries(page?.$taroParams ?? {})
|
|
146
|
-
.filter(([key, value]) => key !== '$taroTimestamp' && value !== undefined)
|
|
147
|
-
.map(([key, value]) => `${encodeURIComponent(key)}=${encodeURIComponent(String(value))}`)
|
|
148
|
-
.join('&');
|
|
149
|
-
runInNextNativeTask(() => wxRuntimeGlobal.wx.reLaunch({ url: `/${route}${query ? `?${query}` : ''}` }));
|
|
150
|
-
}
|
|
151
|
-
/**
|
|
152
|
-
* DevTools dispatches synthetic page lifecycles after the changed module returns. A macrotask—not a microtask—runs
|
|
153
|
-
* after that native turn and also avoids navigation or Taro root mutation from inside React Refresh's callback.
|
|
154
|
-
*/
|
|
155
|
-
function runInNextNativeTask(task) {
|
|
156
|
-
setTimeout(task);
|
|
157
|
-
}
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
/** Runtime exports consumed by generated WX App, page, and recursive-component entries. */
|
|
2
|
-
import '@tarojs/plugin-platform-weapp/dist/runtime.js';
|
|
3
|
-
export { createReactApp } from '@tarojs/plugin-framework-react/dist/runtime';
|
|
4
|
-
export { default as ReactDOM } from '@tarojs/react';
|
|
5
|
-
export { createPageConfig, createRecursiveComponentConfig } from '@tarojs/runtime';
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
/** Runtime exports consumed by generated WX App, page, and recursive-component entries. */
|
|
2
|
-
import '@tarojs/plugin-platform-weapp/dist/runtime.js';
|
|
3
|
-
// @ts-expect-error Taro exposes createReactApp from this runtime-only deep entry without types.
|
|
4
|
-
export { createReactApp } from '@tarojs/plugin-framework-react/dist/runtime';
|
|
5
|
-
export { default as ReactDOM } from '@tarojs/react';
|
|
6
|
-
export { createPageConfig, createRecursiveComponentConfig } from '@tarojs/runtime';
|