@tsrx/rspack-plugin-vue 0.0.76 → 0.0.78

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,45 @@
1
+ # @tsrx/rspack-plugin-vue
2
+
3
+ Rspack plugin for compiling `@tsrx/vue` `.tsrx` files.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ pnpm add @tsrx/vue vue vue-jsx-vapor
9
+ pnpm add -D @tsrx/rspack-plugin-vue
10
+ ```
11
+
12
+ ## Usage
13
+
14
+ ```ts
15
+ import { TsrxVueRspackPlugin } from '@tsrx/rspack-plugin-vue';
16
+
17
+ export default {
18
+ plugins: [new TsrxVueRspackPlugin()],
19
+ };
20
+ ```
21
+
22
+ The plugin compiles `.tsrx` modules with `@tsrx/vue`, runs the result through
23
+ `vue-jsx-vapor`, strips the remaining TypeScript syntax with `builtin:swc-loader`,
24
+ and emits sibling-scoped `<style>` blocks (each styles its siblings and everything
25
+ 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. Editor typechecking should set `jsxImportSource: 'vue-jsx-vapor'`.
29
+
30
+ ## Options
31
+
32
+ - `vapor`: options forwarded to `vue-jsx-vapor`. By default the plugin enables
33
+ macros and uses `runtimeModuleName: 'vue-jsx-vapor'`.
34
+ - `runtimeImports`: helper import mode (`'compiler'` by default, or `'direct'` for
35
+ standalone runtime imports).
36
+
37
+ When using `runtimeImports: 'direct'`, install the runtime as a direct production
38
+ dependency of the package that owns the compiled modules:
39
+
40
+ ```bash
41
+ pnpm add @tsrx/vue-runtime
42
+ ```
43
+
44
+ The plugin only emits bare `@tsrx/vue-runtime/*` imports and does not provide the
45
+ runtime package.
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "description": "Rspack plugin for @tsrx/vue",
4
4
  "license": "MIT",
5
5
  "author": "Dominic Gannaway",
6
- "version": "0.0.76",
6
+ "version": "0.0.78",
7
7
  "type": "module",
8
8
  "publishConfig": {
9
9
  "access": "public"
@@ -21,7 +21,7 @@
21
21
  },
22
22
  "dependencies": {
23
23
  "source-map": "^0.7.6",
24
- "@tsrx/vue": "0.1.64"
24
+ "@tsrx/vue": "0.1.66"
25
25
  },
26
26
  "peerDependencies": {
27
27
  "@rspack/core": ">=1.6.0",
package/src/css-loader.js CHANGED
@@ -7,7 +7,7 @@ import { compile } from '@tsrx/vue';
7
7
  /**
8
8
  * Re-runs the `@tsrx/vue` compiler against the `.tsrx` source to extract the
9
9
  * scoped CSS emitted by its `<style>` block. Invoked when rspack resolves the
10
- * sibling `?tsrx-css&lang.css` import prepended by the JS loader.
10
+ * 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/vue';
6
6
 
7
7
  /**
8
8
  * Compiles `.tsrx` source to Vue-flavoured TSX and, when a `<style>` block is
9
- * present, prepends an `import` to the sibling virtual CSS module so rspack can
9
+ * present, 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
  }