vite-plugin-taro 0.5.7 → 0.5.10

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.
@@ -23,6 +23,14 @@ export function createWxDevelopmentPlugin(options) {
23
23
  config() {
24
24
  return {
25
25
  build: {
26
+ // The development output is the live Mini Program project opened by WeChat DevTools, not a disposable
27
+ // build artifact. Deleting and recreating its directory tree during a dev-server restart disrupts
28
+ // DevTools' hot-reload watcher; recreating the same paths does not reliably attach that watcher again.
29
+ // The host then continues writing hmr/patches.js, but DevTools no longer observes it and therefore never
30
+ // re-executes the Page shell that consumes and acknowledges the patches. Keep the watched paths present
31
+ // across host restarts and let the initial complete build overwrite active outputs. This plugin applies
32
+ // only to `serve`; production builds retain Vite's normal output cleanup.
33
+ emptyOutDir: false,
26
34
  // Disable maps in resolved environment config as well as final output so Oxc and Babel skip producing
27
35
  // intermediate maps that Rolldown would discard.
28
36
  sourcemap: false
@@ -5,7 +5,6 @@ import { once } from '../../../utils/once.js';
5
5
  import { resolvePackageFile } from '../../../utils/packages.js';
6
6
  import { appShellFileName } from '../module.js';
7
7
  import { createWxDevMode } from './create-wx-dev-mode.js';
8
- import { emptyOutputDirectory } from './empty-output-directory.js';
9
8
  /** Installs the physical WX output and runtime conventions over Vite's browser-oriented bundled-development options. */
10
9
  export function installWxDevOptions({ bundledDev, server, options }) {
11
10
  // The buildEnd hook and its one-shot result belong to the same abstraction. Consumers can await startup without receiving
@@ -42,25 +41,13 @@ export function installWxDevOptions({ bundledDev, server, options }) {
42
41
  });
43
42
  rolldownOptions.experimental ??= {};
44
43
  rolldownOptions.experimental.devMode = createWxDevMode(rolldownOptions.experimental.devMode, await bundleRuntimeSource());
45
- const emptyOutputDirectoryPlugin = {
46
- name: 'vpt:wx-empty-output-directory',
47
- renderStart: {
48
- order: 'pre',
49
- // DevEngine bypasses Vite's build-only output preparation. Preserve the watched directory itself while
50
- // removing stale contents before each complete physical render.
51
- handler: () => emptyOutputDirectory(server.config.build.outDir)
52
- }
53
- };
54
44
  const reportInitialBuildPlugin = {
55
45
  name: 'vpt:wx-report-initial-build',
56
46
  buildEnd: settleInitialBuild
57
47
  };
58
- rolldownOptions.plugins = [
59
- emptyOutputDirectoryPlugin,
60
- rolldownOptions.plugins,
61
- reportInitialBuildPlugin,
62
- createViteReporter(server)
63
- ];
48
+ // Preserve the physical paths watched by WeChat DevTools across host restarts; the complete build overwrites every
49
+ // active output without disrupting the hot-reload watcher.
50
+ rolldownOptions.plugins = [rolldownOptions.plugins, reportInitialBuildPlugin, createViteReporter(server)];
64
51
  disableViteOxcSourcemap(rolldownOptions.plugins);
65
52
  return rolldownOptions;
66
53
  };
@@ -104,8 +104,8 @@ function createWxPlugin(options) {
104
104
  generateBundle: {
105
105
  /*
106
106
  * This hook is registered after createCssPlugins() and shares hook-level `order: 'post'` with the adapted
107
- * upstream hooks and VPT style finalizer. Registration order therefore guarantees that app.wxss is complete
108
- * before native Page/component companions are emitted. Without this order, the CSS finalizer could consume
107
+ * upstream hooks and VPT style finalizer. Registration order therefore guarantees that the imported global
108
+ * stylesheet is complete before native Page/component companions are emitted. Without this order, the finalizer could consume
109
109
  * incomplete Tailwind output or mistake native WXSS companions for additional compiler styles.
110
110
  */
111
111
  order: 'post',
@@ -278,7 +278,7 @@ class WxDevRuntime extends DevRuntime {
278
278
  /**
279
279
  * Folds one cumulative physical patch file into a single logical HMR update.
280
280
  *
281
- * `hmr/patches.js` can contain several unacknowledged Rolldown patches and can be required by several Page shells. The
281
+ * `hmr/patches.js` can contain several unacknowledged application patches and can be required by several Page shells. The
282
282
  * runtime must therefore ignore replayed sequences, reject a missing sequence, and move directly from the currently live
283
283
  * module generation to the latest published generation without rendering intermediate generations.
284
284
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite-plugin-taro",
3
- "version": "0.5.7",
3
+ "version": "0.5.10",
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,8 +75,8 @@
75
75
  "rolldown": "1.2.3",
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.5.7",
79
- "@tarojs/react": "npm:vite-plugin-taro-react@0.5.7"
78
+ "@tarojs/react": "npm:vite-plugin-taro-react@0.5.10",
79
+ "@tarojs/plugin-framework-react": "npm:vite-plugin-taro-plugin-framework-react@0.5.10"
80
80
  },
81
81
  "peerDependencies": {
82
82
  "react": "^19.0.0",
@@ -29,6 +29,14 @@ export function createWxDevelopmentPlugin(options: VitePluginTaroOptions): Plugi
29
29
  config() {
30
30
  return {
31
31
  build: {
32
+ // The development output is the live Mini Program project opened by WeChat DevTools, not a disposable
33
+ // build artifact. Deleting and recreating its directory tree during a dev-server restart disrupts
34
+ // DevTools' hot-reload watcher; recreating the same paths does not reliably attach that watcher again.
35
+ // The host then continues writing hmr/patches.js, but DevTools no longer observes it and therefore never
36
+ // re-executes the Page shell that consumes and acknowledges the patches. Keep the watched paths present
37
+ // across host restarts and let the initial complete build overwrite active outputs. This plugin applies
38
+ // only to `serve`; production builds retain Vite's normal output cleanup.
39
+ emptyOutDir: false,
32
40
  // Disable maps in resolved environment config as well as final output so Oxc and Babel skip producing
33
41
  // intermediate maps that Rolldown would discard.
34
42
  sourcemap: false
@@ -8,7 +8,6 @@ import { once } from '../../../utils/once.ts'
8
8
  import { resolvePackageFile } from '../../../utils/packages.ts'
9
9
  import { appShellFileName } from '../module.ts'
10
10
  import { createWxDevMode } from './create-wx-dev-mode.ts'
11
- import { emptyOutputDirectory } from './empty-output-directory.ts'
12
11
 
13
12
  export type BundledDevRolldownOptions = InputOptions & {
14
13
  experimental?: {
@@ -77,27 +76,14 @@ export function installWxDevOptions({
77
76
  await bundleRuntimeSource()
78
77
  )
79
78
 
80
- const emptyOutputDirectoryPlugin: Plugin = {
81
- name: 'vpt:wx-empty-output-directory',
82
- renderStart: {
83
- order: 'pre',
84
- // DevEngine bypasses Vite's build-only output preparation. Preserve the watched directory itself while
85
- // removing stale contents before each complete physical render.
86
- handler: () => emptyOutputDirectory(server.config.build.outDir)
87
- }
88
- }
89
-
90
79
  const reportInitialBuildPlugin: Plugin = {
91
80
  name: 'vpt:wx-report-initial-build',
92
81
  buildEnd: settleInitialBuild
93
82
  }
94
83
 
95
- rolldownOptions.plugins = [
96
- emptyOutputDirectoryPlugin,
97
- rolldownOptions.plugins,
98
- reportInitialBuildPlugin,
99
- createViteReporter(server)
100
- ]
84
+ // Preserve the physical paths watched by WeChat DevTools across host restarts; the complete build overwrites every
85
+ // active output without disrupting the hot-reload watcher.
86
+ rolldownOptions.plugins = [rolldownOptions.plugins, reportInitialBuildPlugin, createViteReporter(server)]
101
87
  disableViteOxcSourcemap(rolldownOptions.plugins)
102
88
 
103
89
  return rolldownOptions
@@ -128,8 +128,8 @@ function createWxPlugin(options: VitePluginTaroOptions): Plugin {
128
128
  generateBundle: {
129
129
  /*
130
130
  * This hook is registered after createCssPlugins() and shares hook-level `order: 'post'` with the adapted
131
- * upstream hooks and VPT style finalizer. Registration order therefore guarantees that app.wxss is complete
132
- * before native Page/component companions are emitted. Without this order, the CSS finalizer could consume
131
+ * upstream hooks and VPT style finalizer. Registration order therefore guarantees that the imported global
132
+ * stylesheet is complete before native Page/component companions are emitted. Without this order, the finalizer could consume
133
133
  * incomplete Tailwind output or mistake native WXSS companions for additional compiler styles.
134
134
  */
135
135
  order: 'post',
@@ -26,8 +26,8 @@ type HmrSession = {
26
26
  /** Fixed control URL discovered from the Vite server that produced this full build. */
27
27
  readonly endpoint: string
28
28
  /**
29
- * Highest contiguous Rolldown sequence whose factories, graph propagation, and accept
30
- * callbacks all succeeded. Replayed Page shells read this watermark; it advances only
29
+ * Highest contiguous application sequence whose factories, graph propagation, and accept callbacks all succeeded.
30
+ * Host-filtered native asset updates consume no sequence. Replayed Page shells read this watermark; it advances only
31
31
  * after an atomic batch succeeds and resets only with a new App heap.
32
32
  */
33
33
  appliedSeq: number
@@ -39,7 +39,7 @@ type PatchPayload = Readonly<{
39
39
  patches: readonly PatchProgram[]
40
40
  }>
41
41
 
42
- /** One patch: its Rolldown sequence, changed module ids, and factory program. */
42
+ /** One patch: its physical application sequence, changed module ids, and Rolldown factory program. */
43
43
  type PatchProgram = Readonly<{
44
44
  seq: number
45
45
  /** Stable ids of the changed modules; the sync apply walks the graph from these. */
@@ -415,7 +415,7 @@ class WxDevRuntime extends DevRuntime {
415
415
  /**
416
416
  * Folds one cumulative physical patch file into a single logical HMR update.
417
417
  *
418
- * `hmr/patches.js` can contain several unacknowledged Rolldown patches and can be required by several Page shells. The
418
+ * `hmr/patches.js` can contain several unacknowledged application patches and can be required by several Page shells. The
419
419
  * runtime must therefore ignore replayed sequences, reject a missing sequence, and move directly from the currently live
420
420
  * module generation to the latest published generation without rendering intermediate generations.
421
421
  *
@@ -1,2 +0,0 @@
1
- /** Empties an output directory without replacing the directory itself or deleting Git metadata. */
2
- export declare function emptyOutputDirectory(directory: string): Promise<void>;
@@ -1,10 +0,0 @@
1
- import fs from 'node:fs/promises';
2
- import path from 'node:path';
3
- /** Empties an output directory without replacing the directory itself or deleting Git metadata. */
4
- export async function emptyOutputDirectory(directory) {
5
- await fs.mkdir(directory, { recursive: true });
6
- const entries = await fs.readdir(directory);
7
- await Promise.all(entries
8
- .filter((entry) => entry !== '.git')
9
- .map((entry) => fs.rm(path.join(directory, entry), { force: true, recursive: true })));
10
- }
@@ -1,14 +0,0 @@
1
- import fs from 'node:fs/promises'
2
- import path from 'node:path'
3
-
4
- /** Empties an output directory without replacing the directory itself or deleting Git metadata. */
5
- export async function emptyOutputDirectory(directory: string): Promise<void> {
6
- await fs.mkdir(directory, { recursive: true })
7
- const entries = await fs.readdir(directory)
8
-
9
- await Promise.all(
10
- entries
11
- .filter((entry) => entry !== '.git')
12
- .map((entry) => fs.rm(path.join(directory, entry), { force: true, recursive: true }))
13
- )
14
- }