vite-plugin-taro 0.5.16 → 0.6.1
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 +1 -1
- package/README.md +1 -1
- package/dist/node/plugins/client/client-taro.d.ts +2 -2
- package/dist/node/plugins/conditional/conditional-directives.d.ts +2 -2
- package/dist/node/plugins/h5/plugins.d.ts +2 -2
- package/dist/node/plugins/h5/resolver/module-resolver.d.ts +2 -2
- package/dist/node/plugins/h5/transform-app.d.ts +2 -2
- package/dist/node/plugins/h5/transform-app.js +2 -2
- package/dist/node/plugins/wx/chunk-path.d.ts +8 -0
- package/dist/node/plugins/wx/chunk-path.js +18 -0
- package/dist/node/plugins/wx/dev/dev-host.d.ts +2 -2
- package/dist/node/plugins/wx/dev/plugins.d.ts +2 -2
- package/dist/node/plugins/wx/dev/wx-dev-options.d.ts +2 -2
- package/dist/node/plugins/wx/dev/wx-dev-options.js +21 -0
- package/dist/node/plugins/wx/native/create-native-component-output.d.ts +3 -1
- package/dist/node/plugins/wx/native/create-native-component-output.js +3 -5
- package/dist/node/plugins/wx/output/files.d.ts +5 -4
- package/dist/node/plugins/wx/output/files.js +2 -2
- package/dist/node/plugins/wx/output/json.d.ts +4 -4
- package/dist/node/plugins/wx/output/json.js +2 -2
- package/dist/node/plugins/wx/output/templates.d.ts +2 -2
- package/dist/node/plugins/wx/placer/placement.d.ts +50 -0
- package/dist/node/plugins/wx/placer/placement.js +245 -0
- package/dist/node/plugins/wx/placer/placer.d.ts +60 -0
- package/dist/node/plugins/wx/placer/placer.js +123 -0
- package/dist/node/plugins/wx/plugins.d.ts +2 -2
- package/dist/node/plugins/wx/plugins.js +16 -16
- package/dist/node/plugins/wx/render/capsule-wrapper.js +3 -3
- package/dist/node/plugins/wx/render/native.js +5 -5
- package/dist/node/plugins/wx/render/transport.d.ts +7 -3
- package/dist/node/plugins/wx/render/transport.js +18 -9
- package/dist/node/plugins/wx/resolve/resolver.d.ts +2 -2
- package/dist/node/plugins/wx/resolve/specialize-bootstrap.d.ts +2 -2
- package/dist/node/plugins/wx/resolve/specialize-bootstrap.js +1 -1
- package/dist/node/plugins/wx/resolve/specialize-page-capsule.d.ts +2 -2
- package/dist/node/plugins/wx/resolve/specialize-page-capsule.js +2 -2
- package/dist/node/utils/modules.d.ts +0 -2
- package/dist/node/utils/modules.js +0 -7
- package/dist/node/utils/project-config.d.ts +2 -2
- package/dist/node/vpt.d.ts +4 -0
- package/dist/node/{vite-plugin.js → vpt.js} +1 -1
- package/dist/options.d.ts +65 -13
- package/dist/runtime/h5/app.js +2 -2
- package/dist/runtime/wx/amphibious/bootstrap.js +1 -1
- package/dist/runtime/wx/amphibious/transport.js +1 -1
- package/dist/runtime/wx/capsule/page.js +1 -1
- package/dist/vite.d.ts +2 -2
- package/dist/vite.js +1 -1
- package/package.json +3 -3
- package/src/node/plugins/client/client-taro.ts +3 -3
- package/src/node/plugins/conditional/conditional-directives.ts +3 -3
- package/src/node/plugins/h5/plugins.ts +3 -3
- package/src/node/plugins/h5/resolver/module-resolver.ts +2 -2
- package/src/node/plugins/h5/transform-app.ts +5 -5
- package/src/node/plugins/wx/chunk-path.ts +22 -0
- package/src/node/plugins/wx/dev/dev-host.ts +2 -2
- package/src/node/plugins/wx/dev/plugins.ts +2 -5
- package/src/node/plugins/wx/dev/wx-dev-options.ts +23 -2
- package/src/node/plugins/wx/native/create-native-component-output.ts +6 -5
- package/src/node/plugins/wx/output/files.ts +7 -5
- package/src/node/plugins/wx/output/json.ts +9 -10
- package/src/node/plugins/wx/output/templates.ts +3 -3
- package/src/node/plugins/wx/placer/placement.ts +364 -0
- package/src/node/plugins/wx/placer/placer.ts +154 -0
- package/src/node/plugins/wx/plugins.ts +20 -20
- package/src/node/plugins/wx/render/capsule-wrapper.ts +3 -3
- package/src/node/plugins/wx/render/native.ts +5 -5
- package/src/node/plugins/wx/render/transport.ts +24 -8
- package/src/node/plugins/wx/resolve/resolver.ts +5 -5
- package/src/node/plugins/wx/resolve/specialize-bootstrap.ts +3 -3
- package/src/node/plugins/wx/resolve/specialize-page-capsule.ts +4 -4
- package/src/node/utils/modules.ts +0 -8
- package/src/node/utils/project-config.ts +2 -2
- package/src/node/{vite-plugin.ts → vpt.ts} +2 -2
- package/src/options.ts +71 -13
- package/src/runtime/h5/app.ts +4 -4
- package/src/runtime/wx/amphibious/bootstrap.ts +2 -2
- package/src/runtime/wx/amphibious/transport.ts +2 -4
- package/src/runtime/wx/capsule/page.ts +3 -8
- package/src/vite.ts +2 -2
- package/dist/node/plugins/wx/placement/placer.d.ts +0 -78
- package/dist/node/plugins/wx/placement/placer.js +0 -158
- package/dist/node/plugins/wx/placement/plan.d.ts +0 -46
- package/dist/node/plugins/wx/placement/plan.js +0 -210
- package/dist/node/vite-plugin.d.ts +0 -4
- package/src/node/plugins/wx/placement/placer.ts +0 -187
- package/src/node/plugins/wx/placement/plan.ts +0 -306
|
@@ -2,9 +2,10 @@ import path from 'node:path'
|
|
|
2
2
|
import { types } from '@babel/core'
|
|
3
3
|
import type { Rolldown } from 'vite'
|
|
4
4
|
import { type AstTransformResult, replaceWithAst } from '../../../utils/transform.ts'
|
|
5
|
+
import { toLogicalChunkId } from '../chunk-path.ts'
|
|
5
6
|
import { getWxExecutionKind } from '../module.ts'
|
|
6
7
|
|
|
7
|
-
const transportPlaceholder = '
|
|
8
|
+
const transportPlaceholder = '__VPT_TRANSPORT__'
|
|
8
9
|
const moduleIdParameter = 'moduleId'
|
|
9
10
|
const exportBindingParameter = 'exportBinding'
|
|
10
11
|
|
|
@@ -14,8 +15,11 @@ type TransportedChunk = {
|
|
|
14
15
|
}
|
|
15
16
|
|
|
16
17
|
/**
|
|
17
|
-
* Materializes transport while Rolldown's preliminary hash placeholders are still active
|
|
18
|
-
*
|
|
18
|
+
* Materializes transport while Rolldown's preliminary hash placeholders are still active. Each switch case deliberately has
|
|
19
|
+
* two IDs: the package-neutral preliminary filename without its `assets/` directory becomes the SystemJS registration
|
|
20
|
+
* identity, while the LTHP-selected assets/package-qualified filename becomes the literal native require path. Rolldown
|
|
21
|
+
* substitutes both hashes after this transform, so the
|
|
22
|
+
* generated transport code and its own content hash describe the exact files that `generateBundle` later materializes.
|
|
19
23
|
*
|
|
20
24
|
* This intentionally creates broad hash invalidation: changing one capsule can rename transport, then bootstrap, then
|
|
21
25
|
* chunks that import bootstrap. A Mini Program ships one application package rather than independently cached HTTP
|
|
@@ -26,14 +30,18 @@ export async function materializeTransport({
|
|
|
26
30
|
transportChunk,
|
|
27
31
|
chunks,
|
|
28
32
|
getLoadMode,
|
|
33
|
+
getPhysicalChunkId = (chunk) => chunk.fileName,
|
|
29
34
|
sourcemap = true
|
|
30
35
|
}: {
|
|
31
36
|
code: string
|
|
32
37
|
transportChunk: Rolldown.RenderedChunk
|
|
33
38
|
chunks: Readonly<Record<string, Rolldown.RenderedChunk>>
|
|
34
39
|
getLoadMode(chunk: Rolldown.RenderedChunk): 'sync' | 'async'
|
|
40
|
+
getPhysicalChunkId?: (chunk: Rolldown.RenderedChunk) => string
|
|
35
41
|
sourcemap?: boolean
|
|
36
42
|
}): Promise<AstTransformResult> {
|
|
43
|
+
const physicalTransportId = getPhysicalChunkId(transportChunk)
|
|
44
|
+
|
|
37
45
|
// Babel constructs and safely serializes an expression shaped like:
|
|
38
46
|
// (moduleId) => {
|
|
39
47
|
// switch (moduleId) {
|
|
@@ -48,13 +56,19 @@ export async function materializeTransport({
|
|
|
48
56
|
.sort((left, right) => left.chunk.fileName.localeCompare(right.chunk.fileName))
|
|
49
57
|
.map(({ chunk, kind }) => {
|
|
50
58
|
const loadMode = getLoadMode(chunk)
|
|
59
|
+
|
|
60
|
+
const logicalChunkId = toLogicalChunkId(chunk.fileName)
|
|
61
|
+
// Only native loading crosses the logical/physical boundary and receives the assets/package-qualified path.
|
|
62
|
+
const physicalChunkId = getPhysicalChunkId(chunk)
|
|
63
|
+
|
|
51
64
|
if (kind === 'amphibious' && loadMode !== 'sync') {
|
|
52
65
|
throw new Error(`Amphibious wx module must be in the main package: ${chunk.fileName}`)
|
|
53
66
|
}
|
|
54
67
|
|
|
55
68
|
return createTransportCase({
|
|
56
|
-
chunkId:
|
|
57
|
-
transportFileName:
|
|
69
|
+
chunkId: logicalChunkId,
|
|
70
|
+
transportFileName: physicalTransportId,
|
|
71
|
+
physicalChunkId: physicalChunkId,
|
|
58
72
|
loadMode,
|
|
59
73
|
kind
|
|
60
74
|
})
|
|
@@ -92,19 +106,21 @@ function getTransportedChunks(chunks: Readonly<Record<string, Rolldown.RenderedC
|
|
|
92
106
|
return transportedChunks
|
|
93
107
|
}
|
|
94
108
|
|
|
95
|
-
/** Creates one
|
|
109
|
+
/** Creates one logical-ID switch case while keeping its physical native require argument literal. */
|
|
96
110
|
function createTransportCase({
|
|
97
111
|
chunkId,
|
|
98
112
|
transportFileName,
|
|
99
113
|
loadMode,
|
|
100
|
-
kind
|
|
114
|
+
kind,
|
|
115
|
+
physicalChunkId
|
|
101
116
|
}: {
|
|
102
117
|
chunkId: string
|
|
103
118
|
transportFileName: string
|
|
104
119
|
loadMode: 'sync' | 'async'
|
|
120
|
+
physicalChunkId: string
|
|
105
121
|
kind: 'capsule' | 'amphibious'
|
|
106
122
|
}): ReturnType<typeof types.switchCase> {
|
|
107
|
-
const requirePath = toNativeRequirePath(transportFileName,
|
|
123
|
+
const requirePath = toNativeRequirePath(transportFileName, physicalChunkId)
|
|
108
124
|
|
|
109
125
|
const requireCallee =
|
|
110
126
|
loadMode === 'sync'
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { normalizePath } from 'vite'
|
|
2
|
-
import type {
|
|
2
|
+
import type { VptOptions, VptPageOption } from '../../../../options.ts'
|
|
3
3
|
import { normalizeModuleId, resolveAppComponentPath, resolvePageComponentPath } from '../../../utils/modules.ts'
|
|
4
4
|
import { createAppConfig } from '../../../utils/project-config.ts'
|
|
5
5
|
import { appComponentId } from '../../client/constant.ts'
|
|
@@ -25,7 +25,7 @@ import { specializePageCapsule } from './specialize-page-capsule.ts'
|
|
|
25
25
|
type PrivateIdResolver = (importer: string | undefined, projectRoot: string) => string
|
|
26
26
|
|
|
27
27
|
/** Creates the resolver and source specializer for the wx module graph. */
|
|
28
|
-
export function createResolver(options:
|
|
28
|
+
export function createResolver(options: VptOptions) {
|
|
29
29
|
const normalizedBootstrapPath = normalizePath(bootstrapPath)
|
|
30
30
|
const normalizedPageCapsulePath = normalizePath(pageCapsulePath)
|
|
31
31
|
|
|
@@ -87,7 +87,7 @@ export function createResolver(options: VitePluginTaroOptions) {
|
|
|
87
87
|
}
|
|
88
88
|
|
|
89
89
|
/** Declares output entries and the ordered application subset that can own user styles. */
|
|
90
|
-
function createEntryGraph(pages: readonly
|
|
90
|
+
function createEntryGraph(pages: readonly VptPageOption[]) {
|
|
91
91
|
const pageEntries = pages.map((page) => {
|
|
92
92
|
return {
|
|
93
93
|
capsuleId: createRouteModuleId({ moduleId: pageCapsulePath, pagePath: page.path }),
|
|
@@ -128,8 +128,8 @@ function requireConfiguredPage({
|
|
|
128
128
|
pageByPath
|
|
129
129
|
}: {
|
|
130
130
|
moduleId: string | undefined
|
|
131
|
-
pageByPath: ReadonlyMap<string,
|
|
132
|
-
}):
|
|
131
|
+
pageByPath: ReadonlyMap<string, VptPageOption>
|
|
132
|
+
}): VptPageOption {
|
|
133
133
|
const queryIndex = moduleId?.indexOf('?') ?? -1
|
|
134
134
|
const pagePath = queryIndex === -1 ? undefined : new URLSearchParams(moduleId?.slice(queryIndex + 1)).get('route')
|
|
135
135
|
const page = pagePath ? pageByPath.get(pagePath) : undefined
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { types } from '@babel/core'
|
|
2
|
-
import type {
|
|
2
|
+
import type { VptJsonObject } from '../../../../options.ts'
|
|
3
3
|
import { type AstTransformResult, replaceWithAst } from '../../../utils/transform.ts'
|
|
4
4
|
|
|
5
|
-
const appConfigPlaceholder = '
|
|
5
|
+
const appConfigPlaceholder = '__VPT_APP_CONFIG__'
|
|
6
6
|
|
|
7
7
|
/** Specializes the amphibious bootstrap with the shared App configuration. */
|
|
8
8
|
export function specializeBootstrap({
|
|
@@ -13,7 +13,7 @@ export function specializeBootstrap({
|
|
|
13
13
|
}: {
|
|
14
14
|
code: string
|
|
15
15
|
id: string
|
|
16
|
-
appConfig:
|
|
16
|
+
appConfig: VptJsonObject
|
|
17
17
|
sourcemap?: boolean
|
|
18
18
|
}): Promise<AstTransformResult> {
|
|
19
19
|
return replaceWithAst(
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { types } from '@babel/core'
|
|
2
|
-
import type {
|
|
2
|
+
import type { VptPageOption } from '../../../../options.ts'
|
|
3
3
|
import { type AstTransformResult, replaceWithAst } from '../../../utils/transform.ts'
|
|
4
4
|
|
|
5
|
-
const pagePathPlaceholder = '
|
|
6
|
-
const pageConfigPlaceholder = '
|
|
5
|
+
const pagePathPlaceholder = '__VPT_PAGE_PATH__'
|
|
6
|
+
const pageConfigPlaceholder = '__VPT_PAGE_CONFIG__'
|
|
7
7
|
|
|
8
8
|
/** Specializes the Page capsule for one configured route. */
|
|
9
9
|
export function specializePageCapsule({
|
|
@@ -14,7 +14,7 @@ export function specializePageCapsule({
|
|
|
14
14
|
}: {
|
|
15
15
|
code: string
|
|
16
16
|
id: string
|
|
17
|
-
page:
|
|
17
|
+
page: VptPageOption
|
|
18
18
|
sourcemap?: boolean
|
|
19
19
|
}): Promise<AstTransformResult> {
|
|
20
20
|
return replaceWithAst(
|
|
@@ -11,14 +11,6 @@ type PageComponentPathOptions = {
|
|
|
11
11
|
projectRoot: string
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
/** Resolves a final relative reference to the canonical output chunk ID used by the WX module registry. */
|
|
15
|
-
export function resolveChunkReference(importerChunkId: string, reference: string): string {
|
|
16
|
-
if (!reference.startsWith('./') && !reference.startsWith('../')) {
|
|
17
|
-
throw new Error(`Expected a relative chunk reference in ${importerChunkId}: ${reference}`)
|
|
18
|
-
}
|
|
19
|
-
return path.posix.join(path.posix.dirname(importerChunkId), reference)
|
|
20
|
-
}
|
|
21
|
-
|
|
22
14
|
/** Resolves the source file for the configured App component. */
|
|
23
15
|
export function resolveAppComponentPath({ appPath, projectRoot }: AppComponentPathOptions): string {
|
|
24
16
|
return path.resolve(projectRoot, appPath)
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { VptJsonObject, VptOptions } from '../../options.ts'
|
|
2
2
|
|
|
3
3
|
/** Creates shared App configuration with configured Page order as the authoritative value. */
|
|
4
|
-
export function createAppConfig(options:
|
|
4
|
+
export function createAppConfig(options: VptOptions): VptJsonObject {
|
|
5
5
|
const { subPackages: _subPackages, subpackages: _subpackages, ...appJson } = options.appJson
|
|
6
6
|
return {
|
|
7
7
|
...appJson,
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import react from '@vitejs/plugin-react'
|
|
2
2
|
import type { PluginOption } from 'vite'
|
|
3
|
-
import type {
|
|
3
|
+
import type { VptOptions } from '../options.ts'
|
|
4
4
|
import { createClientTaroPlugin } from './plugins/client/client-taro.ts'
|
|
5
5
|
import { createConditionalDirectivePlugin } from './plugins/conditional/conditional-directives.ts'
|
|
6
6
|
import { createH5TargetPlugins } from './plugins/h5/plugins.ts'
|
|
7
7
|
import { createWxTargetPlugins } from './plugins/wx/plugins.ts'
|
|
8
8
|
|
|
9
9
|
/** Creates the Vite plugins for one Taro target. */
|
|
10
|
-
export default function
|
|
10
|
+
export default function vpt(options: VptOptions): PluginOption[] {
|
|
11
11
|
return [
|
|
12
12
|
createConditionalDirectivePlugin(options.target),
|
|
13
13
|
createClientTaroPlugin(options.target),
|
package/src/options.ts
CHANGED
|
@@ -1,24 +1,82 @@
|
|
|
1
1
|
/** A JSON object used by generated target configs. */
|
|
2
|
-
export type
|
|
2
|
+
export type VptJsonObject = Record<string, unknown>
|
|
3
3
|
|
|
4
4
|
/** Build target handled by this plugin. */
|
|
5
|
-
export type
|
|
5
|
+
export type VptTarget = 'wx' | 'h5'
|
|
6
6
|
|
|
7
7
|
/** Configures one Taro page. */
|
|
8
|
-
export type
|
|
9
|
-
/**
|
|
8
|
+
export type VptPageOption = {
|
|
9
|
+
/**
|
|
10
|
+
* Taro route and output path without a file extension.
|
|
11
|
+
*
|
|
12
|
+
* The plugin resolves the page component from `src/${path}.tsx`, relative to the Vite project root. For example,
|
|
13
|
+
* `pages/home/index` resolves to `src/pages/home/index.tsx` and is emitted under `pages/home/index` for `wx`.
|
|
14
|
+
*/
|
|
10
15
|
path: string
|
|
11
16
|
|
|
12
|
-
|
|
17
|
+
/**
|
|
18
|
+
* Target-independent Taro page configuration.
|
|
19
|
+
*
|
|
20
|
+
* For `wx`, these values form the generated `<path>.json`; the plugin augments `usingComponents` with its generated
|
|
21
|
+
* component registrations. For `h5`, the values are added to the corresponding Taro router entry.
|
|
22
|
+
*/
|
|
23
|
+
config: VptJsonObject
|
|
13
24
|
}
|
|
14
25
|
|
|
15
|
-
/** Configures
|
|
16
|
-
export interface
|
|
17
|
-
|
|
26
|
+
/** Configures vpt for one build target. */
|
|
27
|
+
export interface VptOptions {
|
|
28
|
+
/**
|
|
29
|
+
* Platform produced by the current Vite invocation.
|
|
30
|
+
*
|
|
31
|
+
* Use `wx` to emit a WeChat Mini Program or `h5` to emit a browser application. The selected target controls Taro
|
|
32
|
+
* module resolution, conditional compilation, runtime bootstrapping, style processing, and output generation.
|
|
33
|
+
*/
|
|
34
|
+
target: VptTarget
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Source module that default-exports the root React application component.
|
|
38
|
+
*
|
|
39
|
+
* Relative paths are resolved from Vite's project root, for example `src/app.tsx`. The component wraps the active
|
|
40
|
+
* page through its `children` prop and is the appropriate place to import application-wide styles.
|
|
41
|
+
*/
|
|
18
42
|
app: string
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Complete ordered list of application pages.
|
|
46
|
+
*
|
|
47
|
+
* The declared order becomes the `pages` order in the generated `app.json`, the H5 route order, and the Page order
|
|
48
|
+
* in the application style cascade. Each Page source is resolved according to its `path`.
|
|
49
|
+
*/
|
|
50
|
+
pages: VptPageOption[]
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Target-independent Taro application configuration.
|
|
54
|
+
*
|
|
55
|
+
* For `wx`, these values form the generated `app.json`. For `h5`, they configure the Taro application and router.
|
|
56
|
+
* The plugin always derives `pages` from {@link pages}; caller-provided `pages`, `subPackages`, and `subpackages`
|
|
57
|
+
* values are discarded because the build pipeline owns page order and generated package placement.
|
|
58
|
+
*/
|
|
59
|
+
appJson: VptJsonObject
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* WeChat DevTools project configuration written to `project.config.json` without merging.
|
|
63
|
+
*
|
|
64
|
+
* This option is required so one configuration shape can be shared between targets, but it is only emitted for a
|
|
65
|
+
* `wx` build and is ignored for `h5`.
|
|
66
|
+
*/
|
|
67
|
+
projectConfigJson: VptJsonObject
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Local WeChat DevTools overrides written to `project.private.config.json` without merging.
|
|
71
|
+
*
|
|
72
|
+
* The file is emitted only when this value is provided for a `wx` build. It is ignored for `h5`.
|
|
73
|
+
*/
|
|
74
|
+
projectPrivateConfigJson?: VptJsonObject
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* WeChat Mini Program indexing rules written to `sitemap.json` without merging.
|
|
78
|
+
*
|
|
79
|
+
* The file is emitted only when this value is provided for a `wx` build. It is ignored for `h5`.
|
|
80
|
+
*/
|
|
81
|
+
sitemapJson?: VptJsonObject
|
|
24
82
|
}
|
package/src/runtime/h5/app.ts
CHANGED
|
@@ -8,16 +8,16 @@ import ReactDOM from 'react-dom/client'
|
|
|
8
8
|
// @ts-expect-error: The H5 build resolves this private App component.
|
|
9
9
|
import AppComponent from '\0vpt:app-component'
|
|
10
10
|
|
|
11
|
-
declare const
|
|
12
|
-
declare const
|
|
11
|
+
declare const __VPT_H5_APP_CONFIG__: SpaRouterConfig
|
|
12
|
+
declare const __VPT_H5_ROUTES__: Route[]
|
|
13
13
|
|
|
14
14
|
const browserWindow = window as unknown as Window &
|
|
15
15
|
typeof window & {
|
|
16
16
|
__taroAppConfig: SpaRouterConfig
|
|
17
17
|
}
|
|
18
|
-
const config =
|
|
18
|
+
const config = __VPT_H5_APP_CONFIG__
|
|
19
19
|
browserWindow.__taroAppConfig = config
|
|
20
|
-
config.routes =
|
|
20
|
+
config.routes = __VPT_H5_ROUTES__
|
|
21
21
|
const app = createReactApp(AppComponent, React, ReactDOM, config)
|
|
22
22
|
const history = createHashHistory({ window: browserWindow })
|
|
23
23
|
handleAppMount(config, history)
|
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
import '../systemjs/system-core.js'
|
|
3
3
|
import { transport } from './transport.ts'
|
|
4
4
|
|
|
5
|
-
declare const
|
|
5
|
+
declare const __VPT_APP_CONFIG__: Record<string, unknown>
|
|
6
6
|
|
|
7
7
|
/** Shares one App configuration object between the specialized bootstrap and App capsule. */
|
|
8
|
-
export const appConfig =
|
|
8
|
+
export const appConfig = __VPT_APP_CONFIG__
|
|
9
9
|
|
|
10
10
|
// WX has no modulepreload transport. Genuine application import() boundaries retain System.import() and may load
|
|
11
11
|
// asynchronous subpackage or top-level-await graphs through this identity wrapper.
|
|
@@ -2,9 +2,7 @@
|
|
|
2
2
|
// amphibious boundary that publishes native namespaces to SystemJS without re-evaluating their module bodies.
|
|
3
3
|
|
|
4
4
|
/** Materialized from the preliminary output graph before Rolldown finalizes content hashes. */
|
|
5
|
-
declare const
|
|
6
|
-
moduleId: string
|
|
7
|
-
) => System.Registration | PromiseLike<System.Registration>
|
|
5
|
+
declare const __VPT_TRANSPORT__: (moduleId: string) => System.Registration | PromiseLike<System.Registration>
|
|
8
6
|
|
|
9
7
|
/** Dispatches to one generated literal require and bridges amphibious CommonJS namespaces inline. */
|
|
10
|
-
export const transport =
|
|
8
|
+
export const transport = __VPT_TRANSPORT__
|
|
@@ -5,14 +5,9 @@ import './app.ts'
|
|
|
5
5
|
import PageComponent from '\0vpt:page-component'
|
|
6
6
|
import { createPageConfig } from './taro-runtime.ts'
|
|
7
7
|
|
|
8
|
-
declare const
|
|
9
|
-
declare const
|
|
8
|
+
declare const __VPT_PAGE_PATH__: string
|
|
9
|
+
declare const __VPT_PAGE_CONFIG__: Record<string, unknown>
|
|
10
10
|
|
|
11
|
-
const config = createPageConfig(
|
|
12
|
-
PageComponent,
|
|
13
|
-
__VITE_PLUGIN_TARO_PAGE_PATH__,
|
|
14
|
-
{ root: { cn: [] } },
|
|
15
|
-
__VITE_PLUGIN_TARO_PAGE_CONFIG__
|
|
16
|
-
)
|
|
11
|
+
const config = createPageConfig(PageComponent, __VPT_PAGE_PATH__, { root: { cn: [] } }, __VPT_PAGE_CONFIG__)
|
|
17
12
|
|
|
18
13
|
export default config
|
package/src/vite.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { default } from './node/
|
|
2
|
-
export type {
|
|
1
|
+
export { default } from './node/vpt.ts'
|
|
2
|
+
export type { VptJsonObject, VptOptions, VptPageOption, VptTarget } from './options.ts'
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
import type { Rolldown } from 'vite';
|
|
2
|
-
import { type ModuleGraph } from './plan.ts';
|
|
3
|
-
/** Native app.json declaration for one generated code-only subpackage. */
|
|
4
|
-
export type GeneratedSubpackage = {
|
|
5
|
-
/** Stable native alias derived from the generated root hash. */
|
|
6
|
-
name: string;
|
|
7
|
-
/** Physical directory containing this subpackage's emitted capsules. */
|
|
8
|
-
root: string;
|
|
9
|
-
/** Marks this as a code-only subpackage with no native Page routes. */
|
|
10
|
-
pages: readonly [];
|
|
11
|
-
};
|
|
12
|
-
/**
|
|
13
|
-
* Creates the stateful adapter between graph planning and Rolldown's output lifecycle:
|
|
14
|
-
*
|
|
15
|
-
* - renderStart analyzes transformed modules before chunking.
|
|
16
|
-
* - codeSplitting prevents modules assigned to different packages from being merged.
|
|
17
|
-
* - filename callbacks materialize planned subpackage roots.
|
|
18
|
-
* - renderChunk derives native loading mode from those physical paths.
|
|
19
|
-
* - generateBundle reconciles the plan with chunks that survived tree shaking.
|
|
20
|
-
*/
|
|
21
|
-
export declare function createPlacer(): {
|
|
22
|
-
/** Assigns every transformed module to main or one generated, size-bounded subpackage. */
|
|
23
|
-
analyze(graph: ModuleGraph): void;
|
|
24
|
-
/**
|
|
25
|
-
* Complete Rolldown fragment required to preserve package placement and native entry semantics.
|
|
26
|
-
*
|
|
27
|
-
* ```text
|
|
28
|
-
* native App/Page/Component shell entry
|
|
29
|
-
* └─ static import / runtime importSync() ─▶ explicit capsule entry + static closure [main, no TLA]
|
|
30
|
-
* └─ System.import() ─▶ lazy-a [package A, TLA allowed]
|
|
31
|
-
* └─ static import ─▶ lazy-b [package B]
|
|
32
|
-
*
|
|
33
|
-
* name() assigns lazy-a and lazy-b to their planned package groups
|
|
34
|
-
* includeDependenciesRecursively false: does not pull lazy-b back into package A
|
|
35
|
-
* preserveEntrySignatures allows cross-chunk bindings without weakening native entry exports
|
|
36
|
-
*
|
|
37
|
-
* package A capsule
|
|
38
|
-
* └─ SystemJS dependency ─▶ package B capsule
|
|
39
|
-
* ▲
|
|
40
|
-
* └─ main transport obtains registration with require.async()
|
|
41
|
-
* ```
|
|
42
|
-
*
|
|
43
|
-
* Explicit entries preserve the shell/capsule rendering boundary while their static edge executes synchronously
|
|
44
|
-
* from main. Once a dynamic boundary is crossed, physical fetches may be asynchronous and modules may use
|
|
45
|
-
* top-level await. SystemJS still links that complete static lazy graph before execution, even across packages.
|
|
46
|
-
*/
|
|
47
|
-
rolldownOptions: {
|
|
48
|
-
output: {
|
|
49
|
-
/**
|
|
50
|
-
* Gives every generated subpackage a distinct Rolldown chunk group. Recursive dependency capture must
|
|
51
|
-
* stay disabled: lazy static dependencies may belong to other subpackages and SystemJS links them
|
|
52
|
-
* asynchronously.
|
|
53
|
-
*/
|
|
54
|
-
codeSplitting: {
|
|
55
|
-
groups: {
|
|
56
|
-
name(moduleId: string): string | null;
|
|
57
|
-
includeDependenciesRecursively: boolean;
|
|
58
|
-
}[];
|
|
59
|
-
};
|
|
60
|
-
/** Preserves exact native shell paths while hashing transport and explicit capsule entries. */
|
|
61
|
-
entryFileNames(chunk: Rolldown.PreRenderedChunk): string;
|
|
62
|
-
/** Converts the planned owner into its physical main or generated subpackage filename template. */
|
|
63
|
-
chunkFileNames(chunk: Rolldown.PreRenderedChunk): string;
|
|
64
|
-
assetFileNames: string;
|
|
65
|
-
};
|
|
66
|
-
preserveEntrySignatures: 'allow-extension';
|
|
67
|
-
};
|
|
68
|
-
/**
|
|
69
|
-
* Selects loading mode from physical output rather than graph intent. Transport executes in main, so main files
|
|
70
|
-
* use require() and every generated subpackage file uses require.async().
|
|
71
|
-
*/
|
|
72
|
-
getLoadMode(chunk: Rolldown.RenderedChunk): 'sync' | 'async';
|
|
73
|
-
/**
|
|
74
|
-
* Reconciles planned ownership with final chunks through module IDs. Tree-shaken subpackages disappear naturally,
|
|
75
|
-
* while roots are deduplicated and sorted before becoming deterministic app.json declarations.
|
|
76
|
-
*/
|
|
77
|
-
getSubpackages(bundle: Rolldown.OutputBundle): GeneratedSubpackage[];
|
|
78
|
-
};
|
|
@@ -1,158 +0,0 @@
|
|
|
1
|
-
import path from 'node:path';
|
|
2
|
-
import { getWxExecutionKind, isTransportModule } from '../module.js';
|
|
3
|
-
import { createPlacementPlan, getSubpackageName, isGeneratedSubpackageFile, mainPackage } from './plan.js';
|
|
4
|
-
/**
|
|
5
|
-
* Creates the stateful adapter between graph planning and Rolldown's output lifecycle:
|
|
6
|
-
*
|
|
7
|
-
* - renderStart analyzes transformed modules before chunking.
|
|
8
|
-
* - codeSplitting prevents modules assigned to different packages from being merged.
|
|
9
|
-
* - filename callbacks materialize planned subpackage roots.
|
|
10
|
-
* - renderChunk derives native loading mode from those physical paths.
|
|
11
|
-
* - generateBundle reconciles the plan with chunks that survived tree shaking.
|
|
12
|
-
*/
|
|
13
|
-
export function createPlacer() {
|
|
14
|
-
// Filename and output callbacks run after analyze and read this immutable plan through their shared closure.
|
|
15
|
-
let plan = new Map();
|
|
16
|
-
/**
|
|
17
|
-
* Reduces module ownership to one package for filename generation. Unknown Rolldown-generated modules default to
|
|
18
|
-
* main, empty chunks default to main, and a chunk containing multiple known owners is rejected before paths diverge.
|
|
19
|
-
*/
|
|
20
|
-
function getChunkLocation(chunk) {
|
|
21
|
-
let location;
|
|
22
|
-
for (const moduleId of chunk.moduleIds) {
|
|
23
|
-
const moduleLocation = plan.get(moduleId) ?? mainPackage;
|
|
24
|
-
if (!location) {
|
|
25
|
-
location = moduleLocation;
|
|
26
|
-
continue;
|
|
27
|
-
}
|
|
28
|
-
if (!hasSameLocation(location, moduleLocation)) {
|
|
29
|
-
throw new Error(`wx chunk mixes package owners: ${chunk.moduleIds.join(', ')}`);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
return location ?? mainPackage;
|
|
33
|
-
}
|
|
34
|
-
return {
|
|
35
|
-
/** Assigns every transformed module to main or one generated, size-bounded subpackage. */
|
|
36
|
-
analyze(graph) {
|
|
37
|
-
plan = createPlacementPlan(graph);
|
|
38
|
-
},
|
|
39
|
-
/**
|
|
40
|
-
* Complete Rolldown fragment required to preserve package placement and native entry semantics.
|
|
41
|
-
*
|
|
42
|
-
* ```text
|
|
43
|
-
* native App/Page/Component shell entry
|
|
44
|
-
* └─ static import / runtime importSync() ─▶ explicit capsule entry + static closure [main, no TLA]
|
|
45
|
-
* └─ System.import() ─▶ lazy-a [package A, TLA allowed]
|
|
46
|
-
* └─ static import ─▶ lazy-b [package B]
|
|
47
|
-
*
|
|
48
|
-
* name() assigns lazy-a and lazy-b to their planned package groups
|
|
49
|
-
* includeDependenciesRecursively false: does not pull lazy-b back into package A
|
|
50
|
-
* preserveEntrySignatures allows cross-chunk bindings without weakening native entry exports
|
|
51
|
-
*
|
|
52
|
-
* package A capsule
|
|
53
|
-
* └─ SystemJS dependency ─▶ package B capsule
|
|
54
|
-
* ▲
|
|
55
|
-
* └─ main transport obtains registration with require.async()
|
|
56
|
-
* ```
|
|
57
|
-
*
|
|
58
|
-
* Explicit entries preserve the shell/capsule rendering boundary while their static edge executes synchronously
|
|
59
|
-
* from main. Once a dynamic boundary is crossed, physical fetches may be asynchronous and modules may use
|
|
60
|
-
* top-level await. SystemJS still links that complete static lazy graph before execution, even across packages.
|
|
61
|
-
*/
|
|
62
|
-
rolldownOptions: {
|
|
63
|
-
output: {
|
|
64
|
-
/**
|
|
65
|
-
* Gives every generated subpackage a distinct Rolldown chunk group. Recursive dependency capture must
|
|
66
|
-
* stay disabled: lazy static dependencies may belong to other subpackages and SystemJS links them
|
|
67
|
-
* asynchronously.
|
|
68
|
-
*/
|
|
69
|
-
codeSplitting: {
|
|
70
|
-
groups: [
|
|
71
|
-
{
|
|
72
|
-
name(moduleId) {
|
|
73
|
-
const location = plan.get(moduleId);
|
|
74
|
-
return location?.kind === 'subpackage' ? getSubpackageName(location.root) : null;
|
|
75
|
-
},
|
|
76
|
-
// Do not let Rolldown pull a lazy group's static closure into one chunk. Past the nested dynamic
|
|
77
|
-
// boundary, transport may obtain registrations from several packages asynchronously before
|
|
78
|
-
// SystemJS links and executes the original graph, including cycles and top-level await.
|
|
79
|
-
includeDependenciesRecursively: false
|
|
80
|
-
}
|
|
81
|
-
]
|
|
82
|
-
},
|
|
83
|
-
// strictExecutionOrder deliberately has no plugin default. When an application enables it through normal
|
|
84
|
-
// Rolldown output options, the generated helper runtime becomes amphibious: CommonJS evaluates it once and
|
|
85
|
-
// transport publishes that cached namespace to SystemJS.
|
|
86
|
-
/** Preserves exact native shell paths while hashing transport and explicit capsule entries. */
|
|
87
|
-
entryFileNames(chunk) {
|
|
88
|
-
return getWxExecutionKind(chunk) === 'native' && !isTransportModule(chunk)
|
|
89
|
-
? '[name]'
|
|
90
|
-
: 'assets/[name]-[hash].js';
|
|
91
|
-
},
|
|
92
|
-
/** Converts the planned owner into its physical main or generated subpackage filename template. */
|
|
93
|
-
chunkFileNames(chunk) {
|
|
94
|
-
const location = getChunkLocation(chunk);
|
|
95
|
-
if (location.kind === 'main') {
|
|
96
|
-
return 'assets/[name]-[hash].js';
|
|
97
|
-
}
|
|
98
|
-
// The package group replaces Rolldown's [name], so recover the first bundled source file's name from
|
|
99
|
-
// the final chunk module list instead of leaking the generated package hash into the filename.
|
|
100
|
-
return `${location.root}/assets/${getFirstModuleName(chunk)}-[hash].js`;
|
|
101
|
-
},
|
|
102
|
-
// Keep generic assets independent of native output identities assigned after bundling.
|
|
103
|
-
assetFileNames: 'assets/[name]-[hash][extname]'
|
|
104
|
-
},
|
|
105
|
-
// Rolldown rejects strict entry signatures when code-splitting groups disable recursive dependency capture.
|
|
106
|
-
// allow-extension retains required native-entry exports while permitting the extra cross-chunk bindings used
|
|
107
|
-
// to split lazy static closures across physical packages.
|
|
108
|
-
preserveEntrySignatures: 'allow-extension'
|
|
109
|
-
},
|
|
110
|
-
/**
|
|
111
|
-
* Selects loading mode from physical output rather than graph intent. Transport executes in main, so main files
|
|
112
|
-
* use require() and every generated subpackage file uses require.async().
|
|
113
|
-
*/
|
|
114
|
-
getLoadMode(chunk) {
|
|
115
|
-
return isGeneratedSubpackageFile(chunk.fileName) ? 'async' : 'sync';
|
|
116
|
-
},
|
|
117
|
-
/**
|
|
118
|
-
* Reconciles planned ownership with final chunks through module IDs. Tree-shaken subpackages disappear naturally,
|
|
119
|
-
* while roots are deduplicated and sorted before becoming deterministic app.json declarations.
|
|
120
|
-
*/
|
|
121
|
-
getSubpackages(bundle) {
|
|
122
|
-
const emittedSubpackageRoots = new Set();
|
|
123
|
-
for (const output of Object.values(bundle)) {
|
|
124
|
-
if (output.type !== 'chunk') {
|
|
125
|
-
continue;
|
|
126
|
-
}
|
|
127
|
-
for (const moduleId of output.moduleIds) {
|
|
128
|
-
const location = plan.get(moduleId);
|
|
129
|
-
if (location?.kind === 'subpackage') {
|
|
130
|
-
emittedSubpackageRoots.add(location.root);
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
return [...emittedSubpackageRoots].sort().map((root) => ({
|
|
135
|
-
name: getSubpackageName(root),
|
|
136
|
-
root,
|
|
137
|
-
pages: []
|
|
138
|
-
}));
|
|
139
|
-
}
|
|
140
|
-
};
|
|
141
|
-
}
|
|
142
|
-
/** Uses the first bundled source filename as the readable identity of a generated subpackage chunk. */
|
|
143
|
-
function getFirstModuleName(chunk) {
|
|
144
|
-
const firstModuleId = chunk.moduleIds[0];
|
|
145
|
-
if (!firstModuleId) {
|
|
146
|
-
throw new Error('wx subpackage chunk has no source modules');
|
|
147
|
-
}
|
|
148
|
-
const normalizedId = firstModuleId.replaceAll('\\', '/');
|
|
149
|
-
const suffixIndex = normalizedId.search(/[?#]/);
|
|
150
|
-
const cleanId = suffixIndex === -1 ? normalizedId : normalizedId.slice(0, suffixIndex);
|
|
151
|
-
const fileName = path.posix.basename(cleanId);
|
|
152
|
-
const extension = path.posix.extname(fileName);
|
|
153
|
-
return extension ? fileName.slice(0, -extension.length) : fileName;
|
|
154
|
-
}
|
|
155
|
-
/** Compares main by discriminant and generated subpackages by their unique physical root. */
|
|
156
|
-
function hasSameLocation(left, right) {
|
|
157
|
-
return left.kind === 'main' ? right.kind === 'main' : right.kind === 'subpackage' && left.root === right.root;
|
|
158
|
-
}
|