vite-plugin-taro 0.6.18 → 0.6.19
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/client.d.ts +2 -3
- package/dist/index.js +213574 -0
- package/dist/node/plugins/wx/dev/react-refresh.d.ts +14 -13
- package/dist/node/utils/packages.d.ts +2 -0
- package/package.json +26 -26
- package/dist/node/plugins/client/client-taro.js +0 -59
- package/dist/node/plugins/client/constant.js +0 -4
- package/dist/node/plugins/client/inject-taro-framework-apis.js +0 -9
- package/dist/node/plugins/conditional/conditional-directives.js +0 -76
- package/dist/node/plugins/h5/constant.js +0 -3
- package/dist/node/plugins/h5/create-stencil-client-adapter.js +0 -94
- package/dist/node/plugins/h5/plugins.js +0 -179
- package/dist/node/plugins/h5/resolver/module-resolver.js +0 -20
- package/dist/node/plugins/h5/transform-app.js +0 -48
- package/dist/node/plugins/tailwind/tailwind-css.js +0 -3
- package/dist/node/plugins/wx/dev/create-hmr-results-stream.js +0 -57
- package/dist/node/plugins/wx/dev/dev-host.js +0 -361
- package/dist/node/plugins/wx/dev/hmr-files.js +0 -56
- package/dist/node/plugins/wx/dev/host-actions.js +0 -58
- package/dist/node/plugins/wx/dev/patch-publisher.js +0 -77
- package/dist/node/plugins/wx/dev/plugins.js +0 -164
- package/dist/node/plugins/wx/dev/react-refresh.js +0 -231
- package/dist/node/plugins/wx/dev/runtime-reports.js +0 -45
- package/dist/node/plugins/wx/dev/wx-dev-options.js +0 -178
- package/dist/node/plugins/wx/module/chunk-path.js +0 -18
- package/dist/node/plugins/wx/module/module.js +0 -79
- package/dist/node/plugins/wx/native/compile-native-component-interface.js +0 -30
- package/dist/node/plugins/wx/native/create-native-component-output.js +0 -39
- package/dist/node/plugins/wx/native/native-component-assets.js +0 -76
- package/dist/node/plugins/wx/native/native-component-interface.js +0 -203
- package/dist/node/plugins/wx/output/files.js +0 -21
- package/dist/node/plugins/wx/output/relative-root.js +0 -6
- package/dist/node/plugins/wx/output/templates.js +0 -358
- package/dist/node/plugins/wx/placer/placement.js +0 -245
- package/dist/node/plugins/wx/placer/placer.js +0 -147
- package/dist/node/plugins/wx/plugins.js +0 -152
- package/dist/node/plugins/wx/render/capsule.js +0 -54
- package/dist/node/plugins/wx/render/native.js +0 -543
- package/dist/node/plugins/wx/render/system-js/string-editor.js +0 -94
- package/dist/node/plugins/wx/render/system-js/system-js.js +0 -588
- package/dist/node/plugins/wx/render/transport.js +0 -103
- package/dist/node/plugins/wx/resolve/resolver.js +0 -102
- package/dist/node/plugins/wx/resolve/specialize-app-capsule.js +0 -9
- package/dist/node/plugins/wx/resolve/specialize-page-capsule.js +0 -11
- package/dist/node/plugins/wx/styles/plugins.js +0 -459
- package/dist/node/utils/constant.js +0 -1
- package/dist/node/utils/memoize.js +0 -86
- package/dist/node/utils/modules.js +0 -22
- package/dist/node/utils/once.js +0 -20
- package/dist/node/utils/oxc-transform.js +0 -57
- package/dist/node/utils/packages.js +0 -9
- package/dist/node/utils/project-config.js +0 -8
- package/dist/node/utils/transform.js +0 -32
- package/dist/node/utils/vite.js +0 -10
- package/dist/node/vpt.js +0 -15
- package/dist/options.js +0 -1
- package/dist/vite.js +0 -1
- package/src/node/plugins/client/client-taro.ts +0 -71
- package/src/node/plugins/client/constant.ts +0 -5
- package/src/node/plugins/client/inject-taro-framework-apis.ts +0 -11
- package/src/node/plugins/conditional/conditional-directives.ts +0 -94
- package/src/node/plugins/h5/constant.ts +0 -4
- package/src/node/plugins/h5/create-stencil-client-adapter.ts +0 -111
- package/src/node/plugins/h5/plugins.ts +0 -194
- package/src/node/plugins/h5/resolver/module-resolver.ts +0 -33
- package/src/node/plugins/h5/transform-app.ts +0 -90
- package/src/node/plugins/tailwind/tailwind-css.ts +0 -4
- package/src/node/plugins/wx/dev/create-hmr-results-stream.ts +0 -71
- package/src/node/plugins/wx/dev/dev-host.ts +0 -453
- package/src/node/plugins/wx/dev/hmr-files.ts +0 -80
- package/src/node/plugins/wx/dev/host-actions.ts +0 -88
- package/src/node/plugins/wx/dev/patch-publisher.ts +0 -92
- package/src/node/plugins/wx/dev/plugins.ts +0 -176
- package/src/node/plugins/wx/dev/react-refresh.ts +0 -253
- package/src/node/plugins/wx/dev/runtime-reports.ts +0 -70
- package/src/node/plugins/wx/dev/wx-dev-options.ts +0 -226
- package/src/node/plugins/wx/module/chunk-path.ts +0 -22
- package/src/node/plugins/wx/module/module.ts +0 -110
- package/src/node/plugins/wx/native/compile-native-component-interface.ts +0 -48
- package/src/node/plugins/wx/native/create-native-component-output.ts +0 -60
- package/src/node/plugins/wx/native/native-component-assets.ts +0 -113
- package/src/node/plugins/wx/native/native-component-interface.ts +0 -267
- package/src/node/plugins/wx/output/files.ts +0 -40
- package/src/node/plugins/wx/output/relative-root.ts +0 -7
- package/src/node/plugins/wx/output/templates.ts +0 -448
- package/src/node/plugins/wx/placer/placement.ts +0 -364
- package/src/node/plugins/wx/placer/placer.ts +0 -180
- package/src/node/plugins/wx/plugins.ts +0 -183
- package/src/node/plugins/wx/render/capsule.ts +0 -57
- package/src/node/plugins/wx/render/native.ts +0 -694
- package/src/node/plugins/wx/render/system-js/string-editor.ts +0 -116
- package/src/node/plugins/wx/render/system-js/system-js.ts +0 -821
- package/src/node/plugins/wx/render/transport.ts +0 -173
- package/src/node/plugins/wx/resolve/resolver.ts +0 -145
- package/src/node/plugins/wx/resolve/specialize-app-capsule.ts +0 -27
- package/src/node/plugins/wx/resolve/specialize-page-capsule.ts +0 -29
- package/src/node/plugins/wx/styles/plugins.ts +0 -595
- package/src/node/utils/constant.ts +0 -1
- package/src/node/utils/memoize.ts +0 -149
- package/src/node/utils/modules.ts +0 -37
- package/src/node/utils/once.ts +0 -21
- package/src/node/utils/oxc-transform.ts +0 -76
- package/src/node/utils/packages.ts +0 -11
- package/src/node/utils/project-config.ts +0 -10
- package/src/node/utils/transform.ts +0 -48
- package/src/node/utils/vite.ts +0 -22
- package/src/node/vpt.ts +0 -18
- package/src/options.ts +0 -82
- package/src/runtime/client/taro/api.ts +0 -11
- package/src/runtime/client/taro/component.ts +0 -1
- package/src/runtime/client/taro/define-native-component.ts +0 -15
- package/src/runtime/h5/app.ts +0 -25
- package/src/runtime/h5/taro-css.d.ts +0 -3
- package/src/runtime/h5/taro-runtime.ts +0 -7
- package/src/runtime/wx/amphibious/bootstrap.ts +0 -17
- package/src/runtime/wx/amphibious/transport.ts +0 -8
- package/src/runtime/wx/capsule/app.ts +0 -12
- package/src/runtime/wx/capsule/component.ts +0 -7
- package/src/runtime/wx/capsule/page.ts +0 -29
- package/src/runtime/wx/capsule/taro-runtime.ts +0 -8
- package/src/runtime/wx/dev/dev-runtime.ts +0 -464
- package/src/runtime/wx/native/app.ts +0 -4
- package/src/runtime/wx/native/component.ts +0 -4
- package/src/runtime/wx/native/custom-wrapper.ts +0 -4
- package/src/runtime/wx/native/page.ts +0 -6
- package/src/runtime/wx/systemjs/LICENSE +0 -10
- package/src/runtime/wx/systemjs/system-core.js +0 -370
- package/src/runtime/wx/systemjs/system.d.ts +0 -55
- package/src/runtime/wx/wechat.d.ts +0 -56
- package/src/vite.ts +0 -2
- /package/dist/{vite.d.ts → index.d.ts} +0 -0
- /package/dist/runtime/client/taro/{define-native-component.d.ts → native.d.ts} +0 -0
- /package/dist/runtime/client/taro/{define-native-component.js → native.js} +0 -0
|
@@ -2,20 +2,21 @@ import type { Plugin } from 'vite';
|
|
|
2
2
|
/**
|
|
3
3
|
* Creates the serve-only React Refresh adaptation transforms for the wx target.
|
|
4
4
|
*
|
|
5
|
-
* @vitejs/plugin-react's generated refresh code assumes
|
|
6
|
-
*
|
|
7
|
-
* - the refresh runtime module (id-filtered): the runtime reads and assigns
|
|
8
|
-
* `window` protocol globals (rewritten to `global`) and must inject itself at evaluation;
|
|
9
|
-
* - React Reconciler: its renderer injection statically depends on the refresh runtime, fixing cold-start order;
|
|
10
|
-
* - react-family modules (filtered on free references): the DevTools hook is read as a free
|
|
11
|
-
* variable, which the WeChat runtime scope never resolves against `global` — every free
|
|
12
|
-
* reference becomes an explicit member access;
|
|
13
|
-
* - boundary modules (filtered on the guard): the preamble's `$RefreshReg$` global is not
|
|
14
|
-
* needed because the transform generates local wrappers over the imported refresh
|
|
15
|
-
* runtime, so the guard that checks for the global is removed.
|
|
5
|
+
* @vitejs/plugin-react's generated refresh code assumes an HTML preamble and a browser global scope; wx has neither. Each
|
|
6
|
+
* transform owns one distinct compatibility boundary:
|
|
16
7
|
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
8
|
+
* - The refresh runtime is selected by exact ID. It rewrites only the two browser protocol globals that React Refresh evaluates
|
|
9
|
+
* and injects its renderer hook at module evaluation, replacing the missing HTML preamble.
|
|
10
|
+
* - React Reconciler is selected by exact physical ID. Its renderer injection receives a static dependency on the refresh
|
|
11
|
+
* runtime, so hook installation cannot race renderer initialization during cold startup.
|
|
12
|
+
* - React-family modules are selected by the reserved free DevTools-hook identifier. Their expression references must resolve
|
|
13
|
+
* through WeChat's `global` object; an AST visitor edits only those identifier ranges after the filter admits the module.
|
|
14
|
+
* - Refresh boundaries are selected by Vite's generated `$RefreshReg$` guard. The AST transform removes only that web-preamble
|
|
15
|
+
* assertion because each boundary already owns local wrappers over the imported refresh runtime.
|
|
16
|
+
*
|
|
17
|
+
* These adaptations deliberately remain serve-only plugin transforms rather than target-wide `define` entries. That scope
|
|
18
|
+
* prevents development protocol behavior from leaking into production or unrelated WX modules. Plugin order also
|
|
19
|
+
* matters: Reconciler receives its static refresh dependency before the later DevTools-hook transform lowers its free references.
|
|
19
20
|
*/
|
|
20
21
|
export declare function createWxReactRefreshTransforms(): Plugin[];
|
|
21
22
|
/** Makes renderer hook injection statically depend on the refresh runtime. */
|
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
export declare const packageRequire: NodeJS.Require;
|
|
2
2
|
/** Resolves a file shipped by this package as a portable Vite module ID. */
|
|
3
3
|
export declare function resolvePackageFile(...segments: string[]): string;
|
|
4
|
+
/** Resolves an unbundled browser runtime module from source in the workspace and from dist after publication. */
|
|
5
|
+
export declare function resolveRuntimeFile(modulePath: string): string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vite-plugin-taro",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.19",
|
|
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",
|
|
@@ -13,23 +13,25 @@
|
|
|
13
13
|
"url": "https://github.com/sep2/vite-plugin-taro/issues"
|
|
14
14
|
},
|
|
15
15
|
"homepage": "https://vpt.js.org",
|
|
16
|
-
"main": "./dist/
|
|
17
|
-
"module": "./dist/
|
|
18
|
-
"types": "./dist/
|
|
16
|
+
"main": "./dist/index.js",
|
|
17
|
+
"module": "./dist/index.js",
|
|
18
|
+
"types": "./dist/index.d.ts",
|
|
19
19
|
"exports": {
|
|
20
20
|
".": {
|
|
21
|
-
"types": "./dist/
|
|
22
|
-
"import": "./dist/
|
|
23
|
-
"default": "./dist/
|
|
21
|
+
"types": "./dist/index.d.ts",
|
|
22
|
+
"import": "./dist/index.js",
|
|
23
|
+
"default": "./dist/index.js"
|
|
24
24
|
},
|
|
25
25
|
"./client": {
|
|
26
26
|
"types": "./client.d.ts"
|
|
27
27
|
},
|
|
28
|
+
"./types/native": {
|
|
29
|
+
"types": "./dist/runtime/client/taro/native.d.ts"
|
|
30
|
+
},
|
|
28
31
|
"./package.json": "./package.json"
|
|
29
32
|
},
|
|
30
33
|
"files": [
|
|
31
34
|
"dist",
|
|
32
|
-
"src",
|
|
33
35
|
"client.d.ts",
|
|
34
36
|
"LICENSE",
|
|
35
37
|
"README.md",
|
|
@@ -51,32 +53,21 @@
|
|
|
51
53
|
"node": "^22.18.0 || >=24.11.0"
|
|
52
54
|
},
|
|
53
55
|
"dependencies": {
|
|
54
|
-
"@
|
|
55
|
-
"@babel/generator": "^8.0.0",
|
|
56
|
-
"@babel/types": "^8.0.4",
|
|
57
|
-
"@oxc-project/types": "0.147.0",
|
|
58
|
-
"@rolldown/plugin-babel": "^0.2.3",
|
|
59
|
-
"@tailwindcss-mangle/engine": "0.2.0",
|
|
56
|
+
"@tailwindcss/node": "4.3.3",
|
|
60
57
|
"@tailwindcss/oxide": "4.3.3",
|
|
61
58
|
"@tarojs/components": "4.2.1",
|
|
62
59
|
"@tarojs/helper": "4.2.1",
|
|
63
|
-
"@tarojs/plugin-framework-react": "npm:vite-plugin-taro-plugin-framework-react@0.6.
|
|
60
|
+
"@tarojs/plugin-framework-react": "npm:vite-plugin-taro-plugin-framework-react@0.6.19",
|
|
64
61
|
"@tarojs/plugin-platform-h5": "4.2.1",
|
|
65
62
|
"@tarojs/plugin-platform-weapp": "4.2.1",
|
|
66
|
-
"@tarojs/react": "npm:vite-plugin-taro-react@0.6.
|
|
63
|
+
"@tarojs/react": "npm:vite-plugin-taro-react@0.6.19",
|
|
67
64
|
"@tarojs/router": "4.2.1",
|
|
68
|
-
"@tarojs/runtime": "npm:vite-plugin-taro-runtime@0.6.
|
|
65
|
+
"@tarojs/runtime": "npm:vite-plugin-taro-runtime@0.6.19",
|
|
69
66
|
"@tarojs/taro": "4.2.1",
|
|
70
67
|
"@vitejs/plugin-react": "^6.1.0",
|
|
71
|
-
"@weapp-tailwindcss/postcss": "3.2.11",
|
|
72
|
-
"oxc-walker": "1.1.1",
|
|
73
|
-
"picocolors": "^1.1.1",
|
|
74
68
|
"react-reconciler": "0.33.0",
|
|
75
|
-
"react-refresh": "^0.18.0",
|
|
76
69
|
"rolldown": "1.2.5",
|
|
77
|
-
"
|
|
78
|
-
"tailwindcss": "^4.3.3",
|
|
79
|
-
"weapp-tailwindcss": "^5.3.5"
|
|
70
|
+
"tailwindcss": "^4.3.3"
|
|
80
71
|
},
|
|
81
72
|
"peerDependencies": {
|
|
82
73
|
"react": "^19.0.0",
|
|
@@ -84,19 +75,28 @@
|
|
|
84
75
|
"vite": "8.2.2"
|
|
85
76
|
},
|
|
86
77
|
"devDependencies": {
|
|
78
|
+
"@babel/core": "^8.0.1",
|
|
79
|
+
"@babel/generator": "^8.0.0",
|
|
87
80
|
"@babel/plugin-transform-dynamic-import": "^8.0.1",
|
|
88
81
|
"@babel/plugin-transform-modules-commonjs": "^8.0.1",
|
|
89
82
|
"@babel/plugin-transform-modules-systemjs": "^8.0.1",
|
|
83
|
+
"@babel/types": "^8.0.4",
|
|
84
|
+
"@oxc-project/types": "0.147.0",
|
|
85
|
+
"@rolldown/plugin-babel": "^0.2.3",
|
|
90
86
|
"@types/node": "^26.3.0",
|
|
91
87
|
"@types/react": "^19.2.18",
|
|
92
88
|
"@types/react-dom": "^19.2.5",
|
|
93
89
|
"@types/react-refresh": "^0.14.7",
|
|
94
90
|
"c8": "^12.0.0",
|
|
91
|
+
"oxc-walker": "1.1.1",
|
|
92
|
+
"picocolors": "^1.1.1",
|
|
93
|
+
"rxjs": "^7.8.2",
|
|
95
94
|
"typescript": "^7.0.2",
|
|
96
|
-
"vite": "8.2.2"
|
|
95
|
+
"vite": "8.2.2",
|
|
96
|
+
"weapp-tailwindcss": "5.3.5"
|
|
97
97
|
},
|
|
98
98
|
"scripts": {
|
|
99
|
-
"build": "node ../../scripts/sync-plugin-readme.ts && node
|
|
99
|
+
"build": "node ../../scripts/sync-plugin-readme.ts && node ./scripts/build.ts",
|
|
100
100
|
"test": "node --test --test-concurrency=2",
|
|
101
101
|
"test:coverage": "c8 node --test --test-concurrency=2",
|
|
102
102
|
"typecheck": "tsc --project tsconfig.json --noEmit"
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import { normalizePath } from 'vite';
|
|
2
|
-
import { normalizeModuleId } from '../../utils/modules.js';
|
|
3
|
-
import { resolvePackageFile } from '../../utils/packages.js';
|
|
4
|
-
import { clientTaroNativeId } from './constant.js';
|
|
5
|
-
import { injectTaroFrameworkApis } from './inject-taro-framework-apis.js';
|
|
6
|
-
/*
|
|
7
|
-
* Taro API resolution uses one public facade while avoiding a recursive `@tarojs/taro` import:
|
|
8
|
-
*
|
|
9
|
-
* 1. Application imports of `virtual:taro/api` or `@tarojs/taro` resolve to the physical `api.js` facade.
|
|
10
|
-
* 2. The facade itself imports `@tarojs/taro`; its importer identifies that request as the platform implementation.
|
|
11
|
-
* 3. H5 receives `@tarojs/plugin-platform-h5` APIs, while WX receives the generic `@tarojs/taro` implementation.
|
|
12
|
-
* 4. React's framework API loader transforms the facade, assigning lifecycle hooks such as `useLaunch` to the same
|
|
13
|
-
* platform object and exposing them as named exports.
|
|
14
|
-
*
|
|
15
|
-
* The importer-sensitive second step removes the need for another public-looking virtual module while retaining one
|
|
16
|
-
* facade object for platform APIs and framework lifecycles.
|
|
17
|
-
*/
|
|
18
|
-
/** Public facade used by transformed application API imports. */
|
|
19
|
-
export const clientTaroApiId = 'virtual:taro/api';
|
|
20
|
-
const clientTaroApiPath = resolvePackageFile('dist/runtime/client/taro/api.js');
|
|
21
|
-
const normalizedClientTaroApiPath = normalizePath(clientTaroApiPath);
|
|
22
|
-
const clientTaroComponentId = 'virtual:taro/components';
|
|
23
|
-
const clientTaroModules = new Map([
|
|
24
|
-
[clientTaroApiId, clientTaroApiPath],
|
|
25
|
-
[clientTaroComponentId, resolvePackageFile('dist/runtime/client/taro/component.js')],
|
|
26
|
-
[clientTaroNativeId, resolvePackageFile('dist/runtime/client/taro/define-native-component.js')]
|
|
27
|
-
]);
|
|
28
|
-
/** Creates the shared Taro facade backed by the selected target's API implementation. */
|
|
29
|
-
export function createClientTaroPlugin(target) {
|
|
30
|
-
const platformTaroId = resolvePlatformTaroId(target);
|
|
31
|
-
return {
|
|
32
|
-
name: 'vpt:client-taro',
|
|
33
|
-
enforce: 'pre',
|
|
34
|
-
async resolveId(id, importer) {
|
|
35
|
-
if (id === '@tarojs/taro') {
|
|
36
|
-
if (!isClientTaroFacade(importer)) {
|
|
37
|
-
return clientTaroApiPath;
|
|
38
|
-
}
|
|
39
|
-
// Delegate the platform backend to Vite instead of returning an absolute dependency path. H5 marks this
|
|
40
|
-
// backend as an optimization root, so delegation lets Vite substitute its prebundled facade. Removing it
|
|
41
|
-
// bypasses CommonJS interop and exposes backend details such as base64-js directly to the browser.
|
|
42
|
-
return this.resolve(platformTaroId, importer, { skipSelf: true });
|
|
43
|
-
}
|
|
44
|
-
return clientTaroModules.get(id);
|
|
45
|
-
},
|
|
46
|
-
// Taro's framework loader transforms source code, so apply it only to the shared physical facade.
|
|
47
|
-
transform(code, id) {
|
|
48
|
-
if (normalizeModuleId(id) === normalizedClientTaroApiPath) {
|
|
49
|
-
return injectTaroFrameworkApis(code);
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
function resolvePlatformTaroId(target) {
|
|
55
|
-
return target === 'h5' ? '@tarojs/plugin-platform-h5/dist/runtime/apis' : '@tarojs/taro';
|
|
56
|
-
}
|
|
57
|
-
function isClientTaroFacade(importer) {
|
|
58
|
-
return importer !== undefined && normalizeModuleId(importer) === normalizedClientTaroApiPath;
|
|
59
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { packageRequire } from '../../utils/packages.js';
|
|
2
|
-
const apiLoader = packageRequire('@tarojs/plugin-framework-react/dist/api-loader');
|
|
3
|
-
/**
|
|
4
|
-
* Applies Taro React's standard source-to-source API loader. It imports the framework lifecycle hooks, assigns them to
|
|
5
|
-
* the facade's `taro` object, and emits matching named exports; keeping the hook inventory owned by Taro avoids drift.
|
|
6
|
-
*/
|
|
7
|
-
export function injectTaroFrameworkApis(source) {
|
|
8
|
-
return apiLoader(source);
|
|
9
|
-
}
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
import { normalizeModuleId } from '../../utils/modules.js';
|
|
2
|
-
/** Creates source-level target conditional handling shared by H5 and WX. */
|
|
3
|
-
export function createConditionalDirectivePlugin(target) {
|
|
4
|
-
return {
|
|
5
|
-
name: 'vpt:conditional-directives',
|
|
6
|
-
enforce: 'pre',
|
|
7
|
-
transform(code, id) {
|
|
8
|
-
if (!isConditionalDirectiveSource(id) || !code.includes('#if')) {
|
|
9
|
-
return;
|
|
10
|
-
}
|
|
11
|
-
return {
|
|
12
|
-
code: transformConditionalDirectives(code, target),
|
|
13
|
-
map: null
|
|
14
|
-
};
|
|
15
|
-
}
|
|
16
|
-
};
|
|
17
|
-
}
|
|
18
|
-
/** Tests whether an application source can contain conditional directives. */
|
|
19
|
-
function isConditionalDirectiveSource(id) {
|
|
20
|
-
const normalizedId = normalizeModuleId(id);
|
|
21
|
-
return !normalizedId.includes('/node_modules/') && /\.(?:[cm]?[jt]sx?|css|s[ac]ss|less|styl)$/.test(normalizedId);
|
|
22
|
-
}
|
|
23
|
-
/** Keeps only the source branches active for one build target. */
|
|
24
|
-
function transformConditionalDirectives(code, target) {
|
|
25
|
-
const lines = Array.from(code.matchAll(/[^\n]*(?:\n|$)/g), (match) => match[0]);
|
|
26
|
-
const frames = [];
|
|
27
|
-
let transformed = '';
|
|
28
|
-
for (const line of lines) {
|
|
29
|
-
if (!line) {
|
|
30
|
-
continue;
|
|
31
|
-
}
|
|
32
|
-
const directive = parseDirective(line);
|
|
33
|
-
const lineEnding = line.match(/\r?\n$/)?.[0] ?? '';
|
|
34
|
-
if (!directive) {
|
|
35
|
-
transformed += frames.every((frame) => frame.active) ? line : lineEnding;
|
|
36
|
-
continue;
|
|
37
|
-
}
|
|
38
|
-
if (directive.name === 'ifdef' || directive.name === 'ifndef') {
|
|
39
|
-
const parentActive = frames.every((frame) => frame.active);
|
|
40
|
-
const targetMatched = directive.target.toLowerCase() === target;
|
|
41
|
-
const matched = directive.name === 'ifdef' ? targetMatched : !targetMatched;
|
|
42
|
-
frames.push({
|
|
43
|
-
parentActive,
|
|
44
|
-
matched,
|
|
45
|
-
active: parentActive && matched
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
else if (directive.name === 'else') {
|
|
49
|
-
const frame = frames.at(-1);
|
|
50
|
-
if (frame) {
|
|
51
|
-
frame.active = frame.parentActive && !frame.matched;
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
else {
|
|
55
|
-
frames.pop();
|
|
56
|
-
}
|
|
57
|
-
transformed += lineEnding;
|
|
58
|
-
}
|
|
59
|
-
return transformed;
|
|
60
|
-
}
|
|
61
|
-
/** Parses one supported Taro conditional directive. */
|
|
62
|
-
function parseDirective(line) {
|
|
63
|
-
const match = line.match(/^\s*(?:(?:\/\/)|(?:\/\*))\s*#(ifdef|ifndef|if|elif|else|endif)\b([^*\r\n]*)/);
|
|
64
|
-
if (!match) {
|
|
65
|
-
return;
|
|
66
|
-
}
|
|
67
|
-
// The regular expression constrains this capture to the complete directive union.
|
|
68
|
-
const name = match[1];
|
|
69
|
-
if (name === 'if' || name === 'elif') {
|
|
70
|
-
throw new Error(`vpt no longer supports #${name}; use #ifdef, #ifndef, or #else`);
|
|
71
|
-
}
|
|
72
|
-
return {
|
|
73
|
-
name,
|
|
74
|
-
target: match[2].replace(/\*\/$/, '').trim()
|
|
75
|
-
};
|
|
76
|
-
}
|
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
import { normalizePath } from 'vite';
|
|
2
|
-
import { normalizeModuleId } from '../../utils/modules.js';
|
|
3
|
-
import { transformWithOxcWalker } from '../../utils/oxc-transform.js';
|
|
4
|
-
import { packageRequire } from '../../utils/packages.js';
|
|
5
|
-
const stencilClientPath = packageRequire.resolve('@stencil/core/internal/client', {
|
|
6
|
-
paths: [packageRequire.resolve('@tarojs/components/package.json')]
|
|
7
|
-
});
|
|
8
|
-
const normalizedStencilClientPath = normalizePath(stencilClientPath);
|
|
9
|
-
/**
|
|
10
|
-
* Creates the compiler-owned adaptation of Stencil's client style insertion.
|
|
11
|
-
*
|
|
12
|
-
* Taro components inject their styles through this internal client. Its default insertion point places those styles
|
|
13
|
-
* after application CSS, allowing component defaults to override application rules. The adapter is registered in both
|
|
14
|
-
* Vite's application pipeline and the independent dependency-optimization build: removing either registration leaves
|
|
15
|
-
* production or development with an unadapted client. This explicit dual registration removes the former optimization
|
|
16
|
-
* exclusion while keeping one transformation implementation.
|
|
17
|
-
*/
|
|
18
|
-
export function createStencilClientAdapter() {
|
|
19
|
-
return {
|
|
20
|
-
name: 'vpt:h5-stencil-client',
|
|
21
|
-
transform: adaptStencilClient
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* Applies the shared Stencil adaptation with one Oxc parse and one range edit.
|
|
26
|
-
*
|
|
27
|
-
* The physical module check is essential because the optimizer and application pipelines can
|
|
28
|
-
* present query-suffixed or platform-normalized IDs. Transforming by source text alone could
|
|
29
|
-
* modify user code that happens to contain the same insertion expression. Source maps remain
|
|
30
|
-
* enabled because this adapter runs before Vite/Rolldown's later transforms in both pipelines;
|
|
31
|
-
* dropping the map would attribute downstream diagnostics to the edited generated positions.
|
|
32
|
-
*/
|
|
33
|
-
export function adaptStencilClient(code, id) {
|
|
34
|
-
if (normalizeModuleId(id) !== normalizedStencilClientPath) {
|
|
35
|
-
return;
|
|
36
|
-
}
|
|
37
|
-
return transformWithOxcWalker({
|
|
38
|
-
code,
|
|
39
|
-
filename: id,
|
|
40
|
-
sourcemap: true,
|
|
41
|
-
createVisitor: createStencilVisitor
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* Finds Stencil's exact default style insertion call and replaces only its insertion anchor.
|
|
46
|
-
*
|
|
47
|
-
* Stencil normally inserts `styleElm` before the first stylesheet link. During Vite development,
|
|
48
|
-
* application CSS is commonly represented by a `<style>` element instead, so that link-only
|
|
49
|
-
* lookup returns `null` and Taro component defaults are appended after application CSS. Those
|
|
50
|
-
* defaults then override the application's selectors despite having the same specificity.
|
|
51
|
-
*
|
|
52
|
-
* Taro Stencil components are identified by the `sc-taro-` scope prefix. For those components,
|
|
53
|
-
* the replacement anchors before the first `<style>` or stylesheet `<link>`, keeping component
|
|
54
|
-
* defaults before application rules. The original link-only lookup is preserved for every other
|
|
55
|
-
* Stencil component so VPT does not globally redefine upstream style-ordering behavior.
|
|
56
|
-
*/
|
|
57
|
-
function createStencilVisitor(editor) {
|
|
58
|
-
return function enter(node) {
|
|
59
|
-
if (node.type !== 'CallExpression' ||
|
|
60
|
-
node.callee.type !== 'MemberExpression' ||
|
|
61
|
-
node.callee.computed ||
|
|
62
|
-
node.callee.object.type !== 'Identifier' ||
|
|
63
|
-
node.callee.object.name !== 'styleContainerNode' ||
|
|
64
|
-
node.callee.property.type !== 'Identifier' ||
|
|
65
|
-
node.callee.property.name !== 'insertBefore') {
|
|
66
|
-
return;
|
|
67
|
-
}
|
|
68
|
-
// Match the complete upstream call, not merely `insertBefore`: range edits have no
|
|
69
|
-
// generated-AST type safety, so a broad match could silently alter unrelated runtime
|
|
70
|
-
// behavior when Stencil changes its implementation.
|
|
71
|
-
const [style, query] = node.arguments;
|
|
72
|
-
if (node.arguments.length !== 2 ||
|
|
73
|
-
style?.type !== 'Identifier' ||
|
|
74
|
-
style.name !== 'styleElm' ||
|
|
75
|
-
query?.type !== 'CallExpression' ||
|
|
76
|
-
query.callee.type !== 'MemberExpression' ||
|
|
77
|
-
query.callee.computed ||
|
|
78
|
-
query.callee.object.type !== 'Identifier' ||
|
|
79
|
-
query.callee.object.name !== 'styleContainerNode' ||
|
|
80
|
-
query.callee.property.type !== 'Identifier' ||
|
|
81
|
-
query.callee.property.name !== 'querySelector') {
|
|
82
|
-
return;
|
|
83
|
-
}
|
|
84
|
-
const [selector] = query.arguments;
|
|
85
|
-
if (selector?.type !== 'Literal' || selector.value !== 'link') {
|
|
86
|
-
return;
|
|
87
|
-
}
|
|
88
|
-
// Replace only the second argument expression. Preserving the surrounding Stencil
|
|
89
|
-
// source avoids Babel-style whole-file regeneration and keeps its formatting, comments,
|
|
90
|
-
// and source positions stable. Removing this edit restores the H5 cascade bug described
|
|
91
|
-
// above; applying it unconditionally would change non-Taro Stencil components.
|
|
92
|
-
editor.overwrite(query.start, query.end, 'scopeId.startsWith("sc-taro-") ? styleContainerNode.querySelector("style,link[rel=\\"stylesheet\\"]") : styleContainerNode.querySelector("link")');
|
|
93
|
-
};
|
|
94
|
-
}
|
|
@@ -1,179 +0,0 @@
|
|
|
1
|
-
import { createRequire } from 'node:module';
|
|
2
|
-
import babel, { defineRolldownBabelPreset } from '@rolldown/plugin-babel';
|
|
3
|
-
import { WeappTailwindcss } from 'weapp-tailwindcss/vite';
|
|
4
|
-
import { esTarget } from '../../utils/constant.js';
|
|
5
|
-
import { toViteFileImportPath } from '../../utils/modules.js';
|
|
6
|
-
import { packageRequire } from '../../utils/packages.js';
|
|
7
|
-
import { clientTaroApiId } from '../client/client-taro.js';
|
|
8
|
-
import { tailwindcssBasedir } from '../tailwind/tailwind-css.js';
|
|
9
|
-
import { h5AppPath } from './constant.js';
|
|
10
|
-
import { createStencilClientAdapter } from './create-stencil-client-adapter.js';
|
|
11
|
-
import { createModuleResolver } from './resolver/module-resolver.js';
|
|
12
|
-
/** Creates the plugins that own the H5 target. */
|
|
13
|
-
export function createH5TargetPlugins(options) {
|
|
14
|
-
return [
|
|
15
|
-
WeappTailwindcss({
|
|
16
|
-
appType: 'weapp-vite',
|
|
17
|
-
rewriteCssImports: false,
|
|
18
|
-
platform: 'web',
|
|
19
|
-
tailwindcssBasedir,
|
|
20
|
-
generator: {
|
|
21
|
-
target: 'web'
|
|
22
|
-
},
|
|
23
|
-
cssOptions: {
|
|
24
|
-
cssCalc: false,
|
|
25
|
-
autoprefixer: true,
|
|
26
|
-
rem2rpx: true,
|
|
27
|
-
px2rpx: true
|
|
28
|
-
},
|
|
29
|
-
logLevel: 'warn'
|
|
30
|
-
}),
|
|
31
|
-
...createH5SupportPlugins(),
|
|
32
|
-
createH5Plugin(options)
|
|
33
|
-
];
|
|
34
|
-
}
|
|
35
|
-
/** Configures H5 resolution and supplies the specialized physical application entry. */
|
|
36
|
-
function createH5Plugin(options) {
|
|
37
|
-
const moduleResolver = createModuleResolver(options);
|
|
38
|
-
return {
|
|
39
|
-
name: 'vpt:h5',
|
|
40
|
-
config() {
|
|
41
|
-
return {
|
|
42
|
-
define: createH5Defines(),
|
|
43
|
-
resolve: {
|
|
44
|
-
mainFields: ['main:h5', 'browser', 'module', 'jsnext:main', 'jsnext'],
|
|
45
|
-
alias: [
|
|
46
|
-
{
|
|
47
|
-
find: /^@tarojs\/runtime$/,
|
|
48
|
-
replacement: packageRequire.resolve('@tarojs/runtime/dist/runtime.esm.js')
|
|
49
|
-
},
|
|
50
|
-
{
|
|
51
|
-
find: /^@tarojs\/components$/,
|
|
52
|
-
replacement: packageRequire.resolve('@tarojs/components/lib/react')
|
|
53
|
-
},
|
|
54
|
-
{
|
|
55
|
-
find: /^@tarojs\/components\/dist\/components$/,
|
|
56
|
-
replacement: packageRequire.resolve('@tarojs/components/dist/components')
|
|
57
|
-
}
|
|
58
|
-
]
|
|
59
|
-
},
|
|
60
|
-
optimizeDeps: {
|
|
61
|
-
/*
|
|
62
|
-
* The compiler-owned H5 app and Taro facade are injected after Vite's initial HTML scan, so declare their
|
|
63
|
-
* optimization entries explicitly. The platform backend needs CommonJS interop, ReactDOM is imported by
|
|
64
|
-
* the hidden app, and @tarojs/runtime must be a first-class entry so subsequently discovered Taro packages
|
|
65
|
-
* share its Current singleton instead of embedding private copies in their optimized chunks.
|
|
66
|
-
*/
|
|
67
|
-
include: ['@tarojs/plugin-platform-h5/dist/runtime/apis', '@tarojs/runtime', 'react-dom/client'],
|
|
68
|
-
// Dependency optimization is its own Rolldown build and does not run application transform plugins.
|
|
69
|
-
// Register the same adapter there so optimized Taro components cannot embed Stencil's original client.
|
|
70
|
-
rolldownOptions: {
|
|
71
|
-
plugins: [createStencilClientAdapter()]
|
|
72
|
-
}
|
|
73
|
-
},
|
|
74
|
-
build: {
|
|
75
|
-
target: esTarget
|
|
76
|
-
}
|
|
77
|
-
};
|
|
78
|
-
},
|
|
79
|
-
resolveId: {
|
|
80
|
-
order: 'pre',
|
|
81
|
-
handler(id) {
|
|
82
|
-
return moduleResolver.resolveId({
|
|
83
|
-
id,
|
|
84
|
-
projectRoot: this.environment.config.root
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
|
-
},
|
|
88
|
-
transform: {
|
|
89
|
-
order: 'pre',
|
|
90
|
-
handler(code, id) {
|
|
91
|
-
return moduleResolver.transform({
|
|
92
|
-
code,
|
|
93
|
-
id,
|
|
94
|
-
projectRoot: this.environment.config.root,
|
|
95
|
-
sourcemap: Boolean(this.environment.config.build.sourcemap)
|
|
96
|
-
});
|
|
97
|
-
}
|
|
98
|
-
},
|
|
99
|
-
transformIndexHtml: {
|
|
100
|
-
order: 'pre',
|
|
101
|
-
handler() {
|
|
102
|
-
return createH5IndexHtmlTags();
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
};
|
|
106
|
-
}
|
|
107
|
-
/** Injects the physical H5 App into the application document. */
|
|
108
|
-
function createH5IndexHtmlTags() {
|
|
109
|
-
return [
|
|
110
|
-
{
|
|
111
|
-
tag: 'script',
|
|
112
|
-
attrs: {
|
|
113
|
-
type: 'module'
|
|
114
|
-
},
|
|
115
|
-
children: `import '${toViteFileImportPath(h5AppPath)}'`,
|
|
116
|
-
injectTo: 'body'
|
|
117
|
-
}
|
|
118
|
-
];
|
|
119
|
-
}
|
|
120
|
-
/**
|
|
121
|
-
* Coarse source prefilter for the upstream Taro API transform.
|
|
122
|
-
*
|
|
123
|
-
* The plugin has two independent responsibilities: adapting imports from the compiler facade and normalizing camel-case
|
|
124
|
-
* H5 ARIA attributes. Matching `aria` followed by any uppercase letter is intentionally broader than Taro's current
|
|
125
|
-
* attribute table. A duplicated exact list would silently stop routing files through Babel when upstream adds another
|
|
126
|
-
* attribute, while a broad false positive costs only one unnecessary transform. Ordinary application modules match
|
|
127
|
-
* neither branch and remain entirely outside Babel's parser and generator.
|
|
128
|
-
*/
|
|
129
|
-
export const h5TaroApiTransformCodeFilter = /virtual:taro\/api|\baria[A-Z]/;
|
|
130
|
-
/** Babel preset body shared by Rolldown's filtered adapter and direct semantic tests. */
|
|
131
|
-
export function h5TaroApiPreset() {
|
|
132
|
-
// Resolve Taro's private transform from the H5 package that owns it instead of promoting it into VPT's Babel graph.
|
|
133
|
-
const h5PlatformRequire = createRequire(packageRequire.resolve('@tarojs/plugin-platform-h5/package.json'));
|
|
134
|
-
const transformTaroApiPath = h5PlatformRequire.resolve('babel-plugin-transform-taroapi');
|
|
135
|
-
const definition = packageRequire(packageRequire.resolve('@tarojs/plugin-platform-h5/dist/definition.json'));
|
|
136
|
-
return {
|
|
137
|
-
plugins: [
|
|
138
|
-
[
|
|
139
|
-
transformTaroApiPath,
|
|
140
|
-
{
|
|
141
|
-
packageName: clientTaroApiId,
|
|
142
|
-
definition
|
|
143
|
-
}
|
|
144
|
-
]
|
|
145
|
-
]
|
|
146
|
-
};
|
|
147
|
-
}
|
|
148
|
-
/** Creates a filterable Babel preset containing Taro's upstream, scope-aware API transform. */
|
|
149
|
-
function createH5TaroApiPreset() {
|
|
150
|
-
return defineRolldownBabelPreset({
|
|
151
|
-
preset: h5TaroApiPreset,
|
|
152
|
-
rolldown: {
|
|
153
|
-
// @rolldown/plugin-babel can lift a preset filter into its native transform hook. The Taro plugin must be
|
|
154
|
-
// nested in this preset rather than passed through Babel's top-level `plugins`: explicit plugins may apply
|
|
155
|
-
// to every module, so their presence deliberately disables Rolldown's preset-level code filtering.
|
|
156
|
-
filter: { code: h5TaroApiTransformCodeFilter }
|
|
157
|
-
}
|
|
158
|
-
});
|
|
159
|
-
}
|
|
160
|
-
/** Creates H5-only transforms for Stencil CSS ordering and Taro API imports. */
|
|
161
|
-
function createH5SupportPlugins() {
|
|
162
|
-
return [
|
|
163
|
-
createStencilClientAdapter(),
|
|
164
|
-
babel({
|
|
165
|
-
presets: [createH5TaroApiPreset()]
|
|
166
|
-
})
|
|
167
|
-
];
|
|
168
|
-
}
|
|
169
|
-
/** Creates H5 Taro compile-time constants. */
|
|
170
|
-
function createH5Defines() {
|
|
171
|
-
return {
|
|
172
|
-
'process.env.FRAMEWORK': JSON.stringify('react'),
|
|
173
|
-
'process.env.SUPPORT_TARO_POLYFILL': JSON.stringify('disabled'),
|
|
174
|
-
'process.env.TARO_ENV': JSON.stringify('h5'),
|
|
175
|
-
'process.env.TARO_PLATFORM': JSON.stringify('web'),
|
|
176
|
-
'process.env.SUPPORT_DINGTALK_NAVIGATE': JSON.stringify('disabled'),
|
|
177
|
-
DEPRECATED_ADAPTER_COMPONENT: 'false'
|
|
178
|
-
};
|
|
179
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { normalizePath } from 'vite';
|
|
2
|
-
import { normalizeModuleId, resolveAppComponentPath } from '../../../utils/modules.js';
|
|
3
|
-
import { appComponentId } from '../../client/constant.js';
|
|
4
|
-
import { h5AppPath } from '../constant.js';
|
|
5
|
-
import { transformH5App } from '../transform-app.js';
|
|
6
|
-
/** Creates H5 application module resolution and specialization. */
|
|
7
|
-
export function createModuleResolver(options) {
|
|
8
|
-
return {
|
|
9
|
-
resolveId({ id, projectRoot }) {
|
|
10
|
-
if (id === appComponentId) {
|
|
11
|
-
return resolveAppComponentPath({ appPath: options.app, projectRoot });
|
|
12
|
-
}
|
|
13
|
-
},
|
|
14
|
-
transform({ code, id, projectRoot, sourcemap = true }) {
|
|
15
|
-
if (normalizeModuleId(id) === normalizePath(h5AppPath)) {
|
|
16
|
-
return transformH5App({ code, id, options, projectRoot, sourcemap });
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
};
|
|
20
|
-
}
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import * as types from '@babel/types';
|
|
2
|
-
import { createPageComponentImportPath } from '../../utils/modules.js';
|
|
3
|
-
import { createAppConfig } from '../../utils/project-config.js';
|
|
4
|
-
import { replaceWithAst } from '../../utils/transform.js';
|
|
5
|
-
const appConfigPlaceholder = '__VPT_H5_APP_CONFIG__';
|
|
6
|
-
const routesPlaceholder = '__VPT_H5_ROUTES__';
|
|
7
|
-
/** Specializes the physical H5 App for one configured project. */
|
|
8
|
-
export async function transformH5App({ code, id, options, projectRoot, sourcemap = true }) {
|
|
9
|
-
const transformed = await replaceWithAst(code, id, {
|
|
10
|
-
[appConfigPlaceholder]: types.valueToNode({
|
|
11
|
-
router: {},
|
|
12
|
-
...createAppConfig(options)
|
|
13
|
-
}),
|
|
14
|
-
[routesPlaceholder]: types.arrayExpression(options.pages.map((page) => {
|
|
15
|
-
return createRoute({ page, projectRoot });
|
|
16
|
-
}))
|
|
17
|
-
}, sourcemap);
|
|
18
|
-
return { code: transformed.code, map: transformed.map };
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* Creates one lazy H5 route shaped like:
|
|
22
|
-
* {
|
|
23
|
-
* path: 'pages/home/index',
|
|
24
|
-
* load: async function (context, params) {
|
|
25
|
-
* const page = await import('/@fs/project/src/pages/home/index.tsx')
|
|
26
|
-
* return [page, context, params]
|
|
27
|
-
* },
|
|
28
|
-
* ...pageConfig
|
|
29
|
-
* }
|
|
30
|
-
*/
|
|
31
|
-
function createRoute({ page, projectRoot }) {
|
|
32
|
-
const pageComponentPath = createPageComponentImportPath({ pagePath: page.path, projectRoot });
|
|
33
|
-
const load = types.functionExpression(null, [types.identifier('context'), types.identifier('params')], types.blockStatement([
|
|
34
|
-
types.variableDeclaration('const', [
|
|
35
|
-
types.variableDeclarator(types.identifier('page'), types.awaitExpression(types.importExpression(types.stringLiteral(pageComponentPath))))
|
|
36
|
-
]),
|
|
37
|
-
types.returnStatement(types.arrayExpression([
|
|
38
|
-
types.identifier('page'),
|
|
39
|
-
types.identifier('context'),
|
|
40
|
-
types.identifier('params')
|
|
41
|
-
]))
|
|
42
|
-
]), false, true);
|
|
43
|
-
return types.objectExpression([
|
|
44
|
-
types.objectProperty(types.identifier('path'), types.stringLiteral(page.path)),
|
|
45
|
-
types.objectProperty(types.identifier('load'), load),
|
|
46
|
-
types.spreadElement(types.valueToNode(page.config))
|
|
47
|
-
]);
|
|
48
|
-
}
|