@vitejs/plugin-react-swc 3.7.2 → 3.8.1
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 +14 -6
- package/index.cjs +10 -12
- package/index.d.ts +10 -2
- package/index.mjs +12 -14
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -93,6 +93,20 @@ react({
|
|
|
93
93
|
});
|
|
94
94
|
```
|
|
95
95
|
|
|
96
|
+
### useAtYourOwnRisk_mutateSwcOptions
|
|
97
|
+
|
|
98
|
+
The future of Vite is with OXC, and from the beginning this was a design choice to not exposed too many specialties from SWC so that Vite React users can move to another transformer later.
|
|
99
|
+
Also debugging why some specific version of decorators with some other unstable/legacy feature doesn't work is not fun, so we won't provide support for it, hence the name `useAtYourOwnRisk`.
|
|
100
|
+
|
|
101
|
+
```ts
|
|
102
|
+
react({
|
|
103
|
+
useAtYourOwnRisk_mutateSwcOptions(options) {
|
|
104
|
+
options.jsc.parser.decorators = true;
|
|
105
|
+
options.jsc.transform.decoratorVersion = "2022-03";
|
|
106
|
+
},
|
|
107
|
+
});
|
|
108
|
+
```
|
|
109
|
+
|
|
96
110
|
## Consistent components exports
|
|
97
111
|
|
|
98
112
|
For React refresh to work correctly, your file should only export React components. The best explanation I've read is the one from the [Gatsby docs](https://www.gatsbyjs.com/docs/reference/local-development/fast-refresh/#how-it-works).
|
|
@@ -100,9 +114,3 @@ For React refresh to work correctly, your file should only export React componen
|
|
|
100
114
|
If an incompatible change in exports is found, the module will be invalidated and HMR will propagate. To make it easier to export simple constants alongside your component, the module is only invalidated when their value changes.
|
|
101
115
|
|
|
102
116
|
You can catch mistakes and get more detailed warning with this [eslint rule](https://github.com/ArnaudBarre/eslint-plugin-react-refresh).
|
|
103
|
-
|
|
104
|
-
## Migrating from `vite-plugin-swc-react-refresh`
|
|
105
|
-
|
|
106
|
-
The documentation for the previous version of the plugin is available in the [v2 branch](https://github.com/vitejs/vite-plugin-react-swc/tree/v2)
|
|
107
|
-
|
|
108
|
-
To migrate, see this [changelog](https://github.com/vitejs/vite-plugin-react-swc/releases/tag/v3.0.0-beta.0)
|
package/index.cjs
CHANGED
|
@@ -16,8 +16,6 @@ var resolve = (0, import_module.createRequire)(
|
|
|
16
16
|
).resolve;
|
|
17
17
|
var reactCompRE = /extends\s+(?:React\.)?(?:Pure)?Component/;
|
|
18
18
|
var refreshContentRE = /\$Refresh(?:Reg|Sig)\$\(/;
|
|
19
|
-
var _a, _b;
|
|
20
|
-
var isWebContainer = (_b = (_a = globalThis.process) == null ? void 0 : _a.versions) == null ? void 0 : _b.webcontainer;
|
|
21
19
|
var react = (_options) => {
|
|
22
20
|
let hmrDisabled = false;
|
|
23
21
|
const options = {
|
|
@@ -25,7 +23,8 @@ var react = (_options) => {
|
|
|
25
23
|
tsDecorators: _options == null ? void 0 : _options.tsDecorators,
|
|
26
24
|
plugins: (_options == null ? void 0 : _options.plugins) ? _options == null ? void 0 : _options.plugins.map((el) => [resolve(el[0]), el[1]]) : void 0,
|
|
27
25
|
devTarget: (_options == null ? void 0 : _options.devTarget) ?? "es2020",
|
|
28
|
-
parserConfig: _options == null ? void 0 : _options.parserConfig
|
|
26
|
+
parserConfig: _options == null ? void 0 : _options.parserConfig,
|
|
27
|
+
useAtYourOwnRisk_mutateSwcOptions: _options == null ? void 0 : _options.useAtYourOwnRisk_mutateSwcOptions
|
|
29
28
|
};
|
|
30
29
|
return [
|
|
31
30
|
{
|
|
@@ -56,11 +55,6 @@ var react = (_options) => {
|
|
|
56
55
|
"[vite:react-swc] The MDX plugin should be placed before this plugin"
|
|
57
56
|
);
|
|
58
57
|
}
|
|
59
|
-
if (isWebContainer) {
|
|
60
|
-
config.logger.warn(
|
|
61
|
-
"[vite:react-swc] SWC is currently not supported in WebContainers. You can use the default React plugin instead."
|
|
62
|
-
);
|
|
63
|
-
}
|
|
64
58
|
},
|
|
65
59
|
transformIndexHtml: (_, config) => [
|
|
66
60
|
{
|
|
@@ -160,7 +154,7 @@ var transformWithOptions = async (id, code, target, options, reactConfig) => {
|
|
|
160
154
|
if (!parser) return;
|
|
161
155
|
let result;
|
|
162
156
|
try {
|
|
163
|
-
|
|
157
|
+
const swcOptions = {
|
|
164
158
|
filename: id,
|
|
165
159
|
swcrc: false,
|
|
166
160
|
configFile: false,
|
|
@@ -174,7 +168,11 @@ var transformWithOptions = async (id, code, target, options, reactConfig) => {
|
|
|
174
168
|
react: reactConfig
|
|
175
169
|
}
|
|
176
170
|
}
|
|
177
|
-
}
|
|
171
|
+
};
|
|
172
|
+
if (options.useAtYourOwnRisk_mutateSwcOptions) {
|
|
173
|
+
options.useAtYourOwnRisk_mutateSwcOptions(swcOptions);
|
|
174
|
+
}
|
|
175
|
+
result = await (0, import_core.transform)(code, swcOptions);
|
|
178
176
|
} catch (e) {
|
|
179
177
|
const message = e.message;
|
|
180
178
|
const fileStartIndex = message.indexOf("\u256D\u2500[");
|
|
@@ -192,14 +190,14 @@ var transformWithOptions = async (id, code, target, options, reactConfig) => {
|
|
|
192
190
|
var silenceUseClientWarning = (userConfig) => ({
|
|
193
191
|
rollupOptions: {
|
|
194
192
|
onwarn(warning, defaultHandler) {
|
|
195
|
-
var
|
|
193
|
+
var _a, _b;
|
|
196
194
|
if (warning.code === "MODULE_LEVEL_DIRECTIVE" && warning.message.includes("use client")) {
|
|
197
195
|
return;
|
|
198
196
|
}
|
|
199
197
|
if (warning.code === "SOURCEMAP_ERROR" && warning.message.includes("resolve original location") && warning.pos === 0) {
|
|
200
198
|
return;
|
|
201
199
|
}
|
|
202
|
-
if ((
|
|
200
|
+
if ((_b = (_a = userConfig.build) == null ? void 0 : _a.rollupOptions) == null ? void 0 : _b.onwarn) {
|
|
203
201
|
userConfig.build.rollupOptions.onwarn(warning, defaultHandler);
|
|
204
202
|
} else {
|
|
205
203
|
defaultHandler(warning);
|
package/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { ParserConfig, JscTarget } from "@swc/core";
|
|
2
|
-
import { PluginOption } from "vite";
|
|
1
|
+
import { type ParserConfig, type JscTarget, type Options as SWCOptions } from "@swc/core";
|
|
2
|
+
import type { PluginOption } from "vite";
|
|
3
3
|
type Options = {
|
|
4
4
|
/**
|
|
5
5
|
* Control where the JSX factory is imported from.
|
|
@@ -29,6 +29,14 @@ type Options = {
|
|
|
29
29
|
* Exclusion of node_modules should be handled by the function if needed.
|
|
30
30
|
*/
|
|
31
31
|
parserConfig?: (id: string) => ParserConfig | undefined;
|
|
32
|
+
/**
|
|
33
|
+
* The future of Vite is with OXC, and from the beginning this was a design choice
|
|
34
|
+
* to not exposed too many specialties from SWC so that Vite React users can move to
|
|
35
|
+
* another transformer later.
|
|
36
|
+
* Also debugging why some specific version of decorators with some other unstable/legacy
|
|
37
|
+
* feature doesn't work is not fun, so we won't provide support for it, hence the name `useAtYourOwnRisk`
|
|
38
|
+
*/
|
|
39
|
+
useAtYourOwnRisk_mutateSwcOptions?: (options: SWCOptions) => void;
|
|
32
40
|
};
|
|
33
41
|
declare const react: (_options?: Options) => PluginOption[];
|
|
34
42
|
export default react;
|
package/index.mjs
CHANGED
|
@@ -17,8 +17,6 @@ var resolve = createRequire(
|
|
|
17
17
|
).resolve;
|
|
18
18
|
var reactCompRE = /extends\s+(?:React\.)?(?:Pure)?Component/;
|
|
19
19
|
var refreshContentRE = /\$Refresh(?:Reg|Sig)\$\(/;
|
|
20
|
-
var _a, _b;
|
|
21
|
-
var isWebContainer = (_b = (_a = globalThis.process) == null ? void 0 : _a.versions) == null ? void 0 : _b.webcontainer;
|
|
22
20
|
var react = (_options) => {
|
|
23
21
|
let hmrDisabled = false;
|
|
24
22
|
const options = {
|
|
@@ -26,7 +24,8 @@ var react = (_options) => {
|
|
|
26
24
|
tsDecorators: _options == null ? void 0 : _options.tsDecorators,
|
|
27
25
|
plugins: (_options == null ? void 0 : _options.plugins) ? _options == null ? void 0 : _options.plugins.map((el) => [resolve(el[0]), el[1]]) : void 0,
|
|
28
26
|
devTarget: (_options == null ? void 0 : _options.devTarget) ?? "es2020",
|
|
29
|
-
parserConfig: _options == null ? void 0 : _options.parserConfig
|
|
27
|
+
parserConfig: _options == null ? void 0 : _options.parserConfig,
|
|
28
|
+
useAtYourOwnRisk_mutateSwcOptions: _options == null ? void 0 : _options.useAtYourOwnRisk_mutateSwcOptions
|
|
30
29
|
};
|
|
31
30
|
return [
|
|
32
31
|
{
|
|
@@ -57,11 +56,6 @@ var react = (_options) => {
|
|
|
57
56
|
"[vite:react-swc] The MDX plugin should be placed before this plugin"
|
|
58
57
|
);
|
|
59
58
|
}
|
|
60
|
-
if (isWebContainer) {
|
|
61
|
-
config.logger.warn(
|
|
62
|
-
"[vite:react-swc] SWC is currently not supported in WebContainers. You can use the default React plugin instead."
|
|
63
|
-
);
|
|
64
|
-
}
|
|
65
59
|
},
|
|
66
60
|
transformIndexHtml: (_, config) => [
|
|
67
61
|
{
|
|
@@ -161,7 +155,7 @@ var transformWithOptions = async (id, code, target, options, reactConfig) => {
|
|
|
161
155
|
if (!parser) return;
|
|
162
156
|
let result;
|
|
163
157
|
try {
|
|
164
|
-
|
|
158
|
+
const swcOptions = {
|
|
165
159
|
filename: id,
|
|
166
160
|
swcrc: false,
|
|
167
161
|
configFile: false,
|
|
@@ -175,7 +169,11 @@ var transformWithOptions = async (id, code, target, options, reactConfig) => {
|
|
|
175
169
|
react: reactConfig
|
|
176
170
|
}
|
|
177
171
|
}
|
|
178
|
-
}
|
|
172
|
+
};
|
|
173
|
+
if (options.useAtYourOwnRisk_mutateSwcOptions) {
|
|
174
|
+
options.useAtYourOwnRisk_mutateSwcOptions(swcOptions);
|
|
175
|
+
}
|
|
176
|
+
result = await transform(code, swcOptions);
|
|
179
177
|
} catch (e) {
|
|
180
178
|
const message = e.message;
|
|
181
179
|
const fileStartIndex = message.indexOf("\u256D\u2500[");
|
|
@@ -193,14 +191,14 @@ var transformWithOptions = async (id, code, target, options, reactConfig) => {
|
|
|
193
191
|
var silenceUseClientWarning = (userConfig) => ({
|
|
194
192
|
rollupOptions: {
|
|
195
193
|
onwarn(warning, defaultHandler) {
|
|
196
|
-
var
|
|
194
|
+
var _a, _b;
|
|
197
195
|
if (warning.code === "MODULE_LEVEL_DIRECTIVE" && warning.message.includes("use client")) {
|
|
198
196
|
return;
|
|
199
197
|
}
|
|
200
198
|
if (warning.code === "SOURCEMAP_ERROR" && warning.message.includes("resolve original location") && warning.pos === 0) {
|
|
201
199
|
return;
|
|
202
200
|
}
|
|
203
|
-
if ((
|
|
201
|
+
if ((_b = (_a = userConfig.build) == null ? void 0 : _a.rollupOptions) == null ? void 0 : _b.onwarn) {
|
|
204
202
|
userConfig.build.rollupOptions.onwarn(warning, defaultHandler);
|
|
205
203
|
} else {
|
|
206
204
|
defaultHandler(warning);
|
|
@@ -208,7 +206,7 @@ var silenceUseClientWarning = (userConfig) => ({
|
|
|
208
206
|
}
|
|
209
207
|
}
|
|
210
208
|
});
|
|
211
|
-
var
|
|
209
|
+
var index_default = react;
|
|
212
210
|
export {
|
|
213
|
-
|
|
211
|
+
index_default as default
|
|
214
212
|
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vitejs/plugin-react-swc",
|
|
3
3
|
"description": "Speed up your Vite dev server with SWC",
|
|
4
|
-
"version": "3.
|
|
4
|
+
"version": "3.8.1",
|
|
5
5
|
"author": "Arnaud Barré (https://github.com/ArnaudBarre)",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"repository": "github:vitejs/vite-plugin-react-swc",
|
|
@@ -28,6 +28,6 @@
|
|
|
28
28
|
"vite": "^4 || ^5 || ^6"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@swc/core": "^1.
|
|
31
|
+
"@swc/core": "^1.11.11"
|
|
32
32
|
}
|
|
33
33
|
}
|