vite-plugin-taro 0.3.0 → 0.3.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.
@@ -7,7 +7,7 @@ type ProjectContext = Readonly<{
7
7
  pages: readonly VitePluginTaroPageOption[];
8
8
  appConfig: JsonObject;
9
9
  projectConfigJson: JsonObject;
10
- projectPrivateConfigJson: JsonObject;
10
+ projectPrivateConfigJson?: JsonObject;
11
11
  sitemapJson: JsonObject;
12
12
  }>;
13
13
  /** Owns the shared project, Vite lifecycle state, and cross-target services for one build. */
@@ -13,6 +13,7 @@ type WxAssetEmitter = {
13
13
  fileName: string;
14
14
  source: WxAssetSource;
15
15
  }): string;
16
+ warn(message: string): void;
16
17
  };
17
18
  export declare function emitWxCompanionAssets(emitter: WxAssetEmitter, bundle: WxBundle, context: BuildContext): void;
18
19
  export {};
@@ -7,6 +7,12 @@ const taroWxComponentsPath = packageRequire.resolve('@tarojs/plugin-platform-wea
7
7
  const templateBuilder = createWxTemplateBuilder();
8
8
  export function emitWxCompanionAssets(emitter, bundle, context) {
9
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
+ }
10
16
  emitter.emitFile({ type: 'asset', fileName: asset.fileName, source: asset.source });
11
17
  }
12
18
  }
@@ -23,7 +29,9 @@ function createWxCompanionAssets(bundle, context) {
23
29
  { fileName: 'comp.wxml', source: templateBuilder.buildBaseComponentTemplate('.wxml') },
24
30
  { fileName: 'comp.json', source: json(createWxComponentConfig()) },
25
31
  { fileName: 'project.config.json', source: json(createWxProjectConfig(context)) },
26
- { fileName: 'project.private.config.json', source: json(context.project.projectPrivateConfigJson) },
32
+ context.project.projectPrivateConfigJson
33
+ ? { fileName: 'project.private.config.json', source: json(context.project.projectPrivateConfigJson) }
34
+ : undefined,
27
35
  { fileName: 'sitemap.json', source: json(context.project.sitemapJson) },
28
36
  ...context.project.pages.flatMap((page) => [
29
37
  {
package/dist/options.d.ts CHANGED
@@ -16,6 +16,6 @@ export interface VitePluginTaroOptions {
16
16
  pages: VitePluginTaroPageOption[];
17
17
  appJson: JsonObject;
18
18
  projectConfigJson: JsonObject;
19
- projectPrivateConfigJson: JsonObject;
19
+ projectPrivateConfigJson?: JsonObject;
20
20
  sitemapJson: JsonObject;
21
21
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite-plugin-taro",
3
- "version": "0.3.0",
3
+ "version": "0.3.1",
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",
@@ -66,8 +66,8 @@
66
66
  "react-refresh": "^0.18.0",
67
67
  "tailwindcss": "^4.3.2",
68
68
  "weapp-tailwindcss": "^5.1.14",
69
- "@tarojs/plugin-framework-react": "npm:vite-plugin-taro-plugin-framework-react@0.3.0",
70
- "@tarojs/react": "npm:vite-plugin-taro-react@0.3.0"
69
+ "@tarojs/plugin-framework-react": "npm:vite-plugin-taro-plugin-framework-react@0.3.1",
70
+ "@tarojs/react": "npm:vite-plugin-taro-react@0.3.1"
71
71
  },
72
72
  "peerDependencies": {
73
73
  "react": "^19.0.0",
@@ -9,7 +9,7 @@ type ProjectContext = Readonly<{
9
9
  pages: readonly VitePluginTaroPageOption[]
10
10
  appConfig: JsonObject
11
11
  projectConfigJson: JsonObject
12
- projectPrivateConfigJson: JsonObject
12
+ projectPrivateConfigJson?: JsonObject
13
13
  sitemapJson: JsonObject
14
14
  }>
15
15
 
@@ -19,6 +19,7 @@ export type WxBundle = Record<
19
19
 
20
20
  type WxAssetEmitter = {
21
21
  emitFile(asset: { type: 'asset'; fileName: string; source: WxAssetSource }): string
22
+ warn(message: string): void
22
23
  }
23
24
 
24
25
  type WxTemplateComponentConfig = {
@@ -33,6 +34,13 @@ const templateBuilder = createWxTemplateBuilder()
33
34
 
34
35
  export function emitWxCompanionAssets(emitter: WxAssetEmitter, bundle: WxBundle, context: BuildContext): void {
35
36
  for (const asset of createWxCompanionAssets(bundle, context)) {
37
+ if (!asset) continue
38
+ if (asset.source === undefined) {
39
+ emitter.warn(
40
+ `[vite-plugin-taro] WX companion asset "${asset.fileName}" is missing its source and was not emitted.`
41
+ )
42
+ continue
43
+ }
36
44
  emitter.emitFile({ type: 'asset', fileName: asset.fileName, source: asset.source })
37
45
  }
38
46
  }
@@ -40,7 +48,7 @@ export function emitWxCompanionAssets(emitter: WxAssetEmitter, bundle: WxBundle,
40
48
  function createWxCompanionAssets(
41
49
  bundle: WxBundle,
42
50
  context: BuildContext
43
- ): { fileName: string; source: WxAssetSource }[] {
51
+ ): ({ fileName: string; source: WxAssetSource } | undefined)[] {
44
52
  const json = (value: JsonObject) => (context.development ? JSON.stringify(value, null, 2) : JSON.stringify(value))
45
53
 
46
54
  return [
@@ -54,7 +62,9 @@ function createWxCompanionAssets(
54
62
  { fileName: 'comp.wxml', source: templateBuilder.buildBaseComponentTemplate('.wxml') },
55
63
  { fileName: 'comp.json', source: json(createWxComponentConfig()) },
56
64
  { fileName: 'project.config.json', source: json(createWxProjectConfig(context)) },
57
- { fileName: 'project.private.config.json', source: json(context.project.projectPrivateConfigJson) },
65
+ context.project.projectPrivateConfigJson
66
+ ? { fileName: 'project.private.config.json', source: json(context.project.projectPrivateConfigJson) }
67
+ : undefined,
58
68
  { fileName: 'sitemap.json', source: json(context.project.sitemapJson) },
59
69
  ...context.project.pages.flatMap((page) => [
60
70
  {
package/src/options.ts CHANGED
@@ -20,6 +20,6 @@ export interface VitePluginTaroOptions {
20
20
  pages: VitePluginTaroPageOption[]
21
21
  appJson: JsonObject
22
22
  projectConfigJson: JsonObject
23
- projectPrivateConfigJson: JsonObject
23
+ projectPrivateConfigJson?: JsonObject
24
24
  sitemapJson: JsonObject
25
25
  }