vite-plugin-taro 0.5.0 → 0.5.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.
@@ -1,4 +1,6 @@
1
1
  import type { PluginOption } from 'vite';
2
2
  import type { VitePluginTaroTarget } from '../../../options.ts';
3
+ /** Completes the final compatibility pass required by generated WXSS. */
4
+ export declare function adaptWxss(source: string): Promise<string>;
3
5
  /** Creates the target-aware Tailwind CSS plugins. */
4
6
  export declare function createCssPlugins(target: VitePluginTaroTarget): PluginOption[];
@@ -11,6 +11,11 @@ const wxStyleOptions = {
11
11
  rem2rpx: true,
12
12
  px2rpx: true
13
13
  };
14
+ const transformWxss = createStyleHandler(wxStyleOptions);
15
+ /** Completes the final compatibility pass required by generated WXSS. */
16
+ export async function adaptWxss(source) {
17
+ return (await transformWxss(source)).css;
18
+ }
14
19
  /** Creates the target-aware Tailwind CSS plugins. */
15
20
  export function createCssPlugins(target) {
16
21
  const wx = target === 'wx';
@@ -53,9 +58,6 @@ export function createCssPlugins(target) {
53
58
  * Remove it when upstream both completes adaptation and preserves the bundler-selected filename.
54
59
  */
55
60
  function createWxssCompatibilityFinalizer() {
56
- // This compatibility pass only needs the PostCSS style pipeline. Creating a complete weapp-tailwindcss context here
57
- // would initialize another Tailwind compiler and source scanner for CSS that the upstream Vite plugin already generated.
58
- const transformWxss = createStyleHandler(wxStyleOptions);
59
61
  return {
60
62
  name: 'vpt:wxss-compatibility-finalizer',
61
63
  enforce: 'post',
@@ -75,7 +77,7 @@ function createWxssCompatibilityFinalizer() {
75
77
  ? globalStyleAsset.source
76
78
  : new TextDecoder().decode(globalStyleAsset.source);
77
79
  if (source.length > 0) {
78
- globalStyleAsset.source = (await transformWxss(source)).css;
80
+ globalStyleAsset.source = await adaptWxss(source);
79
81
  }
80
82
  globalStyleAsset.fileName = 'app.wxss';
81
83
  }
@@ -9,6 +9,7 @@ import { createWxDevMode } from './create-wx-dev-mode.js';
9
9
  import { emptyOutputDirectory } from './empty-output-directory.js';
10
10
  import { hmrControlPath, hmrInfoFileName, hmrPatchesFileName, renderHmrInfo, renderInitialHmrPatches, writeHmrFile } from './hmr-files.js';
11
11
  import { PatchPublisher } from './patch-publisher.js';
12
+ import { publishWxDevStyle } from './publish-wx-dev-style.js';
12
13
  /**
13
14
  * Creates the wx dev host: the adapter that owns the physical Rolldown DevEngine (created
14
15
  * with dev(...)) and the patch publisher, and replaces Vite's bundledDev.listen so the
@@ -117,6 +118,7 @@ export async function createWxDevHost({ server, options }) {
117
118
  throw new Error('wx development requires exactly one Rolldown output.');
118
119
  }
119
120
  return dev(rolldownOptions, rolldownOptions.output, {
121
+ onAdditionalAssets: (output) => publishWxDevStyle(output, server.config.build.outDir),
120
122
  onHmrUpdates: async (result) => {
121
123
  if (result instanceof Error) {
122
124
  logWxError(server.config.logger, 'wx HMR update failed', result);
@@ -149,6 +151,7 @@ export async function createWxDevHost({ server, options }) {
149
151
  logWxError(server.config.logger, 'wx dev build failed', result);
150
152
  return;
151
153
  }
154
+ await publishWxDevStyle(result, server.config.build.outDir);
152
155
  // A fresh build identity per complete physical build; the App runtime reads it
153
156
  // from hmr/info.js before any module registers.
154
157
  await startFreshBuild();
@@ -0,0 +1,11 @@
1
+ type DevOutputFile = Readonly<{
2
+ type: string;
3
+ fileName: string;
4
+ source?: string | Uint8Array;
5
+ }>;
6
+ type DevOutput = Readonly<{
7
+ output: readonly DevOutputFile[];
8
+ }>;
9
+ /** Publishes Vite bundled-dev's source-addressed global WXSS at WeChat's required root path. */
10
+ export declare function publishWxDevStyle(output: DevOutput, outDir: string): Promise<void>;
11
+ export {};
@@ -0,0 +1,12 @@
1
+ import { writeFile } from 'node:fs/promises';
2
+ import path from 'node:path';
3
+ import { adaptWxss } from '../../css/plugins.js';
4
+ /** Publishes Vite bundled-dev's source-addressed global WXSS at WeChat's required root path. */
5
+ export async function publishWxDevStyle(output, outDir) {
6
+ // WX disables CSS splitting, so the only non-empty WXSS asset is the application stylesheet; Page companions are empty.
7
+ const globalStyle = output.output.find((file) => file.type === 'asset' && file.fileName.endsWith('.wxss') && file.source && file.source.length > 0);
8
+ if (!globalStyle?.source)
9
+ return;
10
+ const source = typeof globalStyle.source === 'string' ? globalStyle.source : new TextDecoder().decode(globalStyle.source);
11
+ await writeFile(path.join(outDir, 'app.wxss'), await adaptWxss(source));
12
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite-plugin-taro",
3
- "version": "0.5.0",
3
+ "version": "0.5.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",
@@ -74,8 +74,8 @@
74
74
  "rolldown": "1.2.3",
75
75
  "tailwindcss": "^4.3.3",
76
76
  "weapp-tailwindcss": "^5.2.11",
77
- "@tarojs/plugin-framework-react": "npm:vite-plugin-taro-plugin-framework-react@0.5.0",
78
- "@tarojs/react": "npm:vite-plugin-taro-react@0.5.0"
77
+ "@tarojs/plugin-framework-react": "npm:vite-plugin-taro-plugin-framework-react@0.5.1",
78
+ "@tarojs/react": "npm:vite-plugin-taro-react@0.5.1"
79
79
  },
80
80
  "peerDependencies": {
81
81
  "react": "^19.0.0",
@@ -16,6 +16,13 @@ const wxStyleOptions = {
16
16
  px2rpx: true
17
17
  } as const
18
18
 
19
+ const transformWxss = createStyleHandler(wxStyleOptions)
20
+
21
+ /** Completes the final compatibility pass required by generated WXSS. */
22
+ export async function adaptWxss(source: string): Promise<string> {
23
+ return (await transformWxss(source)).css
24
+ }
25
+
19
26
  /** Creates the target-aware Tailwind CSS plugins. */
20
27
  export function createCssPlugins(target: VitePluginTaroTarget): PluginOption[] {
21
28
  const wx = target === 'wx'
@@ -60,10 +67,6 @@ export function createCssPlugins(target: VitePluginTaroTarget): PluginOption[] {
60
67
  * Remove it when upstream both completes adaptation and preserves the bundler-selected filename.
61
68
  */
62
69
  function createWxssCompatibilityFinalizer(): Plugin {
63
- // This compatibility pass only needs the PostCSS style pipeline. Creating a complete weapp-tailwindcss context here
64
- // would initialize another Tailwind compiler and source scanner for CSS that the upstream Vite plugin already generated.
65
- const transformWxss = createStyleHandler(wxStyleOptions)
66
-
67
70
  return {
68
71
  name: 'vpt:wxss-compatibility-finalizer',
69
72
  enforce: 'post',
@@ -87,7 +90,7 @@ function createWxssCompatibilityFinalizer(): Plugin {
87
90
  ? globalStyleAsset.source
88
91
  : new TextDecoder().decode(globalStyleAsset.source)
89
92
  if (source.length > 0) {
90
- globalStyleAsset.source = (await transformWxss(source)).css
93
+ globalStyleAsset.source = await adaptWxss(source)
91
94
  }
92
95
  globalStyleAsset.fileName = 'app.wxss'
93
96
  }
@@ -22,6 +22,7 @@ import {
22
22
  writeHmrFile
23
23
  } from './hmr-files.ts'
24
24
  import { PatchPublisher } from './patch-publisher.ts'
25
+ import { publishWxDevStyle } from './publish-wx-dev-style.ts'
25
26
 
26
27
  export type WxDevHost = Readonly<{
27
28
  close: () => Promise<void>
@@ -169,6 +170,7 @@ export async function createWxDevHost({
169
170
  }
170
171
 
171
172
  return dev(rolldownOptions, rolldownOptions.output, {
173
+ onAdditionalAssets: (output) => publishWxDevStyle(output, server.config.build.outDir),
172
174
  onHmrUpdates: async (result) => {
173
175
  if (result instanceof Error) {
174
176
  logWxError(server.config.logger, 'wx HMR update failed', result)
@@ -204,6 +206,7 @@ export async function createWxDevHost({
204
206
  logWxError(server.config.logger, 'wx dev build failed', result)
205
207
  return
206
208
  }
209
+ await publishWxDevStyle(result, server.config.build.outDir)
207
210
  // A fresh build identity per complete physical build; the App runtime reads it
208
211
  // from hmr/info.js before any module registers.
209
212
  await startFreshBuild()
@@ -0,0 +1,26 @@
1
+ import { writeFile } from 'node:fs/promises'
2
+ import path from 'node:path'
3
+ import { adaptWxss } from '../../css/plugins.ts'
4
+
5
+ type DevOutputFile = Readonly<{
6
+ type: string
7
+ fileName: string
8
+ source?: string | Uint8Array
9
+ }>
10
+
11
+ type DevOutput = Readonly<{
12
+ output: readonly DevOutputFile[]
13
+ }>
14
+
15
+ /** Publishes Vite bundled-dev's source-addressed global WXSS at WeChat's required root path. */
16
+ export async function publishWxDevStyle(output: DevOutput, outDir: string): Promise<void> {
17
+ // WX disables CSS splitting, so the only non-empty WXSS asset is the application stylesheet; Page companions are empty.
18
+ const globalStyle = output.output.find(
19
+ (file) => file.type === 'asset' && file.fileName.endsWith('.wxss') && file.source && file.source.length > 0
20
+ )
21
+ if (!globalStyle?.source) return
22
+
23
+ const source =
24
+ typeof globalStyle.source === 'string' ? globalStyle.source : new TextDecoder().decode(globalStyle.source)
25
+ await writeFile(path.join(outDir, 'app.wxss'), await adaptWxss(source))
26
+ }