@tsrx/rspack-plugin-solid 0.0.78 → 0.0.80

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,46 @@
1
+ # @tsrx/rspack-plugin-solid
2
+
3
+ Rspack plugin for compiling `@tsrx/solid` `.tsrx` files.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ pnpm add @tsrx/solid solid-js @solidjs/web
9
+ pnpm add -D @tsrx/rspack-plugin-solid
10
+ ```
11
+
12
+ ## Usage
13
+
14
+ ```ts
15
+ import { TsrxSolidRspackPlugin } from '@tsrx/rspack-plugin-solid';
16
+
17
+ export default {
18
+ plugins: [new TsrxSolidRspackPlugin()],
19
+ };
20
+ ```
21
+
22
+ The plugin compiles `.tsrx` modules with `@tsrx/solid`, runs the final TypeScript
23
+ and Solid JSX transform through `babel-loader` with `@babel/preset-typescript` and
24
+ `babel-preset-solid`, and emits sibling-scoped `<style>` blocks (each styles its
25
+ siblings and everything below them) through Rspack's built-in CSS module type.
26
+
27
+ It also pushes `.tsrx` into `resolve.extensions` and enables `experiments.css`
28
+ when unset. In development mode it adds `solid-refresh/babel` unless you pass
29
+ `hot: false`.
30
+
31
+ ## Options
32
+
33
+ - `hot`: whether to add `solid-refresh/babel` to the Babel pipeline. Defaults to
34
+ `true` unless Rspack is running in production mode.
35
+ - `runtimeImports`: helper import mode (`'compiler'` by default, or `'direct'` for
36
+ standalone runtime imports).
37
+
38
+ When using `runtimeImports: 'direct'`, install the runtime as a direct production
39
+ dependency of the package that owns the compiled modules:
40
+
41
+ ```bash
42
+ pnpm add @tsrx/solid-runtime
43
+ ```
44
+
45
+ The plugin only emits bare `@tsrx/solid-runtime/*` imports and does not provide
46
+ the runtime package.
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "description": "Rspack plugin for @tsrx/solid",
4
4
  "license": "MIT",
5
5
  "author": "Dominic Gannaway",
6
- "version": "0.0.78",
6
+ "version": "0.0.80",
7
7
  "type": "module",
8
8
  "publishConfig": {
9
9
  "access": "public"
@@ -25,7 +25,7 @@
25
25
  "babel-loader": "^10.1.1",
26
26
  "babel-preset-solid": "2.0.0-rc.3",
27
27
  "solid-refresh": "0.8.0-next.7",
28
- "@tsrx/solid": "0.1.65"
28
+ "@tsrx/solid": "0.1.67"
29
29
  },
30
30
  "peerDependencies": {
31
31
  "@rspack/core": ">=1.6.0"
package/src/css-loader.js CHANGED
@@ -7,7 +7,7 @@ import { compile } from '@tsrx/solid';
7
7
  /**
8
8
  * Re-runs the `@tsrx/solid` 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/solid';
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
  }