vite-plugin-taro 0.6.17 → 0.6.18

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.
@@ -8,7 +8,7 @@ type JavaScriptArtifact = Readonly<{
8
8
  }>;
9
9
  /** Vite plugin with the development-host operation that finalizes one coherent WX style/JavaScript transaction. */
10
10
  export type WxStylePlugin = Plugin & Readonly<{
11
- /** Converts patch factories and publishes their matching global WXSS through the host's atomic writer. */
11
+ /** Neutralizes browser CSS payloads and publishes their matching global WXSS through the host's atomic writer. */
12
12
  finalizeUpdate: <Artifact extends JavaScriptArtifact>(artifacts: readonly Artifact[], writeWxss: (wxss: string) => Promise<void>) => Promise<readonly Artifact[]>;
13
13
  }>;
14
14
  /**
@@ -93,7 +93,8 @@ export type WxStylePlugin = Plugin & Readonly<{
93
93
  * The development host calls `finalizeUpdate()` after Rolldown produces patch factories or a complete-output notification.
94
94
  * Finalization uses the `PluginContext` captured by `buildStart`, so it observes the same current graph as the compiler. After
95
95
  * all conversion succeeds, the host's atomic writer publishes changed WXSS before `finalizeUpdate()` returns converted patch
96
- * factories. The patch publisher therefore cannot expose newer JavaScript class identities before matching selectors exist.
96
+ * factories. Their captured Vite CSS literals are emptied first; factories, exports, changed IDs, and sequences remain intact.
97
+ * The patch publisher therefore cannot expose newer JavaScript class identities before matching selectors exist.
97
98
  * `publishedWxss` advances only after a successful write and suppresses byte-identical writes that would otherwise trigger
98
99
  * unnecessary WeChat DevTools reload events.
99
100
  *
@@ -98,7 +98,8 @@ const wxStyleOptions = {
98
98
  * The development host calls `finalizeUpdate()` after Rolldown produces patch factories or a complete-output notification.
99
99
  * Finalization uses the `PluginContext` captured by `buildStart`, so it observes the same current graph as the compiler. After
100
100
  * all conversion succeeds, the host's atomic writer publishes changed WXSS before `finalizeUpdate()` returns converted patch
101
- * factories. The patch publisher therefore cannot expose newer JavaScript class identities before matching selectors exist.
101
+ * factories. Their captured Vite CSS literals are emptied first; factories, exports, changed IDs, and sequences remain intact.
102
+ * The patch publisher therefore cannot expose newer JavaScript class identities before matching selectors exist.
102
103
  * `publishedWxss` advances only after a successful write and suppresses byte-identical writes that would otherwise trigger
103
104
  * unnecessary WeChat DevTools reload events.
104
105
  *
@@ -278,8 +279,13 @@ export function createWxStylePlugin(applicationEntryIds) {
278
279
  },
279
280
  /** Finalizes one development result and publishes matching WXSS before exposing converted patch factories. */
280
281
  finalizeUpdate: async (artifacts, writeWxss) => {
282
+ // CSS is already captured for physical publication, so its browser payload need not enter JavaScript conversion.
283
+ const javaScript = artifacts.map((artifact) => ({
284
+ code: neutralizeViteCssPayload(artifact.code),
285
+ filename: artifact.filename
286
+ }));
281
287
  // Step 1: complete every fallible conversion against one snapshot of the current module graph.
282
- const output = await finalizeCurrentOutput(graphContext, artifacts);
288
+ const output = await finalizeCurrentOutput(graphContext, javaScript);
283
289
  // Step 2: publish changed WXSS first so DevTools cannot observe JavaScript containing newer class identities.
284
290
  if (output.wxss !== publishedWxss) {
285
291
  await writeWxss(output.wxss);
@@ -421,6 +427,26 @@ function isApplicationStyle(id) {
421
427
  const parameters = new URLSearchParams(query);
422
428
  return ignoredStyleQueries.every((parameter) => !parameters.has(parameter));
423
429
  }
430
+ /**
431
+ * Empties only the CSS bytes in Vite's generated browser transport:
432
+ *
433
+ * ```js
434
+ * const __vite__css = ".app { color: red }";
435
+ * __vite__updateStyle(__vite__id, __vite__css);
436
+ * ```
437
+ *
438
+ * becomes:
439
+ *
440
+ * ```js
441
+ * const __vite__css = "";
442
+ * __vite__updateStyle(__vite__id, __vite__css);
443
+ * ```
444
+ *
445
+ * The surrounding factory, CSS Module exports, changed IDs, and patch sequence remain unchanged.
446
+ */
447
+ function neutralizeViteCssPayload(code) {
448
+ return code.replace(/(\b(?:const|let|var)\s+__vite__css[\w$]*\s*=\s*)"(?:\\[\s\S]|[^"\\])*"(?=;\s*\b__vite__updateStyle[\w$]*\s*\()/g, '$1""');
449
+ }
424
450
  /** Detects source forms that require Tailwind compilation before Vite processes the resulting CSS. */
425
451
  function isTailwindRoot(code) {
426
452
  // Tailwind v4 uses package imports; legacy directives remain accepted because the generator supports both forms.
@@ -2,11 +2,11 @@ import path from 'node:path';
2
2
  import { normalizePath } from 'vite';
3
3
  /** Resolves the source file for the configured App component. */
4
4
  export function resolveAppComponentPath({ appPath, projectRoot }) {
5
- return path.resolve(projectRoot, appPath);
5
+ return normalizePath(path.resolve(projectRoot, appPath));
6
6
  }
7
7
  /** Resolves the source file for one configured Page component. */
8
8
  export function resolvePageComponentPath({ pagePath, projectRoot }) {
9
- return path.resolve(projectRoot, 'src', `${pagePath}.tsx`);
9
+ return normalizePath(path.resolve(projectRoot, 'src', `${pagePath}.tsx`));
10
10
  }
11
11
  /** Creates a portable import for one configured Page component. */
12
12
  export function createPageComponentImportPath(options) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite-plugin-taro",
3
- "version": "0.6.17",
3
+ "version": "0.6.18",
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",
@@ -60,12 +60,12 @@
60
60
  "@tailwindcss/oxide": "4.3.3",
61
61
  "@tarojs/components": "4.2.1",
62
62
  "@tarojs/helper": "4.2.1",
63
- "@tarojs/plugin-framework-react": "npm:vite-plugin-taro-plugin-framework-react@0.6.17",
63
+ "@tarojs/plugin-framework-react": "npm:vite-plugin-taro-plugin-framework-react@0.6.18",
64
64
  "@tarojs/plugin-platform-h5": "4.2.1",
65
65
  "@tarojs/plugin-platform-weapp": "4.2.1",
66
- "@tarojs/react": "npm:vite-plugin-taro-react@0.6.17",
66
+ "@tarojs/react": "npm:vite-plugin-taro-react@0.6.18",
67
67
  "@tarojs/router": "4.2.1",
68
- "@tarojs/runtime": "npm:vite-plugin-taro-runtime@0.6.17",
68
+ "@tarojs/runtime": "npm:vite-plugin-taro-runtime@0.6.18",
69
69
  "@tarojs/taro": "4.2.1",
70
70
  "@vitejs/plugin-react": "^6.1.0",
71
71
  "@weapp-tailwindcss/postcss": "3.2.11",
@@ -46,7 +46,7 @@ type JavaScriptArtifact = Readonly<{
46
46
  /** Vite plugin with the development-host operation that finalizes one coherent WX style/JavaScript transaction. */
47
47
  export type WxStylePlugin = Plugin &
48
48
  Readonly<{
49
- /** Converts patch factories and publishes their matching global WXSS through the host's atomic writer. */
49
+ /** Neutralizes browser CSS payloads and publishes their matching global WXSS through the host's atomic writer. */
50
50
  finalizeUpdate: <Artifact extends JavaScriptArtifact>(
51
51
  artifacts: readonly Artifact[],
52
52
  writeWxss: (wxss: string) => Promise<void>
@@ -146,7 +146,8 @@ const wxStyleOptions = {
146
146
  * The development host calls `finalizeUpdate()` after Rolldown produces patch factories or a complete-output notification.
147
147
  * Finalization uses the `PluginContext` captured by `buildStart`, so it observes the same current graph as the compiler. After
148
148
  * all conversion succeeds, the host's atomic writer publishes changed WXSS before `finalizeUpdate()` returns converted patch
149
- * factories. The patch publisher therefore cannot expose newer JavaScript class identities before matching selectors exist.
149
+ * factories. Their captured Vite CSS literals are emptied first; factories, exports, changed IDs, and sequences remain intact.
150
+ * The patch publisher therefore cannot expose newer JavaScript class identities before matching selectors exist.
150
151
  * `publishedWxss` advances only after a successful write and suppresses byte-identical writes that would otherwise trigger
151
152
  * unnecessary WeChat DevTools reload events.
152
153
  *
@@ -353,8 +354,14 @@ export function createWxStylePlugin(applicationEntryIds: readonly string[]): WxS
353
354
  artifacts: readonly Artifact[],
354
355
  writeWxss: (wxss: string) => Promise<void>
355
356
  ): Promise<readonly Artifact[]> => {
357
+ // CSS is already captured for physical publication, so its browser payload need not enter JavaScript conversion.
358
+ const javaScript = artifacts.map((artifact) => ({
359
+ code: neutralizeViteCssPayload(artifact.code),
360
+ filename: artifact.filename
361
+ }))
362
+
356
363
  // Step 1: complete every fallible conversion against one snapshot of the current module graph.
357
- const output = await finalizeCurrentOutput(graphContext, artifacts)
364
+ const output = await finalizeCurrentOutput(graphContext, javaScript)
358
365
 
359
366
  // Step 2: publish changed WXSS first so DevTools cannot observe JavaScript containing newer class identities.
360
367
  if (output.wxss !== publishedWxss) {
@@ -549,6 +556,30 @@ function isApplicationStyle(id: string): boolean {
549
556
  return ignoredStyleQueries.every((parameter) => !parameters.has(parameter))
550
557
  }
551
558
 
559
+ /**
560
+ * Empties only the CSS bytes in Vite's generated browser transport:
561
+ *
562
+ * ```js
563
+ * const __vite__css = ".app { color: red }";
564
+ * __vite__updateStyle(__vite__id, __vite__css);
565
+ * ```
566
+ *
567
+ * becomes:
568
+ *
569
+ * ```js
570
+ * const __vite__css = "";
571
+ * __vite__updateStyle(__vite__id, __vite__css);
572
+ * ```
573
+ *
574
+ * The surrounding factory, CSS Module exports, changed IDs, and patch sequence remain unchanged.
575
+ */
576
+ function neutralizeViteCssPayload(code: string): string {
577
+ return code.replace(
578
+ /(\b(?:const|let|var)\s+__vite__css[\w$]*\s*=\s*)"(?:\\[\s\S]|[^"\\])*"(?=;\s*\b__vite__updateStyle[\w$]*\s*\()/g,
579
+ '$1""'
580
+ )
581
+ }
582
+
552
583
  /** Detects source forms that require Tailwind compilation before Vite processes the resulting CSS. */
553
584
  function isTailwindRoot(code: string): boolean {
554
585
  // Tailwind v4 uses package imports; legacy directives remain accepted because the generator supports both forms.
@@ -13,12 +13,12 @@ type PageComponentPathOptions = {
13
13
 
14
14
  /** Resolves the source file for the configured App component. */
15
15
  export function resolveAppComponentPath({ appPath, projectRoot }: AppComponentPathOptions): string {
16
- return path.resolve(projectRoot, appPath)
16
+ return normalizePath(path.resolve(projectRoot, appPath))
17
17
  }
18
18
 
19
19
  /** Resolves the source file for one configured Page component. */
20
20
  export function resolvePageComponentPath({ pagePath, projectRoot }: PageComponentPathOptions): string {
21
- return path.resolve(projectRoot, 'src', `${pagePath}.tsx`)
21
+ return normalizePath(path.resolve(projectRoot, 'src', `${pagePath}.tsx`))
22
22
  }
23
23
 
24
24
  /** Creates a portable import for one configured Page component. */