vite-plugin-taro 0.7.3 → 0.7.4-beta.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/dist/index.js +88 -310
- package/dist/node/plugins/mini/module/module.d.ts +12 -6
- package/dist/node/plugins/mini/placer/placer.d.ts +5 -7
- package/dist/node/plugins/mini/polyfill/create-mini-polyfill-plugin.d.ts +4 -0
- package/dist/node/plugins/mini/polyfill/mini-browser-bindings.d.ts +13 -0
- package/dist/node/plugins/mini/render/native.d.ts +3 -1
- package/dist/node/plugins/mini/styles/minify-mini-stylesheet.d.ts +6 -0
- package/dist/node/plugins/mini/styles/plugins.d.ts +13 -8
- package/dist/options.d.ts +14 -0
- package/dist/runtime/mini/amphibious/bootstrap.d.ts +1 -0
- package/dist/runtime/mini/amphibious/bootstrap.js +3 -0
- package/dist/runtime/mini/dev/mini-hmr-runtime.js +0 -5
- package/dist/runtime/mini/dev/modes/interpreter/interpreter-runtime.js +4 -9
- package/package.json +4 -2
- package/dist/runtime/mini/dev/polyfill/polyfill-queue-microtask.d.ts +0 -14
- package/dist/runtime/mini/dev/polyfill/polyfill-queue-microtask.js +0 -18
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type Rolldown } from 'vite';
|
|
2
2
|
import type { RuntimeModulesContract } from '../mini-contract.ts';
|
|
3
|
+
export declare const miniRuntimeId: string;
|
|
3
4
|
/** Identifies Rolldown's generated helper module independently of its unstable output filename. */
|
|
4
5
|
export declare const rolldownRuntimeId = "\0rolldown/runtime.js";
|
|
6
|
+
/** Generates the selected core-js imports as one independently executable output entry. */
|
|
7
|
+
export declare const miniPolyfillsId = "\0vpt:mini-polyfills";
|
|
5
8
|
/** Resolves the shared Taro facade's target initialization side effect. */
|
|
6
9
|
export declare const taroTargetRuntimeId = "\0vpt:taro-target-runtime";
|
|
7
10
|
/** Redirects Vite's injected browser preload helper to the bootstrap identity loader. */
|
|
@@ -27,12 +30,15 @@ export type MiniChunkClassification = Readonly<{
|
|
|
27
30
|
executionKind: MiniExecutionKind;
|
|
28
31
|
isTransport: boolean;
|
|
29
32
|
}>;
|
|
30
|
-
/** Classifies
|
|
33
|
+
/** Classifies chunks by runtime roles and framework vendor membership. */
|
|
31
34
|
export type MiniModuleClassifier = (chunk: MiniChunk) => MiniChunkClassification;
|
|
35
|
+
/** Groups the generated entry and core-js into common/polyfills.js. */
|
|
36
|
+
export declare function isMiniPolyfillModule(moduleId: string): boolean;
|
|
37
|
+
/** Uses the same resolved roots for vendor grouping and amphibious execution; Rolldown includes their dependencies. */
|
|
38
|
+
export declare function isMiniFrameworkVendorModule(moduleId: string): boolean;
|
|
32
39
|
/**
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
* Construction is O(1)
|
|
36
|
-
* of modules in the chunk. This replaces separate shell, capsule, amphibious, and transport scans.
|
|
40
|
+
* Classifies runtime entries and framework vendor chunks in one module-ID scan.
|
|
41
|
+
* Amphibious chunks share bootstrap's bridge so native and SystemJS callers reuse the same exports.
|
|
42
|
+
* Construction is O(1); each lookup is O(M), where M is the number of modules in the chunk.
|
|
37
43
|
*/
|
|
38
44
|
export declare function createMiniModuleClassifier(modules: RuntimeModulesContract): MiniModuleClassifier;
|
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { Plugin, Rolldown } from 'vite';
|
|
2
2
|
import type { RuntimeModulesContract } from '../mini-contract.ts';
|
|
3
|
-
import { type MiniChunkClassification, type MiniModuleClassifier } from '../module/module.ts';
|
|
3
|
+
import { isMiniPolyfillModule, type MiniChunkClassification, type MiniModuleClassifier } from '../module/module.ts';
|
|
4
4
|
import { type GeneratedSubpackage, type PackageLocation } from './placement.ts';
|
|
5
5
|
export type { GeneratedSubpackage, Placement } from './placement.ts';
|
|
6
|
-
/** Selects the explicit React/Taro roots whose complete dependency closure forms the framework vendor chunk. */
|
|
7
|
-
export declare function isMiniFrameworkVendorModule(moduleId: string): boolean;
|
|
8
6
|
/** Placement services consumed by the later Mini Program rendering and output hooks. */
|
|
9
7
|
export type MiniPlacementPlugin = Plugin & Readonly<{
|
|
10
8
|
classifyChunk(chunk: Rolldown.PreRenderedChunk | Rolldown.RenderedChunk): MiniChunkClassification;
|
|
@@ -24,15 +22,15 @@ export declare function createPlacementRolldownOptions(classifyChunk: MiniModule
|
|
|
24
22
|
*/
|
|
25
23
|
output: {
|
|
26
24
|
/**
|
|
27
|
-
* React and Taro form one stable framework boundary shared by the App and every Page capsule. Keeping their
|
|
28
|
-
*
|
|
25
|
+
* React and Taro form one stable framework boundary shared by the App and every Page capsule. Keeping their framework
|
|
26
|
+
* dependencies together prevents application edits from invalidating framework chunk identity and makes later
|
|
29
27
|
* development generations eligible to reuse the unchanged vendor. Application code and other dependencies
|
|
30
28
|
* use Rolldown's automatic chunking without source-path groups or a blanket external vendor group.
|
|
31
29
|
*/
|
|
32
30
|
codeSplitting: {
|
|
33
31
|
groups: {
|
|
34
32
|
name: string;
|
|
35
|
-
test: typeof
|
|
33
|
+
test: typeof isMiniPolyfillModule;
|
|
36
34
|
priority: number;
|
|
37
35
|
includeDependenciesRecursively: boolean;
|
|
38
36
|
}[];
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { Plugin } from 'vite';
|
|
2
|
+
import type { MiniContract } from '../mini-contract.ts';
|
|
3
|
+
/** Loads a standalone polyfills entry before bootstrap and retains Taro's renderer bindings. */
|
|
4
|
+
export declare function createMiniPolyfillPlugin(contract: Pick<MiniContract, 'options'>): Plugin;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/** Taro's renderer-owned browser bindings; portable APIs use native globals or explicit polyfills. */
|
|
2
|
+
export declare const miniBrowserBindings: {
|
|
3
|
+
window: [string, string];
|
|
4
|
+
document: [string, string];
|
|
5
|
+
navigator: [string, string];
|
|
6
|
+
requestAnimationFrame: [string, string];
|
|
7
|
+
cancelAnimationFrame: [string, string];
|
|
8
|
+
Element: [string, string];
|
|
9
|
+
SVGElement: [string, string];
|
|
10
|
+
MutationObserver: [string, string];
|
|
11
|
+
history: [string, string];
|
|
12
|
+
location: [string, string];
|
|
13
|
+
};
|
|
@@ -4,7 +4,7 @@ import type { MiniModuleClassifier } from '../module/module.ts';
|
|
|
4
4
|
/**
|
|
5
5
|
* Materializes one final native/amphibious Rolldown chunk as executable Mini Program CommonJS.
|
|
6
6
|
*
|
|
7
|
-
* The transform performs
|
|
7
|
+
* The transform performs five semantic operations:
|
|
8
8
|
*
|
|
9
9
|
* 1. Static ESM imports are hoisted into source-order `require` calls. Named imports remain property reads from the required
|
|
10
10
|
* namespace so they observe current values. Default and namespace imports receive Babel-compatible CommonJS interop.
|
|
@@ -14,6 +14,8 @@ import type { MiniModuleClassifier } from '../module/module.ts';
|
|
|
14
14
|
* updates notify every alias without changing expression completion values or accidentally matching shadowed bindings.
|
|
15
15
|
* 4. ESM top-level `this` becomes `undefined`. Direct imported calls and tags are explicitly unbound so converting an import
|
|
16
16
|
* into a namespace property does not introduce a false CommonJS receiver.
|
|
17
|
+
* 5. Dynamic imports call the shared SystemJS loader. Relative string literals become logical chunk IDs, while computed IDs
|
|
18
|
+
* are preserved, matching capsule loading and leaving physical require/require.async selection to transport.
|
|
17
19
|
*
|
|
18
20
|
* Static dependency loading is emitted before the untouched module body because ESM evaluates dependencies before body
|
|
19
21
|
* statements regardless of where import declarations appear textually. Generated helper names are allocated against every
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { BuildOptions } from 'vite';
|
|
2
|
+
/** Minifies only the completed global native stylesheet, without another browser compatibility or preprocessing pass. */
|
|
3
|
+
export declare function minifyMiniStylesheet(css: string, options: Readonly<{
|
|
4
|
+
filename: string;
|
|
5
|
+
minify: BuildOptions['cssMinify'];
|
|
6
|
+
}>): Promise<string>;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { type Plugin } from 'vite';
|
|
2
2
|
import type { MiniContract } from '../mini-contract.ts';
|
|
3
3
|
import { createMiniTransformer } from './create-mini-transformer.ts';
|
|
4
|
+
import { minifyMiniStylesheet } from './minify-mini-stylesheet.ts';
|
|
4
5
|
/** JavaScript code plus the physical filename required by the Mini Program class-name transformer. */
|
|
5
6
|
type JavaScriptArtifact = Readonly<{
|
|
6
7
|
code: string;
|
|
@@ -77,10 +78,12 @@ export type MiniStylePlugin = Plugin & Readonly<{
|
|
|
77
78
|
*
|
|
78
79
|
* ### 4. Shared native-style finalization
|
|
79
80
|
*
|
|
80
|
-
* `finalizeOutput()`
|
|
81
|
-
* with the same projected class set.
|
|
82
|
-
*
|
|
83
|
-
*
|
|
81
|
+
* `finalizeOutput()` converts the concatenated reachable CSS to native CSS, optionally minifies that complete global file
|
|
82
|
+
* (including HTML defaults), then transforms each JavaScript artifact with the same projected class set. Both builds and HMR
|
|
83
|
+
* follow `build.cssMinify`, defaulting to `build.minify`, using Lightning CSS. Vite's intermediate CSS minification
|
|
84
|
+
* remains disabled so only final native bytes are optimized. The function returns data without bundle mutation or filesystem
|
|
85
|
+
* publication. Any conversion or minification failure rejects before callers expose partial output. JavaScript conversion is
|
|
86
|
+
* skipped when the projection contains no Tailwind candidates, preserving ordinary bundle bytes.
|
|
84
87
|
*
|
|
85
88
|
* ### 5a. Complete-build commit
|
|
86
89
|
*
|
|
@@ -100,8 +103,9 @@ export type MiniStylePlugin = Plugin & Readonly<{
|
|
|
100
103
|
*
|
|
101
104
|
* ## Retained state and lifecycle
|
|
102
105
|
*
|
|
103
|
-
* The factory retains
|
|
106
|
+
* The factory retains five explicit mutable state owners plus one fixed transformation service:
|
|
104
107
|
*
|
|
108
|
+
* - `cssMinify`: requested global-style minification captured before disabling Vite's intermediate pass, then resolved once;
|
|
105
109
|
* - `entryIds`: graph-exact App/Page entry identities resolved at the start of each build;
|
|
106
110
|
* - `graphContext`: the active Rolldown graph reader needed by host calls made outside plugin hooks;
|
|
107
111
|
* - `styleByModuleId`: the latest successful Vite CSS plus optional Tailwind state at one normalized module identity;
|
|
@@ -118,14 +122,15 @@ export type MiniStylePlugin = Plugin & Readonly<{
|
|
|
118
122
|
* chunks then parse and walk in `O(J)`; replacing `Kᵢ` candidate tokens in literal `i` costs `O(LᵢKᵢ)` while preserving
|
|
119
123
|
* untouched bytes through Rolldown's native editor. Retained memory is `O(B + C + D + F)` for latest CSS, candidate sets,
|
|
120
124
|
* compiler dependencies, and watched file identities; no second application graph is retained. The Tailwind generator stays
|
|
121
|
-
* alive across candidate edits to avoid repeating source normalization and compiler initialization.
|
|
125
|
+
* alive across candidate edits to avoid repeating source normalization and compiler initialization. Enabled minification parses
|
|
126
|
+
* the one final global stylesheet in builds and HMR; no extra source reads or graph traversals are needed.
|
|
122
127
|
*/
|
|
123
128
|
export declare function createMiniStylePlugin(contract: Pick<MiniContract, 'styles'>, applicationEntryIds: readonly string[]): MiniStylePlugin;
|
|
124
129
|
/**
|
|
125
130
|
* Produces native CSS and JavaScript from one live-graph projection.
|
|
126
131
|
*
|
|
127
132
|
* The function receives every stateful dependency explicitly so tests and both output modes execute the same algorithm. It
|
|
128
|
-
* completes stylesheet conversion before JavaScript conversion and returns bytes without
|
|
133
|
+
* completes stylesheet conversion and optional minification before JavaScript conversion and returns bytes without publication.
|
|
129
134
|
*/
|
|
130
135
|
export declare function finalizeOutput(entryIds: readonly string[], styleByModuleId: ReadonlyMap<string, Readonly<{
|
|
131
136
|
css: string | undefined;
|
|
@@ -135,7 +140,7 @@ export declare function finalizeOutput(entryIds: readonly string[], styleByModul
|
|
|
135
140
|
}>>, getModuleInfo: (moduleId: string) => Readonly<{
|
|
136
141
|
importedIds: readonly string[];
|
|
137
142
|
dynamicallyImportedIds: readonly string[];
|
|
138
|
-
}> | null | undefined, miniTransformer: MiniTransformer, javaScript: readonly JavaScriptArtifact[]): Promise<{
|
|
143
|
+
}> | null | undefined, miniTransformer: MiniTransformer, javaScript: readonly JavaScriptArtifact[], stylesheetOptions: Parameters<typeof minifyMiniStylesheet>[1]): Promise<{
|
|
139
144
|
javaScript: string[];
|
|
140
145
|
stylesheet: string;
|
|
141
146
|
}>;
|
package/dist/options.d.ts
CHANGED
|
@@ -92,6 +92,20 @@ export interface VptOptions {
|
|
|
92
92
|
* The file is emitted only when this value is provided for a `wx` build. It is ignored for ZFB and H5.
|
|
93
93
|
*/
|
|
94
94
|
sitemapJson?: VptJsonObject;
|
|
95
|
+
/**
|
|
96
|
+
* Add JavaScript and Web APIs that your mini app needs but its host may not provide.
|
|
97
|
+
*
|
|
98
|
+
* Use core-js module names without the `core-js/modules/` prefix or `.js` suffix; no separate core-js installation is needed.
|
|
99
|
+
* For example, `web.url` provides `URL` and `URLSearchParams`, while `es.array.at` provides `Array.prototype.at`.
|
|
100
|
+
* On WX, use `globalThis.URL` or add `define: { URL: 'globalThis.URL' }` to your Vite config for bare `URL` references.
|
|
101
|
+
*
|
|
102
|
+
* Selected polyfills run before your app in development and production, updating global APIs and prototypes when needed.
|
|
103
|
+
* Omit this option or use `[]` to add no optional polyfills. H5 ignores this option.
|
|
104
|
+
*
|
|
105
|
+
* @example
|
|
106
|
+
* polyfills: ['web.url', 'es.array.at']
|
|
107
|
+
*/
|
|
108
|
+
polyfills?: readonly string[];
|
|
95
109
|
/**
|
|
96
110
|
* Selects the Mini Program development update mode. Omission uses `devtools`.
|
|
97
111
|
*
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
// Install the selected polyfills before the runtime or application uses them.
|
|
2
|
+
// @ts-expect-error: The Mini build resolves this private polyfills entry.
|
|
3
|
+
import '\0vpt:mini-polyfills';
|
|
1
4
|
// Install the minimal SystemJS loader and its synchronous-import extension before any native entry requests a capsule.
|
|
2
5
|
import '../systemjs/system-core.js';
|
|
3
6
|
import { transport } from './transport.js';
|
|
@@ -7,7 +7,6 @@
|
|
|
7
7
|
* and ACK form one application transaction; it has no file-delivery or interpreter policy of its own.
|
|
8
8
|
*/
|
|
9
9
|
import { runtimeControlEvent, runtimeReportEvent } from './hmr-protocol.js';
|
|
10
|
-
import { polyfillQueueMicrotask } from './polyfill/polyfill-queue-microtask.js';
|
|
11
10
|
/** Shared no-op CSS contract because physical rebuilds replace styles wholesale. */
|
|
12
11
|
const hotContextInternals = Object.freeze({
|
|
13
12
|
updateStyle() { },
|
|
@@ -79,10 +78,6 @@ export class MiniHmrRuntime extends DevRuntime {
|
|
|
79
78
|
// The base has no messenger: the engine tracks per-client shipped payloads instead
|
|
80
79
|
// of executed module ids, so the Mini Program host registers the client session itself.
|
|
81
80
|
super('');
|
|
82
|
-
// Rolldown schedules each generated React Refresh boundary with queueMicrotask. This shared runtime is constructed before
|
|
83
|
-
// any application factory, so installing the language-global fallback here covers every Mini target and development mode
|
|
84
|
-
// at the one common execution boundary while leaving production output untouched.
|
|
85
|
-
polyfillQueueMicrotask(globalThis);
|
|
86
81
|
this.connectSocket = connectSocket;
|
|
87
82
|
}
|
|
88
83
|
/**
|
|
@@ -11,15 +11,10 @@ class InterpreterHmrRuntime extends MiniHmrRuntime {
|
|
|
11
11
|
installPatch;
|
|
12
12
|
constructor(connectSocket) {
|
|
13
13
|
super(connectSocket);
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
* Mini polyfills. Import the resulting host function explicitly so interpreted Rolldown Refresh wrappers resolve the
|
|
19
|
-
* same queue as physical chunks; otherwise their first free `queueMicrotask` lookup aborts the patch before registration.
|
|
20
|
-
*/
|
|
21
|
-
interpreter.import('queueMicrotask', globalThis.queueMicrotask);
|
|
22
|
-
this.installPatch = (patch) => interpreter.run(patch.code);
|
|
14
|
+
// Trusted application patches share live host globals, including APIs installed during app startup, rather than Sval's
|
|
15
|
+
// module-time sandbox snapshot. A function scope keeps patch-local declarations isolated, as in native HMR factories.
|
|
16
|
+
const interpreter = new Sval({ sandBox: false });
|
|
17
|
+
this.installPatch = (patch) => interpreter.run(`(() => {\n${patch.code}\n})();`);
|
|
23
18
|
}
|
|
24
19
|
onSocketEvent(info, event, data) {
|
|
25
20
|
if (event !== interpreterServerEvent) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vite-plugin-taro",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.4-beta.0",
|
|
4
4
|
"author": "sep2",
|
|
5
5
|
"description": "Vite 8 plugin for building one React/Taro codebase for WeChat, Alipay, and H5 targets.",
|
|
6
6
|
"type": "module",
|
|
@@ -59,11 +59,13 @@
|
|
|
59
59
|
"@tailwindcss/vite": "4.3.3",
|
|
60
60
|
"@tarojs/shared": "4.2.1",
|
|
61
61
|
"@vitejs/plugin-react": "^6.1.1",
|
|
62
|
+
"core-js": "^3.50.0",
|
|
63
|
+
"lightningcss": "1.33.0",
|
|
62
64
|
"react-reconciler": "0.34.0",
|
|
63
65
|
"rolldown": "1.2.8",
|
|
64
66
|
"sval": "0.6.12",
|
|
65
67
|
"tailwindcss": "^4.3.3",
|
|
66
|
-
"vite-plugin-taro-runtime": "0.7.
|
|
68
|
+
"vite-plugin-taro-runtime": "0.7.4-beta.0"
|
|
67
69
|
},
|
|
68
70
|
"peerDependencies": {
|
|
69
71
|
"react": "^19.3.0",
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
type QueueMicrotask = (callback: () => void) => void;
|
|
2
|
-
type QueueMicrotaskGlobal = {
|
|
3
|
-
queueMicrotask?: QueueMicrotask;
|
|
4
|
-
};
|
|
5
|
-
/**
|
|
6
|
-
* Polyfills the microtask primitive required by Rolldown's development React Refresh boundaries.
|
|
7
|
-
*
|
|
8
|
-
* Mini Program AppService engines do not share a `queueMicrotask` compatibility baseline, while every supported engine provides
|
|
9
|
-
* Promise jobs. Every target adapter constructs its selected development runtime before any application factory evaluates, so
|
|
10
|
-
* defining the primitive there covers WX and ZFB in every development mode. Reusing one resolved Promise preserves FIFO ordering
|
|
11
|
-
* without rewriting generated modules, delaying registration to a timer task, or adding unused code to production builds.
|
|
12
|
-
*/
|
|
13
|
-
export declare function polyfillQueueMicrotask(runtimeGlobal: QueueMicrotaskGlobal): void;
|
|
14
|
-
export {};
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Polyfills the microtask primitive required by Rolldown's development React Refresh boundaries.
|
|
3
|
-
*
|
|
4
|
-
* Mini Program AppService engines do not share a `queueMicrotask` compatibility baseline, while every supported engine provides
|
|
5
|
-
* Promise jobs. Every target adapter constructs its selected development runtime before any application factory evaluates, so
|
|
6
|
-
* defining the primitive there covers WX and ZFB in every development mode. Reusing one resolved Promise preserves FIFO ordering
|
|
7
|
-
* without rewriting generated modules, delaying registration to a timer task, or adding unused code to production builds.
|
|
8
|
-
*/
|
|
9
|
-
export function polyfillQueueMicrotask(runtimeGlobal) {
|
|
10
|
-
if (runtimeGlobal.queueMicrotask !== undefined)
|
|
11
|
-
return;
|
|
12
|
-
const resolvedPromise = Promise.resolve();
|
|
13
|
-
// This is the one intentional global mutation: every independently bundled development chunk must resolve the same host
|
|
14
|
-
// primitive, and assigning the real global is the only scope shared by the injected runtime and later application factories.
|
|
15
|
-
runtimeGlobal.queueMicrotask = (callback) => {
|
|
16
|
-
void resolvedPromise.then(callback);
|
|
17
|
-
};
|
|
18
|
-
}
|