@tsrx/rspack-plugin-react 0.0.91 → 0.0.92

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.
package/README.md ADDED
@@ -0,0 +1,43 @@
1
+ # @tsrx/rspack-plugin-react
2
+
3
+ Rspack plugin for compiling `@tsrx/react` `.tsrx` files.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ pnpm add -D @tsrx/rspack-plugin-react
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```ts
14
+ import { TsrxReactRspackPlugin } from '@tsrx/rspack-plugin-react';
15
+
16
+ export default {
17
+ plugins: [new TsrxReactRspackPlugin()],
18
+ };
19
+ ```
20
+
21
+ The plugin compiles `.tsrx` modules with `@tsrx/react`, chains
22
+ `builtin:swc-loader` for React's automatic JSX runtime, and emits sibling-scoped
23
+ `<style>` blocks (each styles its siblings and everything below them) through
24
+ Rspack's built-in CSS module type.
25
+
26
+ It also pushes `.tsrx` into `resolve.extensions` and enables `experiments.css`
27
+ when unset.
28
+
29
+ ## Options
30
+
31
+ - `jsxImportSource`: automatic JSX runtime import source (default: `'react'`).
32
+ - `runtimeImports`: helper import mode (`'compiler'` by default, or `'direct'` for
33
+ standalone runtime imports).
34
+
35
+ When using `runtimeImports: 'direct'`, install the runtime as a direct production
36
+ dependency of the package that owns the compiled modules:
37
+
38
+ ```bash
39
+ pnpm add @tsrx/react-runtime
40
+ ```
41
+
42
+ The plugin only emits bare `@tsrx/react-runtime/*` imports and does not provide
43
+ the runtime package.
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "description": "Rspack plugin for @tsrx/react",
4
4
  "license": "MIT",
5
5
  "author": "Dominic Gannaway",
6
- "version": "0.0.91",
6
+ "version": "0.0.92",
7
7
  "type": "module",
8
8
  "publishConfig": {
9
9
  "access": "public"
@@ -20,7 +20,7 @@
20
20
  }
21
21
  },
22
22
  "dependencies": {
23
- "@tsrx/react": "0.2.65"
23
+ "@tsrx/react": "0.2.66"
24
24
  },
25
25
  "peerDependencies": {
26
26
  "@rspack/core": ">=1.6.0"
package/src/css-loader.js CHANGED
@@ -7,7 +7,7 @@ import { compile } from '@tsrx/react';
7
7
  /**
8
8
  * Re-runs the `@tsrx/react` compiler against the `.tsrx` source to extract
9
9
  * the scoped CSS emitted by its `<style>` block. Invoked when rspack resolves
10
- * the sibling `?tsrx-css&lang.css` import prepended by the JS loader.
10
+ * the sibling `?tsrx-css&lang.css` import emitted by the JS loader.
11
11
  *
12
12
  * @this {LoaderContext<{ runtimeImports?: RuntimeImportMode }>}
13
13
  * @param {string} source
package/src/js-loader.js CHANGED
@@ -6,7 +6,7 @@ import { compile } from '@tsrx/react';
6
6
 
7
7
  /**
8
8
  * Compiles `.tsrx` source to TSX and, when a `<style>` block is present,
9
- * prepends an `import` to the sibling virtual CSS module so rspack can
9
+ * appends an `import` of the sibling virtual CSS module so rspack can
10
10
  * include the styles in the asset graph.
11
11
  *
12
12
  * @this {LoaderContext<{ runtimeImports?: RuntimeImportMode }>}
@@ -21,15 +21,16 @@ export default function jsLoader(source) {
21
21
  const { code, map, css } = compile(source, resourcePath, this.getOptions?.());
22
22
 
23
23
  let output = code;
24
- /** @type {typeof map | null} */
25
- let output_map = map;
26
24
  if (css) {
25
+ // The import goes after the module's own imports so the stylesheets of
26
+ // imported themes are added to the asset graph first and a rule in the
27
+ // applying module wins at equal specificity. Nothing above it moves, so
28
+ // the compiler's source map still applies.
27
29
  const cssImport = `${resourcePath}?tsrx-css&lang.css`;
28
- output = `import ${JSON.stringify(cssImport)};\n${code}`;
29
- output_map = null;
30
+ output = `${code}\nimport ${JSON.stringify(cssImport)};\n`;
30
31
  }
31
32
 
32
- callback(null, output, /** @type {any} */ (output_map ?? undefined));
33
+ callback(null, output, /** @type {any} */ (map ?? undefined));
33
34
  } catch (/** @type {any} */ err) {
34
35
  callback(err);
35
36
  }