vite-plugin-taro 0.3.1 → 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 -13
- 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 -33
- 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 -48
- package/dist/node/css/css-pipeline.d.ts +0 -21
- package/dist/node/css/css-pipeline.js +0 -129
- 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 -31
- package/dist/node/targets/wx/dev-server/development-session.js +0 -202
- 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 -143
- 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 -170
- package/src/node/build-context.ts +0 -63
- package/src/node/css/css-pipeline.ts +0 -147
- 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 -170
- package/src/node/targets/wx/dev-server/development-session.ts +0 -253
- 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 -163
- 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 -222
|
@@ -1,129 +0,0 @@
|
|
|
1
|
-
import path from 'node:path';
|
|
2
|
-
import { createContext } from 'weapp-tailwindcss/core';
|
|
3
|
-
import { createWeappTailwindcssGenerator, resolveTailwindV4Source } from 'weapp-tailwindcss/generator';
|
|
4
|
-
import { normalizeModuleId } from '../utils/modules.js';
|
|
5
|
-
const wxStyleOptions = {
|
|
6
|
-
cssCalc: false,
|
|
7
|
-
autoprefixer: false,
|
|
8
|
-
rem2rpx: true,
|
|
9
|
-
px2rpx: true
|
|
10
|
-
};
|
|
11
|
-
/** Owns CSS generation and the class-name state shared by normal chunks and literal WX patches. */
|
|
12
|
-
export class CssPipeline {
|
|
13
|
-
plugin;
|
|
14
|
-
target;
|
|
15
|
-
runtimeClassSet = new Set();
|
|
16
|
-
projectRoot;
|
|
17
|
-
wxContext;
|
|
18
|
-
constructor(target) {
|
|
19
|
-
this.target = target;
|
|
20
|
-
this.plugin = this.createPlugin();
|
|
21
|
-
}
|
|
22
|
-
resolve(projectRoot) {
|
|
23
|
-
if (this.projectRoot)
|
|
24
|
-
throw new Error('vite-plugin-taro CSS pipeline was already resolved.');
|
|
25
|
-
this.projectRoot = projectRoot;
|
|
26
|
-
this.wxContext = this.target === 'wx' ? createWxCssContext(projectRoot) : undefined;
|
|
27
|
-
}
|
|
28
|
-
async transformWxClassNames(code, filename) {
|
|
29
|
-
if (!this.wxContext || this.runtimeClassSet.size === 0)
|
|
30
|
-
return { code, map: null };
|
|
31
|
-
const result = await this.wxContext.transformJs(code, {
|
|
32
|
-
runtimeSet: this.runtimeClassSet,
|
|
33
|
-
filename,
|
|
34
|
-
generateMap: false
|
|
35
|
-
});
|
|
36
|
-
return { code: result.code, map: null };
|
|
37
|
-
}
|
|
38
|
-
createPlugin() {
|
|
39
|
-
const pipeline = this;
|
|
40
|
-
return {
|
|
41
|
-
name: 'vite-plugin-taro:css',
|
|
42
|
-
enforce: 'pre',
|
|
43
|
-
buildStart() {
|
|
44
|
-
pipeline.runtimeClassSet.clear();
|
|
45
|
-
},
|
|
46
|
-
async transform(code, id) {
|
|
47
|
-
if (!isCssModuleId(id) || !shouldGenerateTailwindCss(code))
|
|
48
|
-
return;
|
|
49
|
-
const projectRoot = pipeline.getProjectRoot();
|
|
50
|
-
const cssFile = resolveCssFile(id, projectRoot);
|
|
51
|
-
const cssBase = path.dirname(cssFile);
|
|
52
|
-
const source = await resolveTailwindV4Source({
|
|
53
|
-
projectRoot,
|
|
54
|
-
cwd: projectRoot,
|
|
55
|
-
base: cssBase,
|
|
56
|
-
css: code,
|
|
57
|
-
cssSources: [{ file: cssFile, base: cssBase, css: code, dependencies: [cssFile] }]
|
|
58
|
-
});
|
|
59
|
-
const generator = createWeappTailwindcssGenerator(source);
|
|
60
|
-
const generated = await generator.generate({
|
|
61
|
-
target: pipeline.target === 'wx' ? 'weapp' : 'web',
|
|
62
|
-
scanSources: true,
|
|
63
|
-
candidates: [],
|
|
64
|
-
styleOptions: pipeline.target === 'wx' ? wxStyleOptions : undefined
|
|
65
|
-
});
|
|
66
|
-
for (const className of generated.classSet)
|
|
67
|
-
pipeline.runtimeClassSet.add(className);
|
|
68
|
-
for (const dependency of generated.dependencies)
|
|
69
|
-
this.addWatchFile(dependency);
|
|
70
|
-
return generated.css;
|
|
71
|
-
},
|
|
72
|
-
async renderChunk(code, chunk) {
|
|
73
|
-
if (pipeline.target !== 'wx')
|
|
74
|
-
return;
|
|
75
|
-
return await pipeline.transformWxClassNames(code, chunk.fileName);
|
|
76
|
-
},
|
|
77
|
-
async generateBundle(_, bundle) {
|
|
78
|
-
if (pipeline.target !== 'wx')
|
|
79
|
-
return;
|
|
80
|
-
const core = pipeline.getWxContext();
|
|
81
|
-
await Promise.all(Object.entries(bundle).map(async ([fileName, item]) => {
|
|
82
|
-
if (item.type === 'asset' && fileName.endsWith('.css')) {
|
|
83
|
-
await transformWxssAsset(core, item);
|
|
84
|
-
}
|
|
85
|
-
}));
|
|
86
|
-
}
|
|
87
|
-
};
|
|
88
|
-
}
|
|
89
|
-
getProjectRoot() {
|
|
90
|
-
if (!this.projectRoot)
|
|
91
|
-
throw new Error('vite-plugin-taro CSS pipeline was used before configuration resolved.');
|
|
92
|
-
return this.projectRoot;
|
|
93
|
-
}
|
|
94
|
-
getWxContext() {
|
|
95
|
-
if (!this.wxContext)
|
|
96
|
-
throw new Error('vite-plugin-taro expected a resolved WeChat CSS pipeline.');
|
|
97
|
-
return this.wxContext;
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
function createWxCssContext(projectRoot) {
|
|
101
|
-
return createContext({
|
|
102
|
-
appType: 'taro',
|
|
103
|
-
tailwindcssBasedir: projectRoot,
|
|
104
|
-
generator: { target: 'weapp' },
|
|
105
|
-
...wxStyleOptions,
|
|
106
|
-
logLevel: 'silent'
|
|
107
|
-
});
|
|
108
|
-
}
|
|
109
|
-
async function transformWxssAsset(core, item) {
|
|
110
|
-
const result = await core.transformWxss(getAssetSource(item), { isMainChunk: true });
|
|
111
|
-
item.source = result.css;
|
|
112
|
-
}
|
|
113
|
-
function shouldGenerateTailwindCss(code) {
|
|
114
|
-
const tailwindEntryImportPattern = /@(import|reference)\s+(?:url\(\s*)?(?:["'])tailwindcss(?:\/(?:theme|preflight|utilities)(?:\.css)?)?(?:["'])/;
|
|
115
|
-
return code.includes('tailwindcss') && tailwindEntryImportPattern.test(code);
|
|
116
|
-
}
|
|
117
|
-
function isCssModuleId(id) {
|
|
118
|
-
return /\.(?:css|scss|sass|less|styl|stylus)(?:$|[?#])/.test(id);
|
|
119
|
-
}
|
|
120
|
-
function getAssetSource(item) {
|
|
121
|
-
if (typeof item.source === 'string')
|
|
122
|
-
return item.source;
|
|
123
|
-
return item.source ? new TextDecoder().decode(item.source) : '';
|
|
124
|
-
}
|
|
125
|
-
function resolveCssFile(id, root) {
|
|
126
|
-
const normalizedId = normalizeModuleId(id);
|
|
127
|
-
const cleanId = normalizedId.startsWith('/@fs/') ? normalizedId.slice('/@fs'.length) : normalizedId;
|
|
128
|
-
return path.isAbsolute(cleanId) ? cleanId : path.resolve(root, cleanId);
|
|
129
|
-
}
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import type { Plugin } from 'vite';
|
|
2
|
-
/** Public IDs used by Taro's API transform and generated target modules. */
|
|
3
|
-
export declare const virtualTaroApiId = "virtual:taro/api";
|
|
4
|
-
/** Resolves target-neutral Taro shims once instead of duplicating this concern in every target plugin. */
|
|
5
|
-
export declare function createTaroRuntimePlugin(): Plugin;
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { resolvePackageFile } from '../utils/packages.js';
|
|
2
|
-
/** Public IDs used by Taro's API transform and generated target modules. */
|
|
3
|
-
export const virtualTaroApiId = 'virtual:taro/api';
|
|
4
|
-
const virtualTaroComponentsId = 'virtual:taro/components';
|
|
5
|
-
const runtimeModules = new Map([
|
|
6
|
-
[virtualTaroApiId, resolvePackageFile('dist/runtime/taro/api.js')],
|
|
7
|
-
[virtualTaroComponentsId, resolvePackageFile('dist/runtime/taro/components.js')]
|
|
8
|
-
]);
|
|
9
|
-
/** Resolves target-neutral Taro shims once instead of duplicating this concern in every target plugin. */
|
|
10
|
-
export function createTaroRuntimePlugin() {
|
|
11
|
-
return {
|
|
12
|
-
name: 'vite-plugin-taro:runtime',
|
|
13
|
-
enforce: 'pre',
|
|
14
|
-
resolveId(id) {
|
|
15
|
-
return runtimeModules.get(id);
|
|
16
|
-
}
|
|
17
|
-
};
|
|
18
|
-
}
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import type { PluginOption, UserConfig } from 'vite';
|
|
2
|
-
import type { BuildContext } from '../../build-context.ts';
|
|
3
|
-
/** Creates the plugins that own the complete H5 target lifecycle. */
|
|
4
|
-
export declare function createH5TargetPlugins(context: BuildContext): PluginOption[];
|
|
5
|
-
/** Supplies the complete H5 target configuration from the same target owner as its plugins. */
|
|
6
|
-
export declare function createH5ViteConfig(context: BuildContext): UserConfig;
|
|
@@ -1,117 +0,0 @@
|
|
|
1
|
-
import babel from '@rolldown/plugin-babel';
|
|
2
|
-
import { virtualTaroApiId } from '../../plugins/taro-runtime.js';
|
|
3
|
-
import { stripVirtualPrefix } from '../../utils/modules.js';
|
|
4
|
-
import { packageRequire } from '../../utils/packages.js';
|
|
5
|
-
import { createH5IndexHtmlTags, isH5VirtualModuleId, loadH5VirtualModule } from './virtual-modules.js';
|
|
6
|
-
/** Creates the plugins that own the complete H5 target lifecycle. */
|
|
7
|
-
export function createH5TargetPlugins(context) {
|
|
8
|
-
return [...createH5SupportPlugins(), createH5TargetPlugin(context)];
|
|
9
|
-
}
|
|
10
|
-
function createH5TargetPlugin(context) {
|
|
11
|
-
return {
|
|
12
|
-
name: 'vite-plugin-taro:h5',
|
|
13
|
-
resolveId: {
|
|
14
|
-
order: 'pre',
|
|
15
|
-
handler(id) {
|
|
16
|
-
return isH5VirtualModuleId(id) ? `\0${id}` : undefined;
|
|
17
|
-
}
|
|
18
|
-
},
|
|
19
|
-
load: {
|
|
20
|
-
order: 'post',
|
|
21
|
-
handler(id) {
|
|
22
|
-
return loadH5VirtualModule(stripVirtualPrefix(id), context);
|
|
23
|
-
}
|
|
24
|
-
},
|
|
25
|
-
transformIndexHtml: {
|
|
26
|
-
order: 'pre',
|
|
27
|
-
handler() {
|
|
28
|
-
return createH5IndexHtmlTags(context);
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
};
|
|
32
|
-
}
|
|
33
|
-
/** Creates H5-only Babel transforms for Stencil CSS ordering and Taro API imports. */
|
|
34
|
-
function createH5SupportPlugins() {
|
|
35
|
-
return [
|
|
36
|
-
babel({
|
|
37
|
-
include: /[\\/]@stencil[\\/]core[\\/]internal[\\/]client[\\/]index\.js(?:\?.*)?$/,
|
|
38
|
-
exclude: [],
|
|
39
|
-
plugins: [rewriteStencilStyleInsertion]
|
|
40
|
-
}),
|
|
41
|
-
babel({
|
|
42
|
-
plugins: [
|
|
43
|
-
[
|
|
44
|
-
packageRequire.resolve('babel-plugin-transform-taroapi'),
|
|
45
|
-
{
|
|
46
|
-
packageName: virtualTaroApiId,
|
|
47
|
-
definition: packageRequire(packageRequire.resolve('@tarojs/plugin-platform-h5/dist/definition.json'))
|
|
48
|
-
}
|
|
49
|
-
]
|
|
50
|
-
]
|
|
51
|
-
})
|
|
52
|
-
];
|
|
53
|
-
}
|
|
54
|
-
/** Keeps Stencil-injected Taro component styles before application stylesheets. */
|
|
55
|
-
function rewriteStencilStyleInsertion() {
|
|
56
|
-
return {
|
|
57
|
-
name: 'rewrite-stencil-style-insertion',
|
|
58
|
-
visitor: {
|
|
59
|
-
CallExpression(path) {
|
|
60
|
-
if (!isStencilStyleInsertBeforeCall(path))
|
|
61
|
-
return;
|
|
62
|
-
path.get('arguments.1').replaceWithSourceString(`scopeId.startsWith('sc-taro-') ? styleContainerNode.querySelector('style,link[rel="stylesheet"]') : styleContainerNode.querySelector('link')`);
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
};
|
|
66
|
-
}
|
|
67
|
-
function isStencilStyleInsertBeforeCall(path) {
|
|
68
|
-
return (path.get('callee').matchesPattern('styleContainerNode.insertBefore') &&
|
|
69
|
-
path.get('arguments.0').toString() === 'styleElm' &&
|
|
70
|
-
path.get('arguments.1').toString() === "styleContainerNode.querySelector('link')");
|
|
71
|
-
}
|
|
72
|
-
/** Supplies the complete H5 target configuration from the same target owner as its plugins. */
|
|
73
|
-
export function createH5ViteConfig(context) {
|
|
74
|
-
return {
|
|
75
|
-
define: createH5TaroDefines(),
|
|
76
|
-
resolve: {
|
|
77
|
-
mainFields: ['main:h5', 'browser', 'module', 'jsnext:main', 'jsnext'],
|
|
78
|
-
alias: [
|
|
79
|
-
{
|
|
80
|
-
find: /^@stencil\/core\/internal\/client$/,
|
|
81
|
-
replacement: packageRequire.resolve('@stencil/core/internal/client', {
|
|
82
|
-
paths: [packageRequire.resolve('@tarojs/components/package.json')]
|
|
83
|
-
})
|
|
84
|
-
},
|
|
85
|
-
{
|
|
86
|
-
find: /^@tarojs\/components$/,
|
|
87
|
-
replacement: packageRequire.resolve('@tarojs/components/lib/react')
|
|
88
|
-
},
|
|
89
|
-
{
|
|
90
|
-
find: /^@tarojs\/components\/dist\/components$/,
|
|
91
|
-
replacement: packageRequire.resolve('@tarojs/components/dist/components')
|
|
92
|
-
},
|
|
93
|
-
{
|
|
94
|
-
find: /^@tarojs\/taro$/,
|
|
95
|
-
replacement: packageRequire.resolve('@tarojs/plugin-platform-h5/dist/runtime/apis')
|
|
96
|
-
}
|
|
97
|
-
]
|
|
98
|
-
},
|
|
99
|
-
optimizeDeps: {
|
|
100
|
-
exclude: ['@stencil/core/internal/client']
|
|
101
|
-
},
|
|
102
|
-
build: {
|
|
103
|
-
target: 'es2018',
|
|
104
|
-
minify: !context.development
|
|
105
|
-
}
|
|
106
|
-
};
|
|
107
|
-
}
|
|
108
|
-
function createH5TaroDefines() {
|
|
109
|
-
return {
|
|
110
|
-
'process.env.FRAMEWORK': JSON.stringify('react'),
|
|
111
|
-
'process.env.SUPPORT_TARO_POLYFILL': JSON.stringify('disabled'),
|
|
112
|
-
'process.env.TARO_ENV': JSON.stringify('h5'),
|
|
113
|
-
'process.env.TARO_PLATFORM': JSON.stringify('web'),
|
|
114
|
-
'process.env.SUPPORT_DINGTALK_NAVIGATE': JSON.stringify('disabled'),
|
|
115
|
-
DEPRECATED_ADAPTER_COMPONENT: 'false'
|
|
116
|
-
};
|
|
117
|
-
}
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import type { HtmlTagDescriptor } from 'vite';
|
|
2
|
-
import type { BuildContext } from '../../build-context.ts';
|
|
3
|
-
export declare function isH5VirtualModuleId(id: string): boolean;
|
|
4
|
-
export declare function loadH5VirtualModule(id: string, context: BuildContext): string | undefined;
|
|
5
|
-
export declare function createH5IndexHtmlTags(context: BuildContext): HtmlTagDescriptor[] | undefined;
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import { createPageComponentImportPath, toViteFileImportPath } from '../../utils/modules.js';
|
|
2
|
-
import { resolvePackageFile } from '../../utils/packages.js';
|
|
3
|
-
const h5TaroRuntimeImportPath = toViteFileImportPath(resolvePackageFile('dist/runtime/h5/taro-runtime.js'));
|
|
4
|
-
const virtualH5EntryId = 'virtual:vite-plugin-taro/h5';
|
|
5
|
-
export function isH5VirtualModuleId(id) {
|
|
6
|
-
return id === virtualH5EntryId;
|
|
7
|
-
}
|
|
8
|
-
export function loadH5VirtualModule(id, context) {
|
|
9
|
-
if (id === virtualH5EntryId)
|
|
10
|
-
return createH5EntrySource(context);
|
|
11
|
-
}
|
|
12
|
-
export function createH5IndexHtmlTags(context) {
|
|
13
|
-
if (context.project.target !== 'h5')
|
|
14
|
-
return;
|
|
15
|
-
return [
|
|
16
|
-
{
|
|
17
|
-
tag: 'script',
|
|
18
|
-
attrs: { type: 'module' },
|
|
19
|
-
children: `import '${virtualH5EntryId}'`,
|
|
20
|
-
injectTo: 'body'
|
|
21
|
-
}
|
|
22
|
-
];
|
|
23
|
-
}
|
|
24
|
-
function createH5EntrySource(context) {
|
|
25
|
-
const appConfig = JSON.stringify(createH5AppConfig(context.project.appConfig));
|
|
26
|
-
const routes = createH5RoutesSource(context.project.pages);
|
|
27
|
-
return `import {
|
|
28
|
-
createHashHistory,
|
|
29
|
-
createReactApp,
|
|
30
|
-
createRouter,
|
|
31
|
-
handleAppMount,
|
|
32
|
-
window
|
|
33
|
-
} from ${JSON.stringify(h5TaroRuntimeImportPath)}
|
|
34
|
-
import React from 'react'
|
|
35
|
-
import ReactDOM from 'react-dom/client'
|
|
36
|
-
import AppComponent from ${JSON.stringify(toViteFileImportPath(context.project.appComponentFile))}
|
|
37
|
-
|
|
38
|
-
const config = window.__taroAppConfig = ${appConfig}
|
|
39
|
-
config.routes = ${routes}
|
|
40
|
-
const app = createReactApp(AppComponent, React, ReactDOM, config)
|
|
41
|
-
const history = createHashHistory({ window })
|
|
42
|
-
handleAppMount(config, history)
|
|
43
|
-
createRouter(history, app, config, React)
|
|
44
|
-
`;
|
|
45
|
-
}
|
|
46
|
-
function createH5AppConfig(sharedAppConfig) {
|
|
47
|
-
return { router: {}, ...sharedAppConfig };
|
|
48
|
-
}
|
|
49
|
-
function createH5RoutesSource(pages) {
|
|
50
|
-
const routes = pages.map((page) => [
|
|
51
|
-
'Object.assign({',
|
|
52
|
-
` path: ${JSON.stringify(page.path)},`,
|
|
53
|
-
' load: async function(context, params) {',
|
|
54
|
-
` const page = await import(${JSON.stringify(createPageComponentImportPath(page.path))})`,
|
|
55
|
-
' return [page, context, params]',
|
|
56
|
-
' }',
|
|
57
|
-
`}, ${JSON.stringify(page.config)})`
|
|
58
|
-
].join('\n'));
|
|
59
|
-
return `[\n${routes.join(',\n')}\n]`;
|
|
60
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import type { BuildContext } from '../../build-context.ts';
|
|
2
|
-
type WxAssetSource = string | Uint8Array;
|
|
3
|
-
export type WxBundle = Record<string, {
|
|
4
|
-
type: 'asset' | 'chunk';
|
|
5
|
-
source?: WxAssetSource;
|
|
6
|
-
modules?: Record<string, {
|
|
7
|
-
renderedExports?: string[];
|
|
8
|
-
}>;
|
|
9
|
-
}>;
|
|
10
|
-
type WxAssetEmitter = {
|
|
11
|
-
emitFile(asset: {
|
|
12
|
-
type: 'asset';
|
|
13
|
-
fileName: string;
|
|
14
|
-
source: WxAssetSource;
|
|
15
|
-
}): string;
|
|
16
|
-
warn(message: string): void;
|
|
17
|
-
};
|
|
18
|
-
export declare function emitWxCompanionAssets(emitter: WxAssetEmitter, bundle: WxBundle, context: BuildContext): void;
|
|
19
|
-
export {};
|
|
@@ -1,129 +0,0 @@
|
|
|
1
|
-
import path from 'node:path';
|
|
2
|
-
import { recursiveMerge } from '@tarojs/helper';
|
|
3
|
-
import { Weapp as WxPlatform } from '@tarojs/plugin-platform-weapp';
|
|
4
|
-
import { normalizeModuleId } from '../../utils/modules.js';
|
|
5
|
-
import { packageRequire } from '../../utils/packages.js';
|
|
6
|
-
const taroWxComponentsPath = packageRequire.resolve('@tarojs/plugin-platform-weapp/dist/components-react');
|
|
7
|
-
const templateBuilder = createWxTemplateBuilder();
|
|
8
|
-
export function emitWxCompanionAssets(emitter, bundle, context) {
|
|
9
|
-
for (const asset of createWxCompanionAssets(bundle, context)) {
|
|
10
|
-
if (!asset)
|
|
11
|
-
continue;
|
|
12
|
-
if (asset.source === undefined) {
|
|
13
|
-
emitter.warn(`[vite-plugin-taro] WX companion asset "${asset.fileName}" is missing its source and was not emitted.`);
|
|
14
|
-
continue;
|
|
15
|
-
}
|
|
16
|
-
emitter.emitFile({ type: 'asset', fileName: asset.fileName, source: asset.source });
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
function createWxCompanionAssets(bundle, context) {
|
|
20
|
-
const json = (value) => (context.development ? JSON.stringify(value, null, 2) : JSON.stringify(value));
|
|
21
|
-
return [
|
|
22
|
-
{ fileName: 'app.json', source: json(context.project.appConfig) },
|
|
23
|
-
{ fileName: 'app.wxss', source: collectWxBundleStyles(bundle) },
|
|
24
|
-
{
|
|
25
|
-
fileName: 'base.wxml',
|
|
26
|
-
source: templateBuilder.buildTemplate(collectWxTemplateComponentConfig(bundle))
|
|
27
|
-
},
|
|
28
|
-
{ fileName: 'utils.wxs', source: templateBuilder.buildXScript() },
|
|
29
|
-
{ fileName: 'comp.wxml', source: templateBuilder.buildBaseComponentTemplate('.wxml') },
|
|
30
|
-
{ fileName: 'comp.json', source: json(createWxComponentConfig()) },
|
|
31
|
-
{ fileName: 'project.config.json', source: json(createWxProjectConfig(context)) },
|
|
32
|
-
context.project.projectPrivateConfigJson
|
|
33
|
-
? { fileName: 'project.private.config.json', source: json(context.project.projectPrivateConfigJson) }
|
|
34
|
-
: undefined,
|
|
35
|
-
{ fileName: 'sitemap.json', source: json(context.project.sitemapJson) },
|
|
36
|
-
...context.project.pages.flatMap((page) => [
|
|
37
|
-
{
|
|
38
|
-
fileName: `${page.path}.wxml`,
|
|
39
|
-
source: templateBuilder.buildPageTemplate(relativeWxRootAsset(page.path, 'base.wxml'), {
|
|
40
|
-
content: page.config,
|
|
41
|
-
path: page.path
|
|
42
|
-
})
|
|
43
|
-
},
|
|
44
|
-
{
|
|
45
|
-
fileName: `${page.path}.json`,
|
|
46
|
-
source: json({
|
|
47
|
-
...page.config,
|
|
48
|
-
usingComponents: { comp: relativeWxRootAsset(page.path, 'comp') }
|
|
49
|
-
})
|
|
50
|
-
},
|
|
51
|
-
{ fileName: `${page.path}.wxss`, source: '' }
|
|
52
|
-
])
|
|
53
|
-
];
|
|
54
|
-
}
|
|
55
|
-
function createWxProjectConfig(context) {
|
|
56
|
-
const projectConfig = context.project.projectConfigJson;
|
|
57
|
-
const setting = isJsonObject(projectConfig.setting) ? projectConfig.setting : {};
|
|
58
|
-
return {
|
|
59
|
-
...projectConfig,
|
|
60
|
-
setting: { ...setting, compileHotReLoad: true }
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
function isJsonObject(value) {
|
|
64
|
-
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
65
|
-
}
|
|
66
|
-
function createWxTemplateBuilder() {
|
|
67
|
-
const platform = new WxPlatform({ helper: { recursiveMerge }, modifyWebpackChain() { }, registerPlatform() { } }, {}, {});
|
|
68
|
-
platform.modifyTemplate({});
|
|
69
|
-
return platform.template;
|
|
70
|
-
}
|
|
71
|
-
function relativeWxRootAsset(pagePath, rootAsset) {
|
|
72
|
-
const relativePath = path.posix.relative(path.posix.dirname(pagePath), rootAsset);
|
|
73
|
-
return relativePath.startsWith('.') ? relativePath : `./${relativePath}`;
|
|
74
|
-
}
|
|
75
|
-
function collectWxTemplateComponentConfig(bundle) {
|
|
76
|
-
const config = {
|
|
77
|
-
includes: new Set([
|
|
78
|
-
'view',
|
|
79
|
-
'catch-view',
|
|
80
|
-
'static-view',
|
|
81
|
-
'pure-view',
|
|
82
|
-
'click-view',
|
|
83
|
-
'scroll-view',
|
|
84
|
-
'image',
|
|
85
|
-
'static-image',
|
|
86
|
-
'text',
|
|
87
|
-
'static-text'
|
|
88
|
-
]),
|
|
89
|
-
exclude: new Set(),
|
|
90
|
-
thirdPartyComponents: new Map(),
|
|
91
|
-
includeAll: false
|
|
92
|
-
};
|
|
93
|
-
const components = findBundleModule(bundle, taroWxComponentsPath);
|
|
94
|
-
for (const name of components?.renderedExports ?? [])
|
|
95
|
-
config.includes.add(toDashed(name));
|
|
96
|
-
return config;
|
|
97
|
-
}
|
|
98
|
-
function findBundleModule(bundle, resolvedId) {
|
|
99
|
-
const normalizedResolvedId = normalizeModuleId(resolvedId);
|
|
100
|
-
for (const item of Object.values(bundle)) {
|
|
101
|
-
if (item.type !== 'chunk')
|
|
102
|
-
continue;
|
|
103
|
-
const found = Object.entries(item.modules ?? {}).find(([id]) => normalizeModuleId(id) === normalizedResolvedId);
|
|
104
|
-
if (found)
|
|
105
|
-
return found[1];
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
function toDashed(value) {
|
|
109
|
-
return value.replace(/([a-z0-9])([A-Z])/g, '$1-$2').toLowerCase();
|
|
110
|
-
}
|
|
111
|
-
function createWxComponentConfig() {
|
|
112
|
-
return {
|
|
113
|
-
component: true,
|
|
114
|
-
styleIsolation: 'apply-shared',
|
|
115
|
-
usingComponents: { comp: './comp' }
|
|
116
|
-
};
|
|
117
|
-
}
|
|
118
|
-
function collectWxBundleStyles(bundle) {
|
|
119
|
-
const styles = [];
|
|
120
|
-
for (const [fileName, item] of Object.entries(bundle)) {
|
|
121
|
-
if (item.type !== 'asset' || !fileName.endsWith('.css'))
|
|
122
|
-
continue;
|
|
123
|
-
const source = typeof item.source === 'string' ? item.source : new TextDecoder().decode(item.source);
|
|
124
|
-
if (source)
|
|
125
|
-
styles.push(source);
|
|
126
|
-
delete bundle[fileName];
|
|
127
|
-
}
|
|
128
|
-
return styles.join('\n');
|
|
129
|
-
}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import type { ViteDevServer } from 'vite';
|
|
2
|
-
import type { BuildContext } from '../../../build-context.ts';
|
|
3
|
-
type WxDevServerContext = Pick<BuildContext, 'vite' | 'css'>;
|
|
4
|
-
/** Owns one WX bundled-development graph and all writes to its fixed output directory. */
|
|
5
|
-
export declare class WxDevelopmentSession {
|
|
6
|
-
private readonly context;
|
|
7
|
-
private readonly server;
|
|
8
|
-
private readonly adapter;
|
|
9
|
-
private readonly updateTransport;
|
|
10
|
-
private readonly outDir;
|
|
11
|
-
private readonly initialBundle;
|
|
12
|
-
private readonly outputQueue;
|
|
13
|
-
private readonly fullBuildScheduler;
|
|
14
|
-
private originalPrintUrls;
|
|
15
|
-
private snapshot;
|
|
16
|
-
constructor(context: WxDevServerContext, server: ViteDevServer);
|
|
17
|
-
private get config();
|
|
18
|
-
install(): void;
|
|
19
|
-
close(): Promise<void>;
|
|
20
|
-
private readonly printUrls;
|
|
21
|
-
private readonly handleHttpListening;
|
|
22
|
-
private readonly handleWatchedFile;
|
|
23
|
-
private handleBundleOutput;
|
|
24
|
-
private handlePatch;
|
|
25
|
-
private handleError;
|
|
26
|
-
private requestFullBuild;
|
|
27
|
-
private waitForInitialBundle;
|
|
28
|
-
private reportOutputError;
|
|
29
|
-
private reportRebuildError;
|
|
30
|
-
}
|
|
31
|
-
export {};
|