vite-plugin-taro 0.6.11 → 0.6.13

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.
@@ -11,10 +11,11 @@ const taroComponentsModulePath = packageRequire.resolve('@tarojs/plugin-platform
11
11
  export function createTemplateAssets({ bundle, options, subpackages, nativeComponents, isProduction }) {
12
12
  const templateBuilder = createTemplateBuilder();
13
13
  const componentConfig = collectTemplateComponentConfig(bundle, nativeComponents);
14
- const recursiveComponentJson = createRecursiveComponentJson();
14
+ const nativeComponentConfig = createNativeComponentConfig(nativeComponents);
15
+ const recursiveComponentJson = createRecursiveComponentJson(nativeComponentConfig);
15
16
  const jsonAsset = (fileName, value) => createJsonAsset(fileName, value, isProduction);
16
17
  return [
17
- jsonAsset('app.json', createAppJson({ options, subpackages, nativeComponents })),
18
+ jsonAsset('app.json', createAppJson({ options, subpackages })),
18
19
  createAsset('base.wxml', templateBuilder.buildBaseTemplate(componentConfig)),
19
20
  createAsset('utils.wxs', templateBuilder.buildXScript()),
20
21
  createAsset('comp.wxml', templateBuilder.buildBaseComponentTemplate('.wxml')),
@@ -22,7 +23,7 @@ export function createTemplateAssets({ bundle, options, subpackages, nativeCompo
22
23
  createAsset('custom-wrapper.wxml', templateBuilder.buildCustomComponentTemplate('.wxml')),
23
24
  jsonAsset('custom-wrapper.json', recursiveComponentJson),
24
25
  ...options.pages.flatMap((page) => [
25
- jsonAsset(`${page.path}.json`, createPageJson(page)),
26
+ jsonAsset(`${page.path}.json`, createPageJson(page, nativeComponentConfig)),
26
27
  createAsset(`${page.path}.wxml`, templateBuilder.buildPageTemplate(toRootRelativePath(page.path, 'base.wxml'), {
27
28
  content: page.config,
28
29
  path: page.path
@@ -65,8 +66,9 @@ export function createTemplateAssets({ bundle, options, subpackages, nativeCompo
65
66
  * to page as that component's default slot.
66
67
  *
67
68
  * utils.wxs remains Taro's normal compact-node dispatcher. comp.wxml and custom-wrapper.wxml retain Taro's generic compact
68
- * rendering contracts; their JSON companions register only recursive boundaries, while runtime configs retain standard
69
- * event dispatch. CustomWrapper keeps Taro's Page-local ownership model and is not made slot-transparent for App wrapping.
69
+ * rendering contracts; their JSON companions register recursive boundaries and native components, while runtime configs
70
+ * retain standard event dispatch. CustomWrapper keeps Taro's Page-local ownership model and is not made slot-transparent
71
+ * for App wrapping.
70
72
  * There is one shared template namespace, no Page-specific base file, no App/Page mode property, and no Page object threaded
71
73
  * through App template data.
72
74
  *
@@ -287,57 +289,59 @@ function findBundleModule(bundle, resolvedId) {
287
289
  function toDashed(value) {
288
290
  return value.replace(/([a-z0-9])([A-Z])/g, '$1-$2').toLowerCase();
289
291
  }
290
- /** Creates App JSON with globally inherited native registrations and generated subpackages. */
291
- function createAppJson({ options, subpackages, nativeComponents }) {
292
- const appConfig = createAppConfig(options);
293
- const nativeUsingComponents = nativeComponents.map(({ name, componentPath }) => [name, componentPath]);
292
+ /** Creates App JSON with generated subpackages. */
293
+ function createAppJson({ options, subpackages }) {
294
+ return {
295
+ ...createAppConfig(options),
296
+ ...(subpackages.length > 0 ? { subPackages: subpackages } : {})
297
+ };
298
+ }
299
+ /** Creates native registrations for every WXML rendering scope that can instantiate their templates. */
300
+ function createNativeComponentConfig(nativeComponents) {
294
301
  // Cross-package components require a placeholder while WeChat downloads their generated subpackage. Paths are
295
302
  // root-absolute, so remove the leading slash before testing the output-relative subpackage prefix.
296
303
  // https://developers.weixin.qq.com/miniprogram/dev/framework/subpackages/async.html
297
304
  // https://developers.weixin.qq.com/miniprogram/dev/framework/custom-component/placeholder.html
298
- const componentPlaceholders = nativeComponents.flatMap(({ name, componentPath }) => isGeneratedSubpackageFile(componentPath.slice(1)) ? [[name, 'view']] : []);
299
305
  return {
300
- ...appConfig,
301
- ...(nativeUsingComponents.length > 0
302
- ? {
303
- usingComponents: {
304
- ...(isJsonObject(appConfig.usingComponents) ? appConfig.usingComponents : {}),
305
- ...Object.fromEntries(nativeUsingComponents)
306
- }
307
- }
308
- : {}),
309
- ...(componentPlaceholders.length > 0
310
- ? {
311
- componentPlaceholder: {
312
- ...(isJsonObject(appConfig.componentPlaceholder) ? appConfig.componentPlaceholder : {}),
313
- ...Object.fromEntries(componentPlaceholders)
314
- }
315
- }
316
- : {}),
317
- ...(subpackages.length > 0 ? { subPackages: subpackages } : {})
306
+ usingComponents: Object.fromEntries(nativeComponents.map(({ name, componentPath }) => [name, componentPath])),
307
+ componentPlaceholder: Object.fromEntries(nativeComponents.flatMap(({ name, componentPath }) => isGeneratedSubpackageFile(componentPath.slice(1)) ? [[name, 'view']] : []))
318
308
  };
319
309
  }
320
- /** Preserves configured Page JSON and registers the generated recursive component entries. */
321
- function createPageJson(page) {
310
+ /** Preserves configured Page JSON and registers its recursive and native component entries. */
311
+ function createPageJson(page, nativeComponentConfig) {
322
312
  const usingComponents = isJsonObject(page.config.usingComponents) ? page.config.usingComponents : {};
313
+ const componentPlaceholder = isJsonObject(page.config.componentPlaceholder) ? page.config.componentPlaceholder : {};
314
+ const hasNativeComponentPlaceholder = Object.keys(nativeComponentConfig.componentPlaceholder).length > 0;
323
315
  return {
324
316
  ...page.config,
325
317
  usingComponents: {
326
318
  ...usingComponents,
319
+ ...nativeComponentConfig.usingComponents,
327
320
  comp: toRootRelativePath(page.path, 'comp'),
328
321
  [customWrapperName]: toRootRelativePath(page.path, customWrapperName)
329
- }
322
+ },
323
+ ...(hasNativeComponentPlaceholder
324
+ ? {
325
+ componentPlaceholder: {
326
+ ...componentPlaceholder,
327
+ ...nativeComponentConfig.componentPlaceholder
328
+ }
329
+ }
330
+ : {})
330
331
  };
331
332
  }
332
333
  /** Creates the shared recursive component configuration used by comp and CustomWrapper. */
333
- function createRecursiveComponentJson() {
334
+ function createRecursiveComponentJson(nativeComponentConfig) {
335
+ const hasNativeComponentPlaceholder = Object.keys(nativeComponentConfig.componentPlaceholder).length > 0;
334
336
  return {
335
337
  component: true,
336
338
  styleIsolation: 'apply-shared',
337
339
  usingComponents: {
340
+ ...nativeComponentConfig.usingComponents,
338
341
  comp: './comp',
339
342
  [customWrapperName]: `./${customWrapperName}`
340
- }
343
+ },
344
+ ...(hasNativeComponentPlaceholder ? { componentPlaceholder: nativeComponentConfig.componentPlaceholder } : {})
341
345
  };
342
346
  }
343
347
  /** Tests whether a configured JSON value can be merged as an object. */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite-plugin-taro",
3
- "version": "0.6.11",
3
+ "version": "0.6.13",
4
4
  "author": "sep2",
5
5
  "description": "Vite 8 plugin for building one React/Taro codebase for WeChat Mini Program and H5 targets.",
6
6
  "type": "module",
@@ -75,9 +75,9 @@
75
75
  "rxjs": "^7.8.2",
76
76
  "tailwindcss": "^4.3.3",
77
77
  "weapp-tailwindcss": "^5.2.11",
78
- "@tarojs/plugin-framework-react": "npm:vite-plugin-taro-plugin-framework-react@0.6.11",
79
- "@tarojs/runtime": "npm:vite-plugin-taro-runtime@0.6.11",
80
- "@tarojs/react": "npm:vite-plugin-taro-react@0.6.11"
78
+ "@tarojs/plugin-framework-react": "npm:vite-plugin-taro-plugin-framework-react@0.6.13",
79
+ "@tarojs/react": "npm:vite-plugin-taro-react@0.6.13",
80
+ "@tarojs/runtime": "npm:vite-plugin-taro-runtime@0.6.13"
81
81
  },
82
82
  "peerDependencies": {
83
83
  "react": "^19.0.0",
@@ -21,6 +21,11 @@ type NativeComponentRegistration = {
21
21
  fields: readonly string[]
22
22
  }
23
23
 
24
+ type NativeComponentConfig = {
25
+ usingComponents: Record<string, string>
26
+ componentPlaceholder: Record<string, string>
27
+ }
28
+
24
29
  const customWrapperName = 'custom-wrapper'
25
30
  const taroComponentsModulePath = packageRequire.resolve('@tarojs/plugin-platform-weapp/dist/components-react')
26
31
 
@@ -40,12 +45,13 @@ export function createTemplateAssets({
40
45
  }): Rolldown.EmittedAsset[] {
41
46
  const templateBuilder = createTemplateBuilder()
42
47
  const componentConfig = collectTemplateComponentConfig(bundle, nativeComponents)
43
- const recursiveComponentJson = createRecursiveComponentJson()
48
+ const nativeComponentConfig = createNativeComponentConfig(nativeComponents)
49
+ const recursiveComponentJson = createRecursiveComponentJson(nativeComponentConfig)
44
50
 
45
51
  const jsonAsset = (fileName: string, value: VptJsonObject) => createJsonAsset(fileName, value, isProduction)
46
52
 
47
53
  return [
48
- jsonAsset('app.json', createAppJson({ options, subpackages, nativeComponents })),
54
+ jsonAsset('app.json', createAppJson({ options, subpackages })),
49
55
 
50
56
  createAsset('base.wxml', templateBuilder.buildBaseTemplate(componentConfig)),
51
57
  createAsset('utils.wxs', templateBuilder.buildXScript()),
@@ -57,7 +63,7 @@ export function createTemplateAssets({
57
63
  jsonAsset('custom-wrapper.json', recursiveComponentJson),
58
64
 
59
65
  ...options.pages.flatMap((page) => [
60
- jsonAsset(`${page.path}.json`, createPageJson(page)),
66
+ jsonAsset(`${page.path}.json`, createPageJson(page, nativeComponentConfig)),
61
67
  createAsset(
62
68
  `${page.path}.wxml`,
63
69
  templateBuilder.buildPageTemplate(toRootRelativePath(page.path, 'base.wxml'), {
@@ -105,8 +111,9 @@ export function createTemplateAssets({
105
111
  * to page as that component's default slot.
106
112
  *
107
113
  * utils.wxs remains Taro's normal compact-node dispatcher. comp.wxml and custom-wrapper.wxml retain Taro's generic compact
108
- * rendering contracts; their JSON companions register only recursive boundaries, while runtime configs retain standard
109
- * event dispatch. CustomWrapper keeps Taro's Page-local ownership model and is not made slot-transparent for App wrapping.
114
+ * rendering contracts; their JSON companions register recursive boundaries and native components, while runtime configs
115
+ * retain standard event dispatch. CustomWrapper keeps Taro's Page-local ownership model and is not made slot-transparent
116
+ * for App wrapping.
110
117
  * There is one shared template namespace, no Page-specific base file, no App/Page mode property, and no Page object threaded
111
118
  * through App template data.
112
119
  *
@@ -353,72 +360,75 @@ function toDashed(value: string): string {
353
360
  return value.replace(/([a-z0-9])([A-Z])/g, '$1-$2').toLowerCase()
354
361
  }
355
362
 
356
- /** Creates App JSON with globally inherited native registrations and generated subpackages. */
363
+ /** Creates App JSON with generated subpackages. */
357
364
  function createAppJson({
358
365
  options,
359
- subpackages,
360
- nativeComponents
366
+ subpackages
361
367
  }: {
362
368
  options: VptOptions
363
369
  subpackages: readonly GeneratedSubpackage[]
364
- nativeComponents: readonly NativeComponentRegistration[]
365
370
  }): VptJsonObject {
366
- const appConfig = createAppConfig(options)
367
- const nativeUsingComponents = nativeComponents.map(({ name, componentPath }) => [name, componentPath])
371
+ return {
372
+ ...createAppConfig(options),
373
+ ...(subpackages.length > 0 ? { subPackages: subpackages } : {})
374
+ }
375
+ }
368
376
 
377
+ /** Creates native registrations for every WXML rendering scope that can instantiate their templates. */
378
+ function createNativeComponentConfig(nativeComponents: readonly NativeComponentRegistration[]): NativeComponentConfig {
369
379
  // Cross-package components require a placeholder while WeChat downloads their generated subpackage. Paths are
370
380
  // root-absolute, so remove the leading slash before testing the output-relative subpackage prefix.
371
381
  // https://developers.weixin.qq.com/miniprogram/dev/framework/subpackages/async.html
372
382
  // https://developers.weixin.qq.com/miniprogram/dev/framework/custom-component/placeholder.html
373
- const componentPlaceholders = nativeComponents.flatMap(({ name, componentPath }) =>
374
- isGeneratedSubpackageFile(componentPath.slice(1)) ? ([[name, 'view']] as const) : []
375
- )
376
383
 
377
384
  return {
378
- ...appConfig,
379
- ...(nativeUsingComponents.length > 0
380
- ? {
381
- usingComponents: {
382
- ...(isJsonObject(appConfig.usingComponents) ? appConfig.usingComponents : {}),
383
- ...Object.fromEntries(nativeUsingComponents)
384
- }
385
- }
386
- : {}),
387
- ...(componentPlaceholders.length > 0
388
- ? {
389
- componentPlaceholder: {
390
- ...(isJsonObject(appConfig.componentPlaceholder) ? appConfig.componentPlaceholder : {}),
391
- ...Object.fromEntries(componentPlaceholders)
392
- }
393
- }
394
- : {}),
395
- ...(subpackages.length > 0 ? { subPackages: subpackages } : {})
385
+ usingComponents: Object.fromEntries(nativeComponents.map(({ name, componentPath }) => [name, componentPath])),
386
+ componentPlaceholder: Object.fromEntries(
387
+ nativeComponents.flatMap(({ name, componentPath }) =>
388
+ isGeneratedSubpackageFile(componentPath.slice(1)) ? ([[name, 'view']] as const) : []
389
+ )
390
+ )
396
391
  }
397
392
  }
398
393
 
399
- /** Preserves configured Page JSON and registers the generated recursive component entries. */
400
- function createPageJson(page: VptPageOption): VptJsonObject {
394
+ /** Preserves configured Page JSON and registers its recursive and native component entries. */
395
+ function createPageJson(page: VptPageOption, nativeComponentConfig: NativeComponentConfig): VptJsonObject {
401
396
  const usingComponents = isJsonObject(page.config.usingComponents) ? page.config.usingComponents : {}
397
+ const componentPlaceholder = isJsonObject(page.config.componentPlaceholder) ? page.config.componentPlaceholder : {}
398
+ const hasNativeComponentPlaceholder = Object.keys(nativeComponentConfig.componentPlaceholder).length > 0
402
399
 
403
400
  return {
404
401
  ...page.config,
405
402
  usingComponents: {
406
403
  ...usingComponents,
404
+ ...nativeComponentConfig.usingComponents,
407
405
  comp: toRootRelativePath(page.path, 'comp'),
408
406
  [customWrapperName]: toRootRelativePath(page.path, customWrapperName)
409
- }
407
+ },
408
+ ...(hasNativeComponentPlaceholder
409
+ ? {
410
+ componentPlaceholder: {
411
+ ...componentPlaceholder,
412
+ ...nativeComponentConfig.componentPlaceholder
413
+ }
414
+ }
415
+ : {})
410
416
  }
411
417
  }
412
418
 
413
419
  /** Creates the shared recursive component configuration used by comp and CustomWrapper. */
414
- function createRecursiveComponentJson(): VptJsonObject {
420
+ function createRecursiveComponentJson(nativeComponentConfig: NativeComponentConfig): VptJsonObject {
421
+ const hasNativeComponentPlaceholder = Object.keys(nativeComponentConfig.componentPlaceholder).length > 0
422
+
415
423
  return {
416
424
  component: true,
417
425
  styleIsolation: 'apply-shared',
418
426
  usingComponents: {
427
+ ...nativeComponentConfig.usingComponents,
419
428
  comp: './comp',
420
429
  [customWrapperName]: `./${customWrapperName}`
421
- }
430
+ },
431
+ ...(hasNativeComponentPlaceholder ? { componentPlaceholder: nativeComponentConfig.componentPlaceholder } : {})
422
432
  }
423
433
  }
424
434