vite-plugin-taro 0.6.7 → 0.6.11

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.
Files changed (36) hide show
  1. package/README.en.md +3 -0
  2. package/README.md +3 -0
  3. package/dist/node/plugins/wx/dev/dev-host.js +5 -0
  4. package/dist/node/plugins/wx/module/module.d.ts +6 -2
  5. package/dist/node/plugins/wx/module/module.js +12 -3
  6. package/dist/node/plugins/wx/output/files.d.ts +2 -1
  7. package/dist/node/plugins/wx/output/files.js +8 -4
  8. package/dist/node/plugins/wx/output/templates.d.ts +13 -3
  9. package/dist/node/plugins/wx/output/templates.js +107 -41
  10. package/dist/node/plugins/wx/plugins.js +1 -0
  11. package/dist/node/plugins/wx/resolve/resolver.js +2 -1
  12. package/dist/node/plugins/wx/styles/plugins.js +19 -12
  13. package/dist/runtime/wx/capsule/component.d.ts +2 -2
  14. package/dist/runtime/wx/capsule/component.js +3 -2
  15. package/dist/runtime/wx/capsule/taro-runtime.d.ts +1 -1
  16. package/dist/runtime/wx/capsule/taro-runtime.js +1 -1
  17. package/dist/runtime/wx/native/component.js +1 -1
  18. package/dist/runtime/wx/native/custom-wrapper.d.ts +1 -0
  19. package/dist/runtime/wx/native/custom-wrapper.js +3 -0
  20. package/dist/runtime/wx/systemjs/system-core.js +4 -4
  21. package/package.json +30 -5
  22. package/src/node/plugins/wx/dev/dev-host.ts +5 -0
  23. package/src/node/plugins/wx/module/module.ts +14 -3
  24. package/src/node/plugins/wx/output/files.ts +9 -3
  25. package/src/node/plugins/wx/output/templates.ts +151 -56
  26. package/src/node/plugins/wx/plugins.ts +1 -0
  27. package/src/node/plugins/wx/resolve/resolver.ts +3 -0
  28. package/src/node/plugins/wx/styles/plugins.ts +20 -13
  29. package/src/runtime/wx/capsule/component.ts +3 -2
  30. package/src/runtime/wx/capsule/taro-runtime.ts +1 -1
  31. package/src/runtime/wx/native/component.ts +1 -1
  32. package/src/runtime/wx/native/custom-wrapper.ts +4 -0
  33. package/src/runtime/wx/systemjs/system-core.js +4 -4
  34. package/dist/node/plugins/wx/output/json.d.ts +0 -14
  35. package/dist/node/plugins/wx/output/json.js +0 -72
  36. package/src/node/plugins/wx/output/json.ts +0 -109
@@ -1,109 +0,0 @@
1
- import type { Rolldown } from 'vite'
2
- import type { VptJsonObject, VptOptions, VptPageOption } from '../../../../options.ts'
3
- import { createAppConfig } from '../../../utils/project-config.ts'
4
- import { type GeneratedSubpackage, isGeneratedSubpackageFile } from '../placer/placement.ts'
5
- import { toRootRelativePath } from './relative-root.ts'
6
-
7
- /** Creates every configured native JSON asset. */
8
- export function createJsonAssets({
9
- options,
10
- subpackages,
11
- nativeComponents
12
- }: {
13
- options: VptOptions
14
- subpackages: readonly GeneratedSubpackage[]
15
- nativeComponents: readonly { name: string; componentPath: string }[]
16
- }): Rolldown.EmittedAsset[] {
17
- return [
18
- createJsonAsset(
19
- 'app.json',
20
- createAppJson({ options: options, subpackages: subpackages, nativeComponents: nativeComponents })
21
- ),
22
-
23
- ...options.pages.map((page) => createJsonAsset(`${page.path}.json`, createPageJson(page))),
24
-
25
- createJsonAsset('project.config.json', options.projectConfigJson),
26
-
27
- ...(options.projectPrivateConfigJson
28
- ? [createJsonAsset('project.private.config.json', options.projectPrivateConfigJson)]
29
- : []),
30
-
31
- ...(options.sitemapJson ? [createJsonAsset('sitemap.json', options.sitemapJson)] : [])
32
- ]
33
- }
34
-
35
- /** Creates App JSON with globally inherited native registrations and generated subpackages. */
36
- function createAppJson({
37
- options,
38
- subpackages,
39
- nativeComponents
40
- }: {
41
- options: VptOptions
42
- subpackages: readonly GeneratedSubpackage[]
43
- nativeComponents: readonly { name: string; componentPath: string }[]
44
- }): VptJsonObject {
45
- const appConfig = createAppConfig(options)
46
-
47
- const nativeUsingComponents = nativeComponents.map(({ name, componentPath }) => [name, componentPath])
48
-
49
- // Cross-package components require a placeholder while WeChat downloads their generated subpackage. Paths are
50
- // root-absolute, so remove the leading slash before testing the output-relative subpackage prefix.
51
- // https://developers.weixin.qq.com/miniprogram/dev/framework/subpackages/async.html
52
- // https://developers.weixin.qq.com/miniprogram/dev/framework/custom-component/placeholder.html
53
- const componentPlaceholders = nativeComponents.flatMap(({ name, componentPath }) =>
54
- isGeneratedSubpackageFile(componentPath.slice(1)) ? ([[name, 'view']] as const) : []
55
- )
56
-
57
- return {
58
- ...appConfig,
59
- ...(nativeUsingComponents.length > 0
60
- ? {
61
- usingComponents: {
62
- ...(isJsonObject(appConfig.usingComponents) ? appConfig.usingComponents : {}),
63
- ...Object.fromEntries(nativeUsingComponents)
64
- }
65
- }
66
- : {}),
67
- ...(componentPlaceholders.length > 0
68
- ? {
69
- componentPlaceholder: {
70
- ...(isJsonObject(appConfig.componentPlaceholder) ? appConfig.componentPlaceholder : {}),
71
- ...Object.fromEntries(componentPlaceholders)
72
- }
73
- }
74
- : {}),
75
- ...(subpackages.length > 0 ? { subPackages: subpackages } : {})
76
- }
77
- }
78
-
79
- /** Preserves configured Page JSON and registers only Taro's local recursive component entry. */
80
- function createPageJson(page: VptPageOption): VptJsonObject {
81
- const usingComponents = isJsonObject(page.config.usingComponents) ? page.config.usingComponents : {}
82
-
83
- return {
84
- ...page.config,
85
- usingComponents: {
86
- ...usingComponents,
87
- comp: toRootRelativePath(page.path, 'comp')
88
- }
89
- }
90
- }
91
-
92
- /** Tests whether a configured JSON value can be merged as an object. */
93
- function isJsonObject(value: unknown): value is VptJsonObject {
94
- return typeof value === 'object' && value !== null && !Array.isArray(value)
95
- }
96
-
97
- /** Serializes one native JSON object with stable formatting. */
98
- export function renderJson(value: VptJsonObject): string {
99
- return `${JSON.stringify(value, null, 4)}\n`
100
- }
101
-
102
- /** Creates one native JSON asset. */
103
- function createJsonAsset(fileName: string, value: VptJsonObject): Rolldown.EmittedAsset {
104
- return {
105
- type: 'asset',
106
- fileName,
107
- source: renderJson(value)
108
- }
109
- }