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,197 @@
|
|
|
1
|
+
import type { types as BabelTypes } from '@babel/core'
|
|
2
|
+
import { type NodePath, type PluginObject, types } from '@babel/core'
|
|
3
|
+
import babel from '@rolldown/plugin-babel'
|
|
4
|
+
import type { HtmlTagDescriptor, Plugin, PluginOption } from 'vite'
|
|
5
|
+
import type { VitePluginTaroOptions } from '../../../options.ts'
|
|
6
|
+
import { esTarget } from '../../utils/constant.ts'
|
|
7
|
+
import { toViteFileImportPath } from '../../utils/modules.ts'
|
|
8
|
+
import { packageRequire } from '../../utils/packages.ts'
|
|
9
|
+
import { clientTaroApiId } from '../client/client-taro.ts'
|
|
10
|
+
import { h5AppPath } from './constant.ts'
|
|
11
|
+
import { createModuleResolver } from './resolver/module-resolver.ts'
|
|
12
|
+
|
|
13
|
+
/** Creates the plugins that own the H5 target. */
|
|
14
|
+
export function createH5TargetPlugins(options: VitePluginTaroOptions): PluginOption[] {
|
|
15
|
+
return [...createH5SupportPlugins(), createH5TargetPlugin(options)]
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** Configures H5 resolution and supplies the specialized physical application entry. */
|
|
19
|
+
function createH5TargetPlugin(options: VitePluginTaroOptions): Plugin {
|
|
20
|
+
const moduleResolver = createModuleResolver(options)
|
|
21
|
+
|
|
22
|
+
return {
|
|
23
|
+
name: 'vpt:h5',
|
|
24
|
+
|
|
25
|
+
config() {
|
|
26
|
+
return {
|
|
27
|
+
define: createH5Defines(),
|
|
28
|
+
resolve: {
|
|
29
|
+
mainFields: ['main:h5', 'browser', 'module', 'jsnext:main', 'jsnext'],
|
|
30
|
+
alias: [
|
|
31
|
+
{
|
|
32
|
+
find: /^@stencil\/core\/internal\/client$/,
|
|
33
|
+
replacement: packageRequire.resolve('@stencil/core/internal/client', {
|
|
34
|
+
paths: [packageRequire.resolve('@tarojs/components/package.json')]
|
|
35
|
+
})
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
find: /^@tarojs\/components$/,
|
|
39
|
+
replacement: packageRequire.resolve('@tarojs/components/lib/react')
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
find: /^@tarojs\/components\/dist\/components$/,
|
|
43
|
+
replacement: packageRequire.resolve('@tarojs/components/dist/components')
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
find: /^@tarojs\/taro$/,
|
|
47
|
+
replacement: packageRequire.resolve('@tarojs/plugin-platform-h5/dist/runtime/apis')
|
|
48
|
+
}
|
|
49
|
+
]
|
|
50
|
+
},
|
|
51
|
+
optimizeDeps: {
|
|
52
|
+
exclude: ['@stencil/core/internal/client']
|
|
53
|
+
},
|
|
54
|
+
build: {
|
|
55
|
+
target: esTarget
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
|
|
60
|
+
resolveId: {
|
|
61
|
+
order: 'pre',
|
|
62
|
+
handler(id) {
|
|
63
|
+
return moduleResolver.resolveId({
|
|
64
|
+
id,
|
|
65
|
+
projectRoot: this.environment.config.root
|
|
66
|
+
})
|
|
67
|
+
}
|
|
68
|
+
},
|
|
69
|
+
|
|
70
|
+
transform: {
|
|
71
|
+
order: 'pre',
|
|
72
|
+
handler(code, id) {
|
|
73
|
+
return moduleResolver.transform({
|
|
74
|
+
code,
|
|
75
|
+
id,
|
|
76
|
+
projectRoot: this.environment.config.root,
|
|
77
|
+
sourcemap: Boolean(this.environment.config.build.sourcemap)
|
|
78
|
+
})
|
|
79
|
+
}
|
|
80
|
+
},
|
|
81
|
+
|
|
82
|
+
transformIndexHtml: {
|
|
83
|
+
order: 'pre',
|
|
84
|
+
handler() {
|
|
85
|
+
return createH5IndexHtmlTags()
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/** Injects the physical H5 App into the application document. */
|
|
92
|
+
function createH5IndexHtmlTags(): HtmlTagDescriptor[] {
|
|
93
|
+
return [
|
|
94
|
+
{
|
|
95
|
+
tag: 'script',
|
|
96
|
+
attrs: {
|
|
97
|
+
type: 'module'
|
|
98
|
+
},
|
|
99
|
+
children: `import '${toViteFileImportPath(h5AppPath)}'`,
|
|
100
|
+
injectTo: 'body'
|
|
101
|
+
}
|
|
102
|
+
]
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/** Creates H5-only Babel transforms for Stencil CSS ordering and Taro API imports. */
|
|
106
|
+
function createH5SupportPlugins(): PluginOption[] {
|
|
107
|
+
return [
|
|
108
|
+
babel({
|
|
109
|
+
include: /[\\/]@stencil[\\/]core[\\/]internal[\\/]client[\\/]index\.js(?:\?.*)?$/,
|
|
110
|
+
exclude: [],
|
|
111
|
+
plugins: [rewriteStencilStyleInsertion]
|
|
112
|
+
}),
|
|
113
|
+
babel({
|
|
114
|
+
plugins: [
|
|
115
|
+
[
|
|
116
|
+
packageRequire.resolve('babel-plugin-transform-taroapi'),
|
|
117
|
+
{
|
|
118
|
+
packageName: clientTaroApiId,
|
|
119
|
+
definition: packageRequire(
|
|
120
|
+
packageRequire.resolve('@tarojs/plugin-platform-h5/dist/definition.json')
|
|
121
|
+
)
|
|
122
|
+
}
|
|
123
|
+
]
|
|
124
|
+
]
|
|
125
|
+
})
|
|
126
|
+
]
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/** Keeps Stencil-injected Taro component styles before application stylesheets. */
|
|
130
|
+
function rewriteStencilStyleInsertion(): PluginObject {
|
|
131
|
+
return {
|
|
132
|
+
name: 'vpt:rewrite-stencil-style-insertion',
|
|
133
|
+
visitor: {
|
|
134
|
+
CallExpression(callPath) {
|
|
135
|
+
if (!isStencilStyleInsertBeforeCall(callPath)) {
|
|
136
|
+
return
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
callPath
|
|
140
|
+
.get('arguments.1')
|
|
141
|
+
.replaceWith(
|
|
142
|
+
types.conditionalExpression(
|
|
143
|
+
types.callExpression(
|
|
144
|
+
types.memberExpression(types.identifier('scopeId'), types.identifier('startsWith')),
|
|
145
|
+
[types.stringLiteral('sc-taro-')]
|
|
146
|
+
),
|
|
147
|
+
createStyleQuery('style,link[rel="stylesheet"]'),
|
|
148
|
+
createStyleQuery('link')
|
|
149
|
+
)
|
|
150
|
+
)
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/** Identifies Stencil's default component-style insertion call. */
|
|
157
|
+
function isStencilStyleInsertBeforeCall(callPath: NodePath<BabelTypes.CallExpression>): boolean {
|
|
158
|
+
const { callee, arguments: callArguments } = callPath.node
|
|
159
|
+
return (
|
|
160
|
+
types.isMemberExpression(callee) &&
|
|
161
|
+
types.isIdentifier(callee.object, { name: 'styleContainerNode' }) &&
|
|
162
|
+
types.isIdentifier(callee.property, { name: 'insertBefore' }) &&
|
|
163
|
+
types.isIdentifier(callArguments[0], { name: 'styleElm' }) &&
|
|
164
|
+
isStyleQuery(callArguments[1], 'link')
|
|
165
|
+
)
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/** Identifies one style-container querySelector call. */
|
|
169
|
+
function isStyleQuery(node: BabelTypes.Node | null | undefined, selector: string): boolean {
|
|
170
|
+
return (
|
|
171
|
+
types.isCallExpression(node) &&
|
|
172
|
+
types.isMemberExpression(node.callee) &&
|
|
173
|
+
types.isIdentifier(node.callee.object, { name: 'styleContainerNode' }) &&
|
|
174
|
+
types.isIdentifier(node.callee.property, { name: 'querySelector' }) &&
|
|
175
|
+
types.isStringLiteral(node.arguments[0], { value: selector })
|
|
176
|
+
)
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/** Creates one style-container querySelector call. */
|
|
180
|
+
function createStyleQuery(selector: string): ReturnType<typeof types.callExpression> {
|
|
181
|
+
return types.callExpression(
|
|
182
|
+
types.memberExpression(types.identifier('styleContainerNode'), types.identifier('querySelector')),
|
|
183
|
+
[types.stringLiteral(selector)]
|
|
184
|
+
)
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/** Creates H5 Taro compile-time constants. */
|
|
188
|
+
function createH5Defines(): Record<string, string> {
|
|
189
|
+
return {
|
|
190
|
+
'process.env.FRAMEWORK': JSON.stringify('react'),
|
|
191
|
+
'process.env.SUPPORT_TARO_POLYFILL': JSON.stringify('disabled'),
|
|
192
|
+
'process.env.TARO_ENV': JSON.stringify('h5'),
|
|
193
|
+
'process.env.TARO_PLATFORM': JSON.stringify('web'),
|
|
194
|
+
'process.env.SUPPORT_DINGTALK_NAVIGATE': JSON.stringify('disabled'),
|
|
195
|
+
DEPRECATED_ADAPTER_COMPONENT: 'false'
|
|
196
|
+
}
|
|
197
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { VitePluginTaroOptions } from '../../../../options.ts'
|
|
2
|
+
import { normalizeModuleId, resolveAppComponentPath } from '../../../utils/modules.ts'
|
|
3
|
+
import { appComponentId } from '../../client/constant.ts'
|
|
4
|
+
import { h5AppPath } from '../constant.ts'
|
|
5
|
+
import { transformH5App } from '../transform-app.ts'
|
|
6
|
+
|
|
7
|
+
/** Creates H5 application module resolution and specialization. */
|
|
8
|
+
export function createModuleResolver(options: VitePluginTaroOptions) {
|
|
9
|
+
return {
|
|
10
|
+
resolveId({ id, projectRoot }: { id: string; projectRoot: string }): string | undefined {
|
|
11
|
+
if (id === appComponentId) {
|
|
12
|
+
return resolveAppComponentPath({ appPath: options.app, projectRoot })
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
|
|
16
|
+
transform({
|
|
17
|
+
code,
|
|
18
|
+
id,
|
|
19
|
+
projectRoot,
|
|
20
|
+
sourcemap = true
|
|
21
|
+
}: {
|
|
22
|
+
code: string
|
|
23
|
+
id: string
|
|
24
|
+
projectRoot: string
|
|
25
|
+
sourcemap?: boolean
|
|
26
|
+
}) {
|
|
27
|
+
if (normalizeModuleId(id) === normalizeModuleId(h5AppPath)) {
|
|
28
|
+
return transformH5App({ code, id, options, projectRoot, sourcemap })
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { types } from '@babel/core'
|
|
2
|
+
import type { VitePluginTaroOptions, VitePluginTaroPageOption } from '../../../options.ts'
|
|
3
|
+
import { createPageComponentImportPath } from '../../utils/modules.ts'
|
|
4
|
+
import { createAppConfig } from '../../utils/project-config.ts'
|
|
5
|
+
import { type AstTransformResult, replaceWithAst } from '../../utils/transform.ts'
|
|
6
|
+
|
|
7
|
+
const appConfigPlaceholder = '__VITE_PLUGIN_TARO_H5_APP_CONFIG__'
|
|
8
|
+
const routesPlaceholder = '__VITE_PLUGIN_TARO_H5_ROUTES__'
|
|
9
|
+
|
|
10
|
+
/** Specializes the physical H5 App for one configured project. */
|
|
11
|
+
export async function transformH5App({
|
|
12
|
+
code,
|
|
13
|
+
id,
|
|
14
|
+
options,
|
|
15
|
+
projectRoot,
|
|
16
|
+
sourcemap = true
|
|
17
|
+
}: {
|
|
18
|
+
code: string
|
|
19
|
+
id: string
|
|
20
|
+
options: VitePluginTaroOptions
|
|
21
|
+
projectRoot: string
|
|
22
|
+
sourcemap?: boolean
|
|
23
|
+
}): Promise<AstTransformResult> {
|
|
24
|
+
const transformed = await replaceWithAst(
|
|
25
|
+
code,
|
|
26
|
+
id,
|
|
27
|
+
{
|
|
28
|
+
[appConfigPlaceholder]: types.valueToNode({
|
|
29
|
+
router: {},
|
|
30
|
+
...createAppConfig(options)
|
|
31
|
+
}),
|
|
32
|
+
[routesPlaceholder]: types.arrayExpression(
|
|
33
|
+
options.pages.map((page) => {
|
|
34
|
+
return createRoute({ page, projectRoot })
|
|
35
|
+
})
|
|
36
|
+
)
|
|
37
|
+
},
|
|
38
|
+
sourcemap
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
return { code: transformed.code, map: transformed.map }
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Creates one lazy H5 route shaped like:
|
|
46
|
+
* {
|
|
47
|
+
* path: 'pages/home/index',
|
|
48
|
+
* load: async function (context, params) {
|
|
49
|
+
* const page = await import('/@fs/project/src/pages/home/index.tsx')
|
|
50
|
+
* return [page, context, params]
|
|
51
|
+
* },
|
|
52
|
+
* ...pageConfig
|
|
53
|
+
* }
|
|
54
|
+
*/
|
|
55
|
+
function createRoute({
|
|
56
|
+
page,
|
|
57
|
+
projectRoot
|
|
58
|
+
}: {
|
|
59
|
+
page: VitePluginTaroPageOption
|
|
60
|
+
projectRoot: string
|
|
61
|
+
}): ReturnType<typeof types.objectExpression> {
|
|
62
|
+
const pageComponentPath = createPageComponentImportPath({ pagePath: page.path, projectRoot })
|
|
63
|
+
|
|
64
|
+
const load = types.functionExpression(
|
|
65
|
+
null,
|
|
66
|
+
[types.identifier('context'), types.identifier('params')],
|
|
67
|
+
types.blockStatement([
|
|
68
|
+
types.variableDeclaration('const', [
|
|
69
|
+
types.variableDeclarator(
|
|
70
|
+
types.identifier('page'),
|
|
71
|
+
types.awaitExpression(types.importExpression(types.stringLiteral(pageComponentPath)))
|
|
72
|
+
)
|
|
73
|
+
]),
|
|
74
|
+
types.returnStatement(
|
|
75
|
+
types.arrayExpression([
|
|
76
|
+
types.identifier('page'),
|
|
77
|
+
types.identifier('context'),
|
|
78
|
+
types.identifier('params')
|
|
79
|
+
])
|
|
80
|
+
)
|
|
81
|
+
]),
|
|
82
|
+
false,
|
|
83
|
+
true
|
|
84
|
+
)
|
|
85
|
+
return types.objectExpression([
|
|
86
|
+
types.objectProperty(types.identifier('path'), types.stringLiteral(page.path)),
|
|
87
|
+
types.objectProperty(types.identifier('load'), load),
|
|
88
|
+
types.spreadElement(types.valueToNode(page.config))
|
|
89
|
+
])
|
|
90
|
+
}
|