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
|
@@ -0,0 +1,331 @@
|
|
|
1
|
+
// biome-ignore-start lint: vendored SystemJS core
|
|
2
|
+
/*
|
|
3
|
+
* SystemJS Core
|
|
4
|
+
*
|
|
5
|
+
* Provides
|
|
6
|
+
* - System.import and System.importSync
|
|
7
|
+
* - System.register support for
|
|
8
|
+
* live bindings, function hoisting through circular references,
|
|
9
|
+
* reexports, dynamic import, import.meta.url, top-level await
|
|
10
|
+
* - System.getRegister to get the registration
|
|
11
|
+
* - Symbol.toStringTag support in Module objects
|
|
12
|
+
* - Hookable System.createContext to customize import.meta
|
|
13
|
+
*
|
|
14
|
+
* Core comes with no System.prototype.resolve or
|
|
15
|
+
* System.prototype.instantiate implementations
|
|
16
|
+
*/
|
|
17
|
+
var envGlobal = global;
|
|
18
|
+
var hasSymbol = typeof Symbol !== 'undefined';
|
|
19
|
+
function errMsg(errCode, msg) {
|
|
20
|
+
return (msg || '') + ' (SystemJS https://github.com/systemjs/systemjs/blob/main/docs/errors.md#' + errCode + ')';
|
|
21
|
+
}
|
|
22
|
+
export { REGISTRY, systemJSPrototype };
|
|
23
|
+
var toStringTag = hasSymbol && Symbol.toStringTag;
|
|
24
|
+
var REGISTRY = hasSymbol ? Symbol() : '@';
|
|
25
|
+
function SystemJS() {
|
|
26
|
+
this[REGISTRY] = {};
|
|
27
|
+
}
|
|
28
|
+
var systemJSPrototype = SystemJS.prototype;
|
|
29
|
+
systemJSPrototype.import = function (id, parentId, meta) {
|
|
30
|
+
var loader = this;
|
|
31
|
+
if (parentId && typeof parentId === 'object')
|
|
32
|
+
meta = parentId;
|
|
33
|
+
var load = getOrCreateLoad(loader, id, undefined, meta);
|
|
34
|
+
return Promise.resolve(load.C || topLevelLoad(loader, load));
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* Instantiates, links, and evaluates a graph without yielding the current JavaScript turn.
|
|
38
|
+
*
|
|
39
|
+
* WX placement guarantees that every registration in a synchronous graph uses the main-package transport. Encountering
|
|
40
|
+
* a thenable therefore indicates a fatal placement invariant violation. No rollback is attempted: rows already published
|
|
41
|
+
* to the shared registry remain there and the current runtime heap must not be reused.
|
|
42
|
+
*/
|
|
43
|
+
systemJSPrototype.importSync = function (id) {
|
|
44
|
+
var loader = this;
|
|
45
|
+
var load = linkLoadSync(loader, id);
|
|
46
|
+
var execution = postOrderExec(loader, load, {});
|
|
47
|
+
if (isThenable(execution))
|
|
48
|
+
throw createAsyncGraphError(id);
|
|
49
|
+
// Share completion and namespace identity with normal System.import calls.
|
|
50
|
+
load.C = load.n;
|
|
51
|
+
return load.n;
|
|
52
|
+
};
|
|
53
|
+
// Hookable createContext function -> allowing eg custom import meta
|
|
54
|
+
systemJSPrototype.createContext = function (parentId) {
|
|
55
|
+
return { url: parentId };
|
|
56
|
+
};
|
|
57
|
+
/** Publishes one synchronous row before linking dependencies so cycles observe the same live namespace. */
|
|
58
|
+
function linkLoadSync(loader, id) {
|
|
59
|
+
var existing = loader[REGISTRY][id];
|
|
60
|
+
if (existing)
|
|
61
|
+
return existing;
|
|
62
|
+
var registration = loader.instantiate(id);
|
|
63
|
+
if (isThenable(registration))
|
|
64
|
+
throw createAsyncGraphError(id);
|
|
65
|
+
if (!registration)
|
|
66
|
+
throw Error(errMsg(2, id));
|
|
67
|
+
// This row is intentionally mutable SystemJS-owned linking and execution state.
|
|
68
|
+
var load = {
|
|
69
|
+
id: id,
|
|
70
|
+
i: [],
|
|
71
|
+
n: createModuleNamespace(),
|
|
72
|
+
h: false,
|
|
73
|
+
d: undefined,
|
|
74
|
+
e: undefined,
|
|
75
|
+
C: undefined
|
|
76
|
+
};
|
|
77
|
+
loader[REGISTRY][id] = load;
|
|
78
|
+
var declared = registration[1](createExport(load), registration[1].length === 2 ? createDeclarationContext(loader, id) : undefined);
|
|
79
|
+
load.e = declared.execute || function () { };
|
|
80
|
+
var setters = declared.setters || [];
|
|
81
|
+
load.d = registration[0].map(function (dependency, index) {
|
|
82
|
+
var dependencyLoad = linkLoadSync(loader, dependency);
|
|
83
|
+
var setter = setters[index];
|
|
84
|
+
if (setter) {
|
|
85
|
+
dependencyLoad.i.push(setter);
|
|
86
|
+
if (dependencyLoad.h || dependencyLoad.C === dependencyLoad.n)
|
|
87
|
+
setter(dependencyLoad.n);
|
|
88
|
+
}
|
|
89
|
+
return dependencyLoad;
|
|
90
|
+
});
|
|
91
|
+
return load;
|
|
92
|
+
}
|
|
93
|
+
/** Supplies dynamic import and import.meta using the canonical IDs emitted at build time. */
|
|
94
|
+
function createDeclarationContext(loader, id) {
|
|
95
|
+
return {
|
|
96
|
+
import: function (dependency, meta) {
|
|
97
|
+
return loader.import(dependency, undefined, meta);
|
|
98
|
+
},
|
|
99
|
+
meta: loader.createContext(id)
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
/** Creates a live module namespace shared by both completion policies. */
|
|
103
|
+
function createModuleNamespace() {
|
|
104
|
+
var namespace = Object.create(null);
|
|
105
|
+
if (toStringTag)
|
|
106
|
+
Object.defineProperty(namespace, toStringTag, { value: 'Module' });
|
|
107
|
+
return namespace;
|
|
108
|
+
}
|
|
109
|
+
/** Creates the shared live-binding publisher used by synchronous and asynchronous load records. */
|
|
110
|
+
function createExport(load) {
|
|
111
|
+
return function (name, value) {
|
|
112
|
+
load.h = true;
|
|
113
|
+
// This flag coalesces object-form exports into one importer notification pass.
|
|
114
|
+
var changed = false;
|
|
115
|
+
if (typeof name === 'string') {
|
|
116
|
+
if (!(name in load.n) || load.n[name] !== value) {
|
|
117
|
+
load.n[name] = value;
|
|
118
|
+
changed = true;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
else {
|
|
122
|
+
for (var property in name) {
|
|
123
|
+
var propertyValue = name[property];
|
|
124
|
+
if (!(property in load.n) || load.n[property] !== propertyValue) {
|
|
125
|
+
load.n[property] = propertyValue;
|
|
126
|
+
changed = true;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
if (name && name.__esModule)
|
|
130
|
+
load.n.__esModule = name.__esModule;
|
|
131
|
+
}
|
|
132
|
+
if (changed) {
|
|
133
|
+
for (var i = 0; i < load.i.length; i++) {
|
|
134
|
+
var setter = load.i[i];
|
|
135
|
+
if (setter)
|
|
136
|
+
setter(load.n);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
return value;
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
/** Accepts cross-realm and custom thenables rather than only native Promises. */
|
|
143
|
+
function isThenable(value) {
|
|
144
|
+
return (value !== null && (typeof value === 'object' || typeof value === 'function') && typeof value.then === 'function');
|
|
145
|
+
}
|
|
146
|
+
function createAsyncGraphError(id) {
|
|
147
|
+
return Error('Cannot synchronously import ' + id + ': module graph is asynchronous');
|
|
148
|
+
}
|
|
149
|
+
var lastRegister;
|
|
150
|
+
systemJSPrototype.register = function (deps, declare, metas) {
|
|
151
|
+
lastRegister = [deps, declare, metas];
|
|
152
|
+
};
|
|
153
|
+
/*
|
|
154
|
+
* getRegister provides the last anonymous System.register call
|
|
155
|
+
*/
|
|
156
|
+
systemJSPrototype.getRegister = function () {
|
|
157
|
+
var _lastRegister = lastRegister;
|
|
158
|
+
lastRegister = undefined;
|
|
159
|
+
return _lastRegister;
|
|
160
|
+
};
|
|
161
|
+
export function getOrCreateLoad(loader, id, firstParentUrl, meta) {
|
|
162
|
+
var load = loader[REGISTRY][id];
|
|
163
|
+
if (load)
|
|
164
|
+
return load;
|
|
165
|
+
var importerSetters = [];
|
|
166
|
+
var ns = createModuleNamespace();
|
|
167
|
+
var instantiatePromise = Promise.resolve()
|
|
168
|
+
.then(function () {
|
|
169
|
+
return loader.instantiate(id, firstParentUrl, meta);
|
|
170
|
+
})
|
|
171
|
+
.then(function (registration) {
|
|
172
|
+
if (!registration)
|
|
173
|
+
throw Error(errMsg(2, id));
|
|
174
|
+
var declared = registration[1](createExport(load), registration[1].length === 2 ? createDeclarationContext(loader, id) : undefined);
|
|
175
|
+
load.e = declared.execute || function () { };
|
|
176
|
+
return [registration[0], declared.setters || [], registration[2] || []];
|
|
177
|
+
}, function (err) {
|
|
178
|
+
load.e = null;
|
|
179
|
+
load.er = err;
|
|
180
|
+
throw err;
|
|
181
|
+
});
|
|
182
|
+
var linkPromise = instantiatePromise.then(function (instantiation) {
|
|
183
|
+
return Promise.all(instantiation[0].map(function (dep, i) {
|
|
184
|
+
var setter = instantiation[1][i];
|
|
185
|
+
var meta = instantiation[2][i];
|
|
186
|
+
var depLoad = getOrCreateLoad(loader, dep, id, meta);
|
|
187
|
+
// depLoad.I may be undefined for already-evaluated
|
|
188
|
+
return Promise.resolve(depLoad.I).then(function () {
|
|
189
|
+
if (setter) {
|
|
190
|
+
depLoad.i.push(setter);
|
|
191
|
+
// only run early setters when there are hoisted exports of that module
|
|
192
|
+
// the timing works here as pending hoisted export calls will trigger through importerSetters
|
|
193
|
+
if (depLoad.h || !depLoad.I)
|
|
194
|
+
setter(depLoad.n);
|
|
195
|
+
}
|
|
196
|
+
return depLoad;
|
|
197
|
+
});
|
|
198
|
+
})).then(function (depLoads) {
|
|
199
|
+
load.d = depLoads;
|
|
200
|
+
});
|
|
201
|
+
});
|
|
202
|
+
// Capital letter = a promise function
|
|
203
|
+
return (load = loader[REGISTRY][id] =
|
|
204
|
+
{
|
|
205
|
+
id: id,
|
|
206
|
+
// importerSetters, the setters functions registered to this dependency
|
|
207
|
+
// we retain this to add more later
|
|
208
|
+
i: importerSetters,
|
|
209
|
+
// module namespace object
|
|
210
|
+
n: ns,
|
|
211
|
+
// extra module information for import assertion
|
|
212
|
+
// shape like: { assert: { type: 'xyz' } }
|
|
213
|
+
m: meta,
|
|
214
|
+
// instantiate
|
|
215
|
+
I: instantiatePromise,
|
|
216
|
+
// link
|
|
217
|
+
L: linkPromise,
|
|
218
|
+
// whether it has hoisted exports
|
|
219
|
+
h: false,
|
|
220
|
+
// On instantiate completion we have populated:
|
|
221
|
+
// dependency load records
|
|
222
|
+
d: undefined,
|
|
223
|
+
// execution function
|
|
224
|
+
e: undefined,
|
|
225
|
+
// On execution we have populated:
|
|
226
|
+
// the execution error if any
|
|
227
|
+
er: undefined,
|
|
228
|
+
// in the case of TLA, the execution promise
|
|
229
|
+
E: undefined,
|
|
230
|
+
// On execution, L, I, E cleared
|
|
231
|
+
// Promise for top-level completion
|
|
232
|
+
C: undefined,
|
|
233
|
+
// parent instantiator / executor
|
|
234
|
+
p: undefined
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
function instantiateAll(loader, load, parent, loaded) {
|
|
238
|
+
if (!loaded[load.id]) {
|
|
239
|
+
loaded[load.id] = true;
|
|
240
|
+
// load.L may be undefined for already-instantiated
|
|
241
|
+
return Promise.resolve(load.L)
|
|
242
|
+
.then(function () {
|
|
243
|
+
if (!load.p || load.p.e === null)
|
|
244
|
+
load.p = parent;
|
|
245
|
+
return Promise.all(load.d.map(function (dep) {
|
|
246
|
+
return instantiateAll(loader, dep, parent, loaded);
|
|
247
|
+
}));
|
|
248
|
+
})
|
|
249
|
+
.catch(function (err) {
|
|
250
|
+
if (load.er)
|
|
251
|
+
throw err;
|
|
252
|
+
load.e = null;
|
|
253
|
+
throw err;
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
function topLevelLoad(loader, load) {
|
|
258
|
+
return (load.C = instantiateAll(loader, load, load, {})
|
|
259
|
+
.then(function () {
|
|
260
|
+
return postOrderExec(loader, load, {});
|
|
261
|
+
})
|
|
262
|
+
.then(function () {
|
|
263
|
+
return load.n;
|
|
264
|
+
}));
|
|
265
|
+
}
|
|
266
|
+
// the closest we can get to call(undefined)
|
|
267
|
+
var nullContext = Object.freeze(Object.create(null));
|
|
268
|
+
// returns a promise if and only if a top-level await subgraph
|
|
269
|
+
// throws on sync errors
|
|
270
|
+
function postOrderExec(loader, load, seen) {
|
|
271
|
+
if (seen[load.id])
|
|
272
|
+
return;
|
|
273
|
+
seen[load.id] = true;
|
|
274
|
+
if (!load.e) {
|
|
275
|
+
if (load.er)
|
|
276
|
+
throw load.er;
|
|
277
|
+
if (load.E)
|
|
278
|
+
return load.E;
|
|
279
|
+
return;
|
|
280
|
+
}
|
|
281
|
+
// From here we're about to execute the load.
|
|
282
|
+
// Because the execution may be async, we pop the `load.e` first.
|
|
283
|
+
// So `load.e === null` always means the load has been executed or is executing.
|
|
284
|
+
// To inspect the state:
|
|
285
|
+
// - If `load.er` is truthy, the execution has threw or has been rejected;
|
|
286
|
+
// - otherwise, either the `load.E` is a promise, means it's under async execution, or
|
|
287
|
+
// - the `load.E` is null, means the load has completed the execution or has been async resolved.
|
|
288
|
+
var exec = load.e;
|
|
289
|
+
load.e = null;
|
|
290
|
+
// deps execute first, unless circular
|
|
291
|
+
var depLoadPromises;
|
|
292
|
+
load.d.forEach(function (depLoad) {
|
|
293
|
+
try {
|
|
294
|
+
var depLoadPromise = postOrderExec(loader, depLoad, seen);
|
|
295
|
+
if (depLoadPromise)
|
|
296
|
+
(depLoadPromises = depLoadPromises || []).push(depLoadPromise);
|
|
297
|
+
}
|
|
298
|
+
catch (err) {
|
|
299
|
+
load.er = err;
|
|
300
|
+
throw err;
|
|
301
|
+
}
|
|
302
|
+
});
|
|
303
|
+
if (depLoadPromises)
|
|
304
|
+
return Promise.all(depLoadPromises).then(doExec);
|
|
305
|
+
return doExec();
|
|
306
|
+
function doExec() {
|
|
307
|
+
try {
|
|
308
|
+
var execPromise = exec.call(nullContext);
|
|
309
|
+
if (execPromise) {
|
|
310
|
+
execPromise = execPromise.then(function () {
|
|
311
|
+
load.C = load.n;
|
|
312
|
+
load.E = null; // indicates completion
|
|
313
|
+
}, function (err) {
|
|
314
|
+
load.er = err;
|
|
315
|
+
load.E = null;
|
|
316
|
+
throw err;
|
|
317
|
+
});
|
|
318
|
+
return (load.E = execPromise);
|
|
319
|
+
}
|
|
320
|
+
// (should be a promise, but a minify optimization to leave out Promise.resolve)
|
|
321
|
+
load.C = load.n;
|
|
322
|
+
load.L = load.I = undefined;
|
|
323
|
+
}
|
|
324
|
+
catch (err) {
|
|
325
|
+
load.er = err;
|
|
326
|
+
throw err;
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
envGlobal.System = new SystemJS();
|
|
331
|
+
// biome-ignore-end lint: vendored SystemJS core
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vite-plugin-taro",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"author": "sep2",
|
|
5
5
|
"description": "Vite 8 plugin for building one React/Taro codebase for WeChat Mini Program and H5 targets.",
|
|
6
6
|
"type": "module",
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"client.d.ts",
|
|
34
34
|
"LICENSE",
|
|
35
35
|
"README.md",
|
|
36
|
-
"README.
|
|
36
|
+
"README.en.md"
|
|
37
37
|
],
|
|
38
38
|
"keywords": [
|
|
39
39
|
"vite",
|
|
@@ -48,12 +48,17 @@
|
|
|
48
48
|
"access": "public"
|
|
49
49
|
},
|
|
50
50
|
"engines": {
|
|
51
|
-
"node": ">=
|
|
51
|
+
"node": "^22.18.0 || >=24.11.0"
|
|
52
52
|
},
|
|
53
53
|
"dependencies": {
|
|
54
|
-
"@babel/core": "^
|
|
54
|
+
"@babel/core": "^8.0.1",
|
|
55
|
+
"@babel/generator": "^8.0.0",
|
|
56
|
+
"@babel/plugin-transform-dynamic-import": "^8.0.1",
|
|
57
|
+
"@babel/plugin-transform-modules-commonjs": "^8.0.1",
|
|
58
|
+
"@babel/plugin-transform-modules-systemjs": "^8.0.1",
|
|
55
59
|
"@rolldown/plugin-babel": "^0.2.3",
|
|
56
|
-
"@tailwindcss-mangle/engine": "0.
|
|
60
|
+
"@tailwindcss-mangle/engine": "0.2.0",
|
|
61
|
+
"@weapp-tailwindcss/postcss": "3.2.8",
|
|
57
62
|
"@tarojs/components": "^4.2.0",
|
|
58
63
|
"@tarojs/helper": "^4.2.0",
|
|
59
64
|
"@tarojs/plugin-platform-h5": "^4.2.0",
|
|
@@ -61,30 +66,32 @@
|
|
|
61
66
|
"@tarojs/router": "^4.2.0",
|
|
62
67
|
"@tarojs/runtime": "^4.2.0",
|
|
63
68
|
"@tarojs/taro": "^4.2.0",
|
|
64
|
-
"@vitejs/plugin-react": "^6.0.
|
|
69
|
+
"@vitejs/plugin-react": "^6.0.5",
|
|
65
70
|
"babel-plugin-transform-taroapi": "^4.2.0",
|
|
66
71
|
"picocolors": "^1.1.1",
|
|
72
|
+
"react-reconciler": "0.33.0",
|
|
67
73
|
"react-refresh": "^0.18.0",
|
|
68
|
-
"
|
|
69
|
-
"
|
|
70
|
-
"
|
|
71
|
-
"@tarojs/react": "npm:vite-plugin-taro-react@0.
|
|
74
|
+
"rolldown": "~1.2.2",
|
|
75
|
+
"tailwindcss": "^4.3.3",
|
|
76
|
+
"weapp-tailwindcss": "^5.2.11",
|
|
77
|
+
"@tarojs/plugin-framework-react": "npm:vite-plugin-taro-plugin-framework-react@0.4.0",
|
|
78
|
+
"@tarojs/react": "npm:vite-plugin-taro-react@0.4.0"
|
|
72
79
|
},
|
|
73
80
|
"peerDependencies": {
|
|
74
81
|
"react": "^19.0.0",
|
|
75
82
|
"react-dom": "^19.0.0",
|
|
76
|
-
"vite": "^8.
|
|
83
|
+
"vite": "^8.2.0"
|
|
77
84
|
},
|
|
78
85
|
"devDependencies": {
|
|
79
|
-
"@types/babel__core": "^7.20.5",
|
|
80
86
|
"@types/node": "^26.1.1",
|
|
81
87
|
"@types/react": "^19.2.17",
|
|
88
|
+
"@types/react-dom": "^19.2.3",
|
|
82
89
|
"@types/react-refresh": "^0.14.7",
|
|
83
90
|
"typescript": "^7.0.2",
|
|
84
|
-
"vite": "^8.
|
|
91
|
+
"vite": "^8.2.0"
|
|
85
92
|
},
|
|
86
93
|
"scripts": {
|
|
87
|
-
"build": "node ../../scripts/sync-plugin-readme.ts && node ../../scripts/clean-directory.ts dist && tsc --project tsconfig.json",
|
|
94
|
+
"build": "node ../../scripts/sync-plugin-readme.ts && node ../../scripts/clean-directory.ts dist && tsc --project tsconfig.build.json",
|
|
88
95
|
"test": "node --test",
|
|
89
96
|
"typecheck": "tsc --project tsconfig.json --noEmit"
|
|
90
97
|
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { Plugin } from 'vite'
|
|
2
|
+
import { resolvePackageFile } from '../../utils/packages.ts'
|
|
3
|
+
import { clientTaroNativeId } from './constant.ts'
|
|
4
|
+
|
|
5
|
+
export const clientTaroApiId = 'virtual:taro/api'
|
|
6
|
+
const clientTaroComponentId = 'virtual:taro/components'
|
|
7
|
+
const clientTaroModules = new Map([
|
|
8
|
+
[clientTaroApiId, resolvePackageFile('dist/runtime/client/taro/api.js')],
|
|
9
|
+
[clientTaroComponentId, resolvePackageFile('dist/runtime/client/taro/component.js')],
|
|
10
|
+
[clientTaroNativeId, resolvePackageFile('dist/runtime/client/taro/define-native-component.js')]
|
|
11
|
+
])
|
|
12
|
+
|
|
13
|
+
/** Creates the target-neutral Taro facade plugin. */
|
|
14
|
+
export function createClientTaroPlugin(): Plugin {
|
|
15
|
+
return {
|
|
16
|
+
name: 'vpt:client-taro',
|
|
17
|
+
enforce: 'pre',
|
|
18
|
+
|
|
19
|
+
resolveId(id) {
|
|
20
|
+
return clientTaroModules.get(id)
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/** Maps runtime App imports to the configured application component. */
|
|
2
|
+
export const appComponentId = '\0vpt:app-component'
|
|
3
|
+
|
|
4
|
+
/** Exposes compile-time native component JSX interfaces to application modules. */
|
|
5
|
+
export const clientTaroNativeId = 'virtual:taro/native'
|
package/src/node/plugins/{conditional-directives.ts → conditional/conditional-directives.ts}
RENAMED
|
@@ -1,19 +1,25 @@
|
|
|
1
1
|
import type { Plugin } from 'vite'
|
|
2
|
-
import type { VitePluginTaroTarget } from '
|
|
3
|
-
import
|
|
4
|
-
import { normalizeModuleId } from '../utils/modules.ts'
|
|
2
|
+
import type { VitePluginTaroTarget } from '../../../options.ts'
|
|
3
|
+
import { normalizeModuleId } from '../../utils/modules.ts'
|
|
5
4
|
|
|
6
|
-
|
|
5
|
+
/** Creates source-level target conditional handling shared by H5 and WX. */
|
|
6
|
+
export function createConditionalDirectivePlugin(target: VitePluginTaroTarget): Plugin {
|
|
7
7
|
return {
|
|
8
|
-
name: '
|
|
8
|
+
name: 'vpt:conditional-directives',
|
|
9
9
|
enforce: 'pre',
|
|
10
10
|
transform(code, id) {
|
|
11
|
-
if (!isConditionalDirectiveSource(id) || !code.includes('#if'))
|
|
12
|
-
|
|
11
|
+
if (!isConditionalDirectiveSource(id) || !code.includes('#if')) {
|
|
12
|
+
return
|
|
13
|
+
}
|
|
14
|
+
return {
|
|
15
|
+
code: transformConditionalDirectives(code, target),
|
|
16
|
+
map: null
|
|
17
|
+
}
|
|
13
18
|
}
|
|
14
19
|
}
|
|
15
20
|
}
|
|
16
21
|
|
|
22
|
+
/** Tests whether an application source can contain conditional directives. */
|
|
17
23
|
function isConditionalDirectiveSource(id: string): boolean {
|
|
18
24
|
const normalizedId = normalizeModuleId(id)
|
|
19
25
|
return !normalizedId.includes('/node_modules/') && /\.(?:[cm]?[jt]sx?|css|s[ac]ss|less|styl)$/.test(normalizedId)
|
|
@@ -30,13 +36,16 @@ type DirectiveFrame = {
|
|
|
30
36
|
active: boolean
|
|
31
37
|
}
|
|
32
38
|
|
|
39
|
+
/** Keeps only the source branches active for one build target. */
|
|
33
40
|
function transformConditionalDirectives(code: string, target: VitePluginTaroTarget): string {
|
|
34
41
|
const lines = code.match(/[^\n]*(?:\n|$)/g) ?? []
|
|
35
42
|
const frames: DirectiveFrame[] = []
|
|
36
43
|
let transformed = ''
|
|
37
44
|
|
|
38
45
|
for (const line of lines) {
|
|
39
|
-
if (!line)
|
|
46
|
+
if (!line) {
|
|
47
|
+
continue
|
|
48
|
+
}
|
|
40
49
|
const directive = parseDirective(line)
|
|
41
50
|
const lineEnding = line.match(/\r?\n$/)?.[0] ?? ''
|
|
42
51
|
if (!directive) {
|
|
@@ -48,10 +57,16 @@ function transformConditionalDirectives(code: string, target: VitePluginTaroTarg
|
|
|
48
57
|
const parentActive = frames.every((frame) => frame.active)
|
|
49
58
|
const targetMatched = directive.target.toLowerCase() === target
|
|
50
59
|
const matched = directive.name === 'ifdef' ? targetMatched : !targetMatched
|
|
51
|
-
frames.push({
|
|
60
|
+
frames.push({
|
|
61
|
+
parentActive,
|
|
62
|
+
matched,
|
|
63
|
+
active: parentActive && matched
|
|
64
|
+
})
|
|
52
65
|
} else if (directive.name === 'else') {
|
|
53
66
|
const frame = frames.at(-1)
|
|
54
|
-
if (frame)
|
|
67
|
+
if (frame) {
|
|
68
|
+
frame.active = frame.parentActive && !frame.matched
|
|
69
|
+
}
|
|
55
70
|
} else {
|
|
56
71
|
frames.pop()
|
|
57
72
|
}
|
|
@@ -61,14 +76,19 @@ function transformConditionalDirectives(code: string, target: VitePluginTaroTarg
|
|
|
61
76
|
return transformed
|
|
62
77
|
}
|
|
63
78
|
|
|
79
|
+
/** Parses one supported Taro conditional directive. */
|
|
64
80
|
function parseDirective(line: string): Directive | undefined {
|
|
65
81
|
const match = line.match(/^\s*(?:(?:\/\/)|(?:\/\*))\s*#(ifdef|ifndef|if|elif|else|endif)\b([^*\r\n]*)/)
|
|
66
|
-
if (!match)
|
|
82
|
+
if (!match) {
|
|
83
|
+
return
|
|
84
|
+
}
|
|
67
85
|
const name = match[1]
|
|
68
86
|
if (name === 'if' || name === 'elif') {
|
|
69
|
-
throw new Error(`
|
|
87
|
+
throw new Error(`vpt no longer supports #${name}; use #ifdef, #ifndef, or #else`)
|
|
88
|
+
}
|
|
89
|
+
if (name !== 'ifdef' && name !== 'ifndef' && name !== 'else' && name !== 'endif') {
|
|
90
|
+
return
|
|
70
91
|
}
|
|
71
|
-
if (name !== 'ifdef' && name !== 'ifndef' && name !== 'else' && name !== 'endif') return
|
|
72
92
|
return {
|
|
73
93
|
name,
|
|
74
94
|
target: match[2]?.replace(/\*\/$/, '').trim() ?? ''
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import path from 'node:path'
|
|
2
|
+
import { createStyleHandler } from '@weapp-tailwindcss/postcss'
|
|
3
|
+
import type { Plugin, PluginOption, Rolldown } from 'vite'
|
|
4
|
+
import { WeappTailwindcss } from 'weapp-tailwindcss/vite'
|
|
5
|
+
import type { VitePluginTaroTarget } from '../../../options.ts'
|
|
6
|
+
import { packageRequire } from '../../utils/packages.ts'
|
|
7
|
+
|
|
8
|
+
// Keep the Vite plugin and the compatibility finalizer on identical WX conversion settings. A difference here can
|
|
9
|
+
// make the second pass preserve browser units or apply a transformation that the first pass did not expect.
|
|
10
|
+
const tailwindcssBasedir = path.dirname(packageRequire.resolve('tailwindcss/package.json'))
|
|
11
|
+
|
|
12
|
+
const wxStyleOptions = {
|
|
13
|
+
cssCalc: false,
|
|
14
|
+
autoprefixer: false,
|
|
15
|
+
rem2rpx: true,
|
|
16
|
+
px2rpx: true
|
|
17
|
+
} as const
|
|
18
|
+
|
|
19
|
+
/** Creates the target-aware Tailwind CSS plugins. */
|
|
20
|
+
export function createCssPlugins(target: VitePluginTaroTarget): PluginOption[] {
|
|
21
|
+
const wx = target === 'wx'
|
|
22
|
+
|
|
23
|
+
return [
|
|
24
|
+
...(WeappTailwindcss({
|
|
25
|
+
appType: 'weapp-vite',
|
|
26
|
+
// WX must enable this for split Tailwind imports such as `tailwindcss/theme.css`. Otherwise Vite's
|
|
27
|
+
// PostCSS resolver tries to resolve those imports from the application and fails when Tailwind is owned
|
|
28
|
+
// by vpt. The web generator consumes the imports before that resolver runs, so H5 keeps the
|
|
29
|
+
// upstream default.
|
|
30
|
+
rewriteCssImports: wx,
|
|
31
|
+
// Tailwind is a plugin dependency, not an application dependency. Give weapp-tailwindcss the owning package
|
|
32
|
+
// directory explicitly so bundled development and strict package managers resolve split CSS imports equally.
|
|
33
|
+
tailwindcssBasedir,
|
|
34
|
+
generator: {
|
|
35
|
+
target: wx ? 'weapp' : 'web'
|
|
36
|
+
// webCompat: {
|
|
37
|
+
// preset: 'legacy-web'
|
|
38
|
+
// }
|
|
39
|
+
},
|
|
40
|
+
cssOptions: {
|
|
41
|
+
...wxStyleOptions,
|
|
42
|
+
autoprefixer: !wx
|
|
43
|
+
},
|
|
44
|
+
logLevel: 'warn'
|
|
45
|
+
}) ?? []),
|
|
46
|
+
wx ? createWxssCompatibilityFinalizer() : undefined
|
|
47
|
+
]
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Completes WXSS adaptation that weapp-tailwindcss leaves pending after rewriting split Tailwind imports.
|
|
52
|
+
*
|
|
53
|
+
* `rewriteCssImports: true` makes the early Vite transform generate the Tailwind CSS, but the non-web generator
|
|
54
|
+
* also defers CSS adaptation. The generated asset is consequently browser-shaped
|
|
55
|
+
* CSS containing values and syntax such as `rem`, escaped class selectors, and `@property`. It is then recorded as a
|
|
56
|
+
* processed Vite asset, so the upstream output finalizer does not perform the missing complete WXSS adaptation.
|
|
57
|
+
*
|
|
58
|
+
* This plugin runs after the upstream finalizer, repeats only the compatibility transform, and restores the captured
|
|
59
|
+
* global asset to WeChat's required `app.wxss` path. Exact path correlation leaves Page WXSS companions untouched.
|
|
60
|
+
* Remove it when upstream both completes adaptation and preserves the bundler-selected filename.
|
|
61
|
+
*/
|
|
62
|
+
function createWxssCompatibilityFinalizer(): Plugin {
|
|
63
|
+
// This compatibility pass only needs the PostCSS style pipeline. Creating a complete weapp-tailwindcss context here
|
|
64
|
+
// would initialize another Tailwind compiler and source scanner for CSS that the upstream Vite plugin already generated.
|
|
65
|
+
const transformWxss = createStyleHandler(wxStyleOptions)
|
|
66
|
+
|
|
67
|
+
return {
|
|
68
|
+
name: 'vpt:wxss-compatibility-finalizer',
|
|
69
|
+
enforce: 'post',
|
|
70
|
+
generateBundle: {
|
|
71
|
+
order: 'post',
|
|
72
|
+
async handler(_, bundle) {
|
|
73
|
+
// With cssCodeSplit: false the global style is the only asset with a logical
|
|
74
|
+
// .css source name, even when an earlier hook already changed its final suffix.
|
|
75
|
+
const globalStyleAsset = Object.values(bundle).find(
|
|
76
|
+
(output): output is Rolldown.OutputAsset =>
|
|
77
|
+
output.type === 'asset' &&
|
|
78
|
+
(output.fileName.replaceAll('\\', '/').endsWith('.css') ||
|
|
79
|
+
output.names.some((name) => name.replaceAll('\\', '/').endsWith('.css')))
|
|
80
|
+
)
|
|
81
|
+
if (!globalStyleAsset) return
|
|
82
|
+
|
|
83
|
+
// Both finalizers use a post-ordered generateBundle hook. Array order places this hook after the
|
|
84
|
+
// upstream finalizer, where the single Vite global style asset has its final contents and filename.
|
|
85
|
+
const source =
|
|
86
|
+
typeof globalStyleAsset.source === 'string'
|
|
87
|
+
? globalStyleAsset.source
|
|
88
|
+
: new TextDecoder().decode(globalStyleAsset.source)
|
|
89
|
+
if (source.length > 0) {
|
|
90
|
+
globalStyleAsset.source = (await transformWxss(source)).css
|
|
91
|
+
}
|
|
92
|
+
globalStyleAsset.fileName = 'app.wxss'
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|