@tsrx/vite-plugin-react 0.0.88 → 0.0.90
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 +39 -22
- package/types/index.d.ts +16 -11
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.90",
|
|
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.57",
|
|
24
|
+
"@tsrx/react": "0.2.57"
|
|
25
25
|
},
|
|
26
26
|
"peerDependencies": {
|
|
27
27
|
"vite": "*"
|
package/src/index.js
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
* (id: `\0${string}?tsrx-css&lang.css`): string,
|
|
16
16
|
* (id: string): string | null,
|
|
17
17
|
* }} TsrxReactLoad
|
|
18
|
-
* @typedef {
|
|
18
|
+
* @typedef {{
|
|
19
19
|
* optimizeDeps: {
|
|
20
20
|
* extensions: string[],
|
|
21
21
|
* rolldownOptions: {
|
|
@@ -23,9 +23,13 @@
|
|
|
23
23
|
* plugins: [DepScanTransformPlugin],
|
|
24
24
|
* },
|
|
25
25
|
* },
|
|
26
|
-
* }}
|
|
27
|
-
* @typedef {
|
|
28
|
-
*
|
|
26
|
+
* }} TsrxReactEnvironmentConfig
|
|
27
|
+
* @typedef {(
|
|
28
|
+
* name: string,
|
|
29
|
+
* config: import('vite').EnvironmentOptions,
|
|
30
|
+
* ) => TsrxReactEnvironmentConfig | undefined} TsrxReactConfigEnvironmentHook
|
|
31
|
+
* @typedef {Omit<Plugin, 'configEnvironment' | 'transform' | 'resolveId' | 'load'> & {
|
|
32
|
+
* configEnvironment: TsrxReactConfigEnvironmentHook,
|
|
29
33
|
* transform: TsrxReactTransform,
|
|
30
34
|
* resolveId: TsrxReactResolveId,
|
|
31
35
|
* load: TsrxReactLoad,
|
|
@@ -72,24 +76,14 @@ export function tsrxReact(options = {}) {
|
|
|
72
76
|
name: '@tsrx/vite-plugin-react',
|
|
73
77
|
enforce: 'pre',
|
|
74
78
|
|
|
75
|
-
config
|
|
76
|
-
|
|
77
|
-
optimizeDeps
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
// The scan runs its own jsx transform over the tsx the
|
|
84
|
-
// dep-scan plugin hands back, and that transform defaults to
|
|
85
|
-
// react's runtime. Point it at the configured source, or the
|
|
86
|
-
// scan fails outright on an unresolvable
|
|
87
|
-
// `react/jsx-dev-runtime` in a project that has no react.
|
|
88
|
-
transform: { jsx: { importSource: jsxImportSource } },
|
|
89
|
-
plugins: [create_dep_scan_plugin(jsxImportSource)],
|
|
90
|
-
},
|
|
91
|
-
},
|
|
92
|
-
};
|
|
79
|
+
configEnvironment(name, config) {
|
|
80
|
+
const discovers_dependencies =
|
|
81
|
+
name === 'client' || config.optimizeDeps?.noDiscovery === false;
|
|
82
|
+
if (!discovers_dependencies) {
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
return create_dep_scan_config(jsxImportSource);
|
|
93
87
|
},
|
|
94
88
|
|
|
95
89
|
resolveId(/** @type {string} */ source) {
|
|
@@ -153,6 +147,29 @@ export function tsrxReact(options = {}) {
|
|
|
153
147
|
});
|
|
154
148
|
}
|
|
155
149
|
|
|
150
|
+
/**
|
|
151
|
+
* @param {string} jsxImportSource
|
|
152
|
+
* @returns {TsrxReactEnvironmentConfig}
|
|
153
|
+
*/
|
|
154
|
+
function create_dep_scan_config(jsxImportSource) {
|
|
155
|
+
return {
|
|
156
|
+
optimizeDeps: {
|
|
157
|
+
// The scanner externalizes anything that is not a known JS type
|
|
158
|
+
// unless its extension is listed here, so without this entry the
|
|
159
|
+
// dep-scan plugin below never runs.
|
|
160
|
+
extensions: ['.tsrx'],
|
|
161
|
+
rolldownOptions: {
|
|
162
|
+
// The scan runs its own jsx transform over the tsx the dep-scan
|
|
163
|
+
// plugin hands back, and that transform defaults to react's runtime.
|
|
164
|
+
// Point it at the configured source, or the scan fails outright on
|
|
165
|
+
// an unresolvable `react/jsx-dev-runtime` in a project without react.
|
|
166
|
+
transform: { jsx: { importSource: jsxImportSource } },
|
|
167
|
+
plugins: [create_dep_scan_plugin(jsxImportSource)],
|
|
168
|
+
},
|
|
169
|
+
},
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
|
|
156
173
|
/**
|
|
157
174
|
* @param {string} jsxImportSource
|
|
158
175
|
* @returns {DepScanTransformPlugin}
|
package/types/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Plugin } from 'vite';
|
|
1
|
+
import type { EnvironmentOptions, Plugin } from 'vite';
|
|
2
2
|
import type { DepScanTransformPlugin } from '@tsrx/core/types/vite/dep-scan';
|
|
3
3
|
|
|
4
4
|
export interface TsrxReactPluginOptions {
|
|
@@ -12,17 +12,22 @@ export interface TsrxReactTransformResult {
|
|
|
12
12
|
|
|
13
13
|
export interface TsrxReactPlugin extends Omit<
|
|
14
14
|
Plugin,
|
|
15
|
-
'
|
|
15
|
+
'configEnvironment' | 'transform' | 'resolveId' | 'load'
|
|
16
16
|
> {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
17
|
+
configEnvironment: (
|
|
18
|
+
name: string,
|
|
19
|
+
config: EnvironmentOptions,
|
|
20
|
+
) =>
|
|
21
|
+
| {
|
|
22
|
+
optimizeDeps: {
|
|
23
|
+
extensions: string[];
|
|
24
|
+
rolldownOptions: {
|
|
25
|
+
transform: { jsx: { importSource: string } };
|
|
26
|
+
plugins: [DepScanTransformPlugin];
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
| undefined;
|
|
26
31
|
transform: {
|
|
27
32
|
(code: string, id: `${string}.tsrx`): Promise<TsrxReactTransformResult>;
|
|
28
33
|
(code: string, id: string): Promise<TsrxReactTransformResult | null>;
|