@tsrx/vite-plugin-preact 0.0.43 → 0.0.44

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.
Files changed (2) hide show
  1. package/package.json +3 -3
  2. package/src/index.js +26 -0
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "description": "Vite plugin for @tsrx/preact (.tsrx modules)",
4
4
  "license": "MIT",
5
5
  "author": "Dominic Gannaway",
6
- "version": "0.0.43",
6
+ "version": "0.0.44",
7
7
  "type": "module",
8
8
  "publishConfig": {
9
9
  "access": "public"
@@ -20,7 +20,7 @@
20
20
  }
21
21
  },
22
22
  "dependencies": {
23
- "@tsrx/preact": "0.1.18"
23
+ "@tsrx/preact": "0.1.19"
24
24
  },
25
25
  "peerDependencies": {
26
26
  "vite": "*"
@@ -29,7 +29,7 @@
29
29
  "preact": "^10.27.0",
30
30
  "typescript": "^5.9.3",
31
31
  "vite": "^8.0.12",
32
- "@tsrx/core": "0.1.18"
32
+ "@tsrx/core": "0.1.19"
33
33
  },
34
34
  "files": [
35
35
  "src",
package/src/index.js CHANGED
@@ -48,6 +48,20 @@ export function tsrxPreact(options = {}) {
48
48
  /** @type {Map<string, string>} */
49
49
  const css_cache = new Map();
50
50
 
51
+ /**
52
+ * @param {string} source
53
+ * @param {string} id
54
+ * @returns {void}
55
+ */
56
+ function update_css_cache(source, id) {
57
+ const { css } = compile(source, id, compile_options);
58
+ if (css) {
59
+ css_cache.set(id, css);
60
+ } else {
61
+ css_cache.delete(id);
62
+ }
63
+ }
64
+
51
65
  return /** @type {TsrxPreactPlugin} */ ({
52
66
  name: '@tsrx/vite-plugin-preact',
53
67
  enforce: 'pre',
@@ -98,6 +112,18 @@ export function tsrxPreact(options = {}) {
98
112
 
99
113
  return { code: result.code, map: result.map };
100
114
  },
115
+
116
+ async handleHotUpdate(ctx) {
117
+ if (!TSRX_EXTENSION_PATTERN.test(ctx.file)) return;
118
+
119
+ update_css_cache(await ctx.read(), ctx.file);
120
+
121
+ const css_mod = ctx.server.moduleGraph.getModuleById('\0' + ctx.file + CSS_QUERY);
122
+ if (!css_mod) return ctx.modules;
123
+
124
+ ctx.server.moduleGraph.invalidateModule(css_mod);
125
+ return [...ctx.modules, css_mod];
126
+ },
101
127
  });
102
128
  }
103
129