@tsrx/vite-plugin-react 0.0.103 → 0.0.104
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 +3 -3
- package/src/index.js +47 -10
- package/types/index.d.ts +7 -2
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"description": "Vite plugin for @tsrx/react (.tsrx modules)",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": "Dominic Gannaway",
|
|
6
|
-
"version": "0.0.
|
|
6
|
+
"version": "0.0.104",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"publishConfig": {
|
|
9
9
|
"access": "public"
|
|
@@ -20,8 +20,8 @@
|
|
|
20
20
|
}
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@tsrx/core": "0.1.
|
|
24
|
-
"@tsrx/react": "0.2.
|
|
23
|
+
"@tsrx/core": "0.1.71",
|
|
24
|
+
"@tsrx/react": "0.2.71"
|
|
25
25
|
},
|
|
26
26
|
"peerDependencies": {
|
|
27
27
|
"vite": "*"
|
package/src/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/** @import { Plugin } from 'vite' */
|
|
2
2
|
/** @import { DepScanTransformPlugin } from '@tsrx/core/types/vite/dep-scan' */
|
|
3
|
-
/** @import { RuntimeImportMode } from '@tsrx/react' */
|
|
3
|
+
/** @import { Platform, RuntimeImportMode } from '@tsrx/react' */
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* @typedef {{ code: string, map: unknown }} TsrxReactTransformResult
|
|
@@ -17,7 +17,8 @@
|
|
|
17
17
|
* (id: string): string | null,
|
|
18
18
|
* }} TsrxReactLoad
|
|
19
19
|
* @typedef {{
|
|
20
|
-
*
|
|
20
|
+
* define?: Record<string, unknown>,
|
|
21
|
+
* optimizeDeps?: {
|
|
21
22
|
* extensions: string[],
|
|
22
23
|
* rolldownOptions: {
|
|
23
24
|
* transform: { jsx: { importSource: string } },
|
|
@@ -27,7 +28,7 @@
|
|
|
27
28
|
* }} TsrxReactEnvironmentConfig
|
|
28
29
|
* @typedef {(
|
|
29
30
|
* name: string,
|
|
30
|
-
* config
|
|
31
|
+
* config?: import('vite').EnvironmentOptions,
|
|
31
32
|
* ) => TsrxReactEnvironmentConfig | undefined} TsrxReactConfigEnvironmentHook
|
|
32
33
|
* @typedef {Omit<Plugin, 'configEnvironment' | 'transform' | 'resolveId' | 'load'> & {
|
|
33
34
|
* configEnvironment: TsrxReactConfigEnvironmentHook,
|
|
@@ -39,6 +40,8 @@
|
|
|
39
40
|
|
|
40
41
|
import { transformWithOxc } from 'vite';
|
|
41
42
|
import { compile } from '@tsrx/react';
|
|
43
|
+
import { mergePlatformDefinitions, validatePlatform } from '@tsrx/core';
|
|
44
|
+
import { resolveBuildPlatform } from '@tsrx/core/config';
|
|
42
45
|
import { createDepScanTransformPlugin } from '@tsrx/core/vite/dep-scan';
|
|
43
46
|
|
|
44
47
|
const TSRX_EXTENSION_PATTERN = /\.tsrx$/;
|
|
@@ -50,12 +53,27 @@ const CSS_QUERY = '?tsrx-css&lang.css';
|
|
|
50
53
|
* `jsx-runtime`. Per-component `<style>` blocks are emitted as virtual CSS
|
|
51
54
|
* modules that are imported by the compiled JS output.
|
|
52
55
|
*
|
|
53
|
-
* @param {{ jsxImportSource?: string, runtimeImports?: RuntimeImportMode }} [options]
|
|
56
|
+
* @param {{ jsxImportSource?: string, runtimeImports?: RuntimeImportMode, platform?: Platform, tsconfig?: string }} [options]
|
|
54
57
|
* @returns {TsrxReactPlugin}
|
|
55
58
|
*/
|
|
56
59
|
export function tsrxReact(options = {}) {
|
|
60
|
+
const explicit_platform = validatePlatform(options.platform);
|
|
61
|
+
let platform = explicit_platform;
|
|
57
62
|
const jsxImportSource = options.jsxImportSource ?? 'react';
|
|
58
|
-
const compile_options = { runtimeImports: options.runtimeImports };
|
|
63
|
+
const compile_options = { runtimeImports: options.runtimeImports, platform };
|
|
64
|
+
|
|
65
|
+
/** @param {import('vite').UserConfig} config */
|
|
66
|
+
function resolve_platform(config) {
|
|
67
|
+
platform = resolveBuildPlatform({
|
|
68
|
+
root: config.root ?? process.cwd(),
|
|
69
|
+
tsconfig:
|
|
70
|
+
options.tsconfig ??
|
|
71
|
+
/** @type {{ tsconfig?: string }} */ (/** @type {unknown} */ (config)).tsconfig,
|
|
72
|
+
platform: explicit_platform,
|
|
73
|
+
integration: '@tsrx/vite-plugin-react',
|
|
74
|
+
});
|
|
75
|
+
compile_options.platform = platform;
|
|
76
|
+
}
|
|
59
77
|
|
|
60
78
|
/** @type {Map<string, string>} */
|
|
61
79
|
const css_cache = new Map();
|
|
@@ -78,14 +96,33 @@ export function tsrxReact(options = {}) {
|
|
|
78
96
|
name: '@tsrx/vite-plugin-react',
|
|
79
97
|
enforce: 'pre',
|
|
80
98
|
|
|
81
|
-
|
|
99
|
+
config(config = /** @type {import('vite').UserConfig} */ ({})) {
|
|
100
|
+
resolve_platform(config);
|
|
101
|
+
if (platform === undefined) return;
|
|
102
|
+
return {
|
|
103
|
+
define: mergePlatformDefinitions(config.define, platform, {
|
|
104
|
+
integration: 'Vite',
|
|
105
|
+
}),
|
|
106
|
+
};
|
|
107
|
+
},
|
|
108
|
+
|
|
109
|
+
configEnvironment(name, config = /** @type {import('vite').EnvironmentOptions} */ ({})) {
|
|
82
110
|
const discovers_dependencies =
|
|
83
111
|
name === 'client' || config.optimizeDeps?.noDiscovery === false;
|
|
84
|
-
if (!discovers_dependencies) {
|
|
112
|
+
if (!discovers_dependencies && platform === undefined) {
|
|
85
113
|
return;
|
|
86
114
|
}
|
|
87
115
|
|
|
88
|
-
return
|
|
116
|
+
return {
|
|
117
|
+
...(platform === undefined
|
|
118
|
+
? {}
|
|
119
|
+
: {
|
|
120
|
+
define: mergePlatformDefinitions(config.define, platform, {
|
|
121
|
+
integration: `Vite environment ${JSON.stringify(name)}`,
|
|
122
|
+
}),
|
|
123
|
+
}),
|
|
124
|
+
...(discovers_dependencies ? create_dep_scan_config(jsxImportSource, compile_options) : {}),
|
|
125
|
+
};
|
|
89
126
|
},
|
|
90
127
|
|
|
91
128
|
resolveId(/** @type {string} */ source) {
|
|
@@ -150,7 +187,7 @@ export function tsrxReact(options = {}) {
|
|
|
150
187
|
|
|
151
188
|
/**
|
|
152
189
|
* @param {string} jsxImportSource
|
|
153
|
-
* @param {{ runtimeImports?: RuntimeImportMode }} compile_options
|
|
190
|
+
* @param {{ runtimeImports?: RuntimeImportMode, platform?: Platform }} compile_options
|
|
154
191
|
* @returns {TsrxReactEnvironmentConfig}
|
|
155
192
|
*/
|
|
156
193
|
function create_dep_scan_config(jsxImportSource, compile_options) {
|
|
@@ -174,7 +211,7 @@ function create_dep_scan_config(jsxImportSource, compile_options) {
|
|
|
174
211
|
|
|
175
212
|
/**
|
|
176
213
|
* @param {string} jsxImportSource
|
|
177
|
-
* @param {{ runtimeImports?: RuntimeImportMode }} compile_options
|
|
214
|
+
* @param {{ runtimeImports?: RuntimeImportMode, platform?: Platform }} compile_options
|
|
178
215
|
* @returns {DepScanTransformPlugin}
|
|
179
216
|
*/
|
|
180
217
|
function create_dep_scan_plugin(jsxImportSource, compile_options) {
|
package/types/index.d.ts
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
import type { EnvironmentOptions, Plugin } from 'vite';
|
|
2
|
-
import type { RuntimeImportMode } from '@tsrx/react';
|
|
2
|
+
import type { Platform, RuntimeImportMode } from '@tsrx/react';
|
|
3
3
|
import type { DepScanTransformPlugin } from '@tsrx/core/types/vite/dep-scan';
|
|
4
4
|
|
|
5
5
|
export interface TsrxReactPluginOptions {
|
|
6
6
|
jsxImportSource?: string;
|
|
7
7
|
/** Direct mode requires `@tsrx/react-runtime` as a direct production dependency. */
|
|
8
8
|
runtimeImports?: RuntimeImportMode;
|
|
9
|
+
/** Optional override; inferred from tsconfig by default and must agree when both exist. */
|
|
10
|
+
platform?: Platform;
|
|
11
|
+
/** Optional tsconfig path override, resolved from Vite's project root. */
|
|
12
|
+
tsconfig?: string;
|
|
9
13
|
}
|
|
10
14
|
|
|
11
15
|
export interface TsrxReactTransformResult {
|
|
@@ -22,7 +26,8 @@ export interface TsrxReactPlugin extends Omit<
|
|
|
22
26
|
config: EnvironmentOptions,
|
|
23
27
|
) =>
|
|
24
28
|
| {
|
|
25
|
-
|
|
29
|
+
define?: Record<string, unknown>;
|
|
30
|
+
optimizeDeps?: {
|
|
26
31
|
extensions: string[];
|
|
27
32
|
rolldownOptions: {
|
|
28
33
|
transform: { jsx: { importSource: string } };
|