@tsrx/rspack-plugin-preact 0.0.81 → 0.0.83
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 +45 -0
- package/package.json +2 -2
- package/src/css-loader.js +1 -1
- package/src/js-loader.js +7 -6
package/README.md
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# @tsrx/rspack-plugin-preact
|
|
2
|
+
|
|
3
|
+
Rspack plugin for compiling `@tsrx/preact` `.tsrx` files.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pnpm add -D @tsrx/rspack-plugin-preact
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
import { TsrxPreactRspackPlugin } from '@tsrx/rspack-plugin-preact';
|
|
15
|
+
|
|
16
|
+
export default {
|
|
17
|
+
plugins: [new TsrxPreactRspackPlugin()],
|
|
18
|
+
};
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
The plugin compiles `.tsrx` modules with `@tsrx/preact`, chains
|
|
22
|
+
`builtin:swc-loader` for Preact'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: `'preact'`).
|
|
32
|
+
- `suspenseSource`: module used by the compiler for Suspense imports (default:
|
|
33
|
+
`'preact/compat'`).
|
|
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/preact-runtime
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
The plugin only emits bare `@tsrx/preact-runtime/*` imports and does not provide
|
|
45
|
+
the runtime package.
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"description": "Rspack plugin for @tsrx/preact",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": "Dominic Gannaway",
|
|
6
|
-
"version": "0.0.
|
|
6
|
+
"version": "0.0.83",
|
|
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.
|
|
23
|
+
"@tsrx/preact": "0.1.67"
|
|
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/preact';
|
|
|
7
7
|
/**
|
|
8
8
|
* Re-runs the `@tsrx/preact` 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
|
|
10
|
+
* the sibling `?tsrx-css&lang.css` import emitted by the JS loader.
|
|
11
11
|
*
|
|
12
12
|
* @this {LoaderContext<{ suspenseSource?: string, runtimeImports?: RuntimeImportMode }>}
|
|
13
13
|
* @param {string} source
|
package/src/js-loader.js
CHANGED
|
@@ -6,7 +6,7 @@ import { compile } from '@tsrx/preact';
|
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* Compiles `.tsrx` source to TSX and, when a `<style>` block is present,
|
|
9
|
-
*
|
|
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<{ suspenseSource?: string, 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 =
|
|
29
|
-
output_map = null;
|
|
30
|
+
output = `${code}\nimport ${JSON.stringify(cssImport)};\n`;
|
|
30
31
|
}
|
|
31
32
|
|
|
32
|
-
callback(null, output, /** @type {any} */ (
|
|
33
|
+
callback(null, output, /** @type {any} */ (map ?? undefined));
|
|
33
34
|
} catch (/** @type {any} */ err) {
|
|
34
35
|
callback(err);
|
|
35
36
|
}
|