@tsrx/rspack-plugin-react 0.0.83 → 0.0.85

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/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.83",
6
+ "version": "0.0.85",
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.57"
23
+ "@tsrx/react": "0.2.59"
24
24
  },
25
25
  "peerDependencies": {
26
26
  "@rspack/core": ">=1.6.0"
package/src/css-loader.js CHANGED
@@ -1,5 +1,7 @@
1
1
  /** @import { LoaderContext } from '@rspack/core' */
2
2
 
3
+ /** @import { RuntimeImportMode } from '@tsrx/react' */
4
+
3
5
  import { compile } from '@tsrx/react';
4
6
 
5
7
  /**
@@ -7,7 +9,7 @@ import { compile } from '@tsrx/react';
7
9
  * the scoped CSS emitted by its `<style>` block. Invoked when rspack resolves
8
10
  * the sibling `?tsrx-css&lang.css` import prepended by the JS loader.
9
11
  *
10
- * @this {LoaderContext<object>}
12
+ * @this {LoaderContext<{ runtimeImports?: RuntimeImportMode }>}
11
13
  * @param {string} source
12
14
  * @returns {void}
13
15
  */
@@ -16,7 +18,7 @@ export default function cssLoader(source) {
16
18
  const resourcePath = this.resourcePath;
17
19
 
18
20
  try {
19
- const { css } = compile(source, resourcePath);
21
+ const { css } = compile(source, resourcePath, this.getOptions?.());
20
22
  callback(null, css);
21
23
  } catch (/** @type {any} */ err) {
22
24
  callback(err);
package/src/index.js CHANGED
@@ -1,4 +1,5 @@
1
1
  /** @import { Compiler, RspackPluginInstance } from '@rspack/core' */
2
+ /** @import { RuntimeImportMode } from '@tsrx/react' */
2
3
 
3
4
  import path from 'node:path';
4
5
  import { fileURLToPath } from 'node:url';
@@ -23,11 +24,12 @@ const CSS_QUERY_PATTERN = /tsrx-css/;
23
24
  */
24
25
  export class TsrxReactRspackPlugin {
25
26
  /**
26
- * @param {{ jsxImportSource?: string }} [options]
27
+ * @param {{ jsxImportSource?: string, runtimeImports?: RuntimeImportMode }} [options]
27
28
  */
28
29
  constructor(options = {}) {
29
30
  this.options = {
30
31
  jsxImportSource: options.jsxImportSource ?? 'react',
32
+ runtimeImports: options.runtimeImports ?? 'compiler',
31
33
  };
32
34
  }
33
35
 
@@ -82,6 +84,9 @@ export class TsrxReactRspackPlugin {
82
84
  },
83
85
  {
84
86
  loader: JS_LOADER,
87
+ options: {
88
+ runtimeImports: this.options.runtimeImports,
89
+ },
85
90
  },
86
91
  ],
87
92
  },
@@ -92,6 +97,9 @@ export class TsrxReactRspackPlugin {
92
97
  use: [
93
98
  {
94
99
  loader: CSS_LOADER,
100
+ options: {
101
+ runtimeImports: this.options.runtimeImports,
102
+ },
95
103
  },
96
104
  ],
97
105
  },
package/src/js-loader.js CHANGED
@@ -1,5 +1,7 @@
1
1
  /** @import { LoaderContext } from '@rspack/core' */
2
2
 
3
+ /** @import { RuntimeImportMode } from '@tsrx/react' */
4
+
3
5
  import { compile } from '@tsrx/react';
4
6
 
5
7
  /**
@@ -7,7 +9,7 @@ import { compile } from '@tsrx/react';
7
9
  * prepends an `import` to the sibling virtual CSS module so rspack can
8
10
  * include the styles in the asset graph.
9
11
  *
10
- * @this {LoaderContext<object>}
12
+ * @this {LoaderContext<{ runtimeImports?: RuntimeImportMode }>}
11
13
  * @param {string} source
12
14
  * @returns {void}
13
15
  */
@@ -16,7 +18,7 @@ export default function jsLoader(source) {
16
18
  const resourcePath = this.resourcePath;
17
19
 
18
20
  try {
19
- const { code, map, css } = compile(source, resourcePath);
21
+ const { code, map, css } = compile(source, resourcePath, this.getOptions?.());
20
22
 
21
23
  let output = code;
22
24
  /** @type {typeof map | null} */
package/types/index.d.ts CHANGED
@@ -1,7 +1,10 @@
1
1
  import type { Compiler, RspackPluginInstance } from '@rspack/core';
2
+ import type { RuntimeImportMode } from '@tsrx/react';
2
3
 
3
4
  export interface TsrxReactRspackPluginOptions {
4
5
  jsxImportSource?: string;
6
+ /** Direct mode requires `@tsrx/react-runtime` as a direct production dependency. */
7
+ runtimeImports?: RuntimeImportMode;
5
8
  }
6
9
 
7
10
  export declare class TsrxReactRspackPlugin implements RspackPluginInstance {
@@ -18,6 +18,7 @@ declare module '@rspack/core' {
18
18
  }
19
19
 
20
20
  export interface LoaderContext<TOptions = object> {
21
+ getOptions(): TOptions;
21
22
  async(): (
22
23
  error?: Error | null,
23
24
  content?: string,