@vitejs/plugin-react-swc 3.2.0 → 3.3.0
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/index.cjs +33 -12
- package/index.mjs +36 -13
- package/package.json +2 -2
- package/refresh-runtime.js +11 -1
package/index.cjs
CHANGED
|
@@ -22,6 +22,14 @@ var react = (_options) => {
|
|
|
22
22
|
plugins: (_options == null ? void 0 : _options.plugins) ? _options == null ? void 0 : _options.plugins.map((el) => [resolve(el[0]), el[1]]) : void 0
|
|
23
23
|
};
|
|
24
24
|
return [
|
|
25
|
+
{
|
|
26
|
+
name: "vite:react-swc:resolve-runtime",
|
|
27
|
+
apply: "serve",
|
|
28
|
+
enforce: "pre",
|
|
29
|
+
// Run before Vite default resolve to avoid syscalls
|
|
30
|
+
resolveId: (id) => id === runtimePublicPath ? id : void 0,
|
|
31
|
+
load: (id) => id === runtimePublicPath ? (0, import_fs.readFileSync)((0, import_path.join)(_dirname, "refresh-runtime.js"), "utf-8") : void 0
|
|
32
|
+
},
|
|
25
33
|
{
|
|
26
34
|
name: "vite:react-swc",
|
|
27
35
|
apply: "serve",
|
|
@@ -31,8 +39,6 @@ var react = (_options) => {
|
|
|
31
39
|
include: [`${options.jsxImportSource}/jsx-dev-runtime`]
|
|
32
40
|
}
|
|
33
41
|
}),
|
|
34
|
-
resolveId: (id) => id === runtimePublicPath ? id : void 0,
|
|
35
|
-
load: (id) => id === runtimePublicPath ? (0, import_fs.readFileSync)((0, import_path.join)(_dirname, "refresh-runtime.js"), "utf-8") : void 0,
|
|
36
42
|
transformIndexHtml: (_, config) => [
|
|
37
43
|
{
|
|
38
44
|
tag: "script",
|
|
@@ -45,10 +51,9 @@ var react = (_options) => {
|
|
|
45
51
|
],
|
|
46
52
|
async transform(code, _id, transformOptions) {
|
|
47
53
|
const id = _id.split("?")[0];
|
|
48
|
-
const result = await transformWithOptions(id, code, options, {
|
|
54
|
+
const result = await transformWithOptions(id, code, "es2020", options, {
|
|
49
55
|
refresh: !(transformOptions == null ? void 0 : transformOptions.ssr),
|
|
50
56
|
development: true,
|
|
51
|
-
useBuiltins: true,
|
|
52
57
|
runtime: "automatic",
|
|
53
58
|
importSource: options.jsxImportSource
|
|
54
59
|
});
|
|
@@ -69,7 +74,7 @@ ${result.code}
|
|
|
69
74
|
|
|
70
75
|
window.$RefreshReg$ = prevRefreshReg;
|
|
71
76
|
window.$RefreshSig$ = prevRefreshSig;
|
|
72
|
-
|
|
77
|
+
RefreshRuntime.__hmr_import(import.meta.url).then((currentExports) => {
|
|
73
78
|
RefreshRuntime.registerExportsForReactRefresh("${id}", currentExports);
|
|
74
79
|
import.meta.hot.accept((nextExports) => {
|
|
75
80
|
if (!nextExports) return;
|
|
@@ -88,15 +93,18 @@ import(/* @vite-ignore */ import.meta.url).then((currentExports) => {
|
|
|
88
93
|
apply: "build",
|
|
89
94
|
enforce: "pre",
|
|
90
95
|
// Run before esbuild
|
|
91
|
-
|
|
92
|
-
|
|
96
|
+
config: (userConfig) => ({
|
|
97
|
+
build: silenceUseClientWarning(userConfig)
|
|
98
|
+
}),
|
|
99
|
+
transform: (code, _id) => transformWithOptions(_id.split("?")[0], code, "esnext", options, {
|
|
93
100
|
runtime: "automatic",
|
|
94
101
|
importSource: options.jsxImportSource
|
|
95
102
|
})
|
|
96
103
|
} : {
|
|
97
104
|
name: "vite:react-swc",
|
|
98
105
|
apply: "build",
|
|
99
|
-
config: () => ({
|
|
106
|
+
config: (userConfig) => ({
|
|
107
|
+
build: silenceUseClientWarning(userConfig),
|
|
100
108
|
esbuild: {
|
|
101
109
|
jsx: "automatic",
|
|
102
110
|
jsxImportSource: options.jsxImportSource,
|
|
@@ -108,9 +116,7 @@ import(/* @vite-ignore */ import.meta.url).then((currentExports) => {
|
|
|
108
116
|
}
|
|
109
117
|
];
|
|
110
118
|
};
|
|
111
|
-
var transformWithOptions = async (id, code, options, reactConfig) => {
|
|
112
|
-
if (id.includes("node_modules"))
|
|
113
|
-
return;
|
|
119
|
+
var transformWithOptions = async (id, code, target, options, reactConfig) => {
|
|
114
120
|
const decorators = (options == null ? void 0 : options.tsDecorators) ?? false;
|
|
115
121
|
const parser = id.endsWith(".tsx") ? { syntax: "typescript", tsx: true, decorators } : id.endsWith(".ts") ? { syntax: "typescript", tsx: false, decorators } : id.endsWith(".jsx") ? { syntax: "ecmascript", jsx: true } : id.endsWith(".mdx") ? (
|
|
116
122
|
// JSX is required to trigger fast refresh transformations, even if MDX already transforms it
|
|
@@ -126,7 +132,7 @@ var transformWithOptions = async (id, code, options, reactConfig) => {
|
|
|
126
132
|
configFile: false,
|
|
127
133
|
sourceMaps: true,
|
|
128
134
|
jsc: {
|
|
129
|
-
target
|
|
135
|
+
target,
|
|
130
136
|
parser,
|
|
131
137
|
experimental: { plugins: options.plugins },
|
|
132
138
|
transform: {
|
|
@@ -149,6 +155,21 @@ var transformWithOptions = async (id, code, options, reactConfig) => {
|
|
|
149
155
|
}
|
|
150
156
|
return result;
|
|
151
157
|
};
|
|
158
|
+
var silenceUseClientWarning = (userConfig) => ({
|
|
159
|
+
rollupOptions: {
|
|
160
|
+
onwarn(warning, defaultHandler) {
|
|
161
|
+
var _a, _b;
|
|
162
|
+
if (warning.code === "MODULE_LEVEL_DIRECTIVE" && warning.message.includes("use client")) {
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
if ((_b = (_a = userConfig.build) == null ? void 0 : _a.rollupOptions) == null ? void 0 : _b.onwarn) {
|
|
166
|
+
userConfig.build.rollupOptions.onwarn(warning, defaultHandler);
|
|
167
|
+
} else {
|
|
168
|
+
defaultHandler(warning);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
});
|
|
152
173
|
var src_default = react;
|
|
153
174
|
|
|
154
175
|
// <stdin>
|
package/index.mjs
CHANGED
|
@@ -2,7 +2,9 @@
|
|
|
2
2
|
import { readFileSync } from "fs";
|
|
3
3
|
import { dirname, join } from "path";
|
|
4
4
|
import { fileURLToPath } from "url";
|
|
5
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
transform
|
|
7
|
+
} from "@swc/core";
|
|
6
8
|
import { createRequire } from "module";
|
|
7
9
|
var runtimePublicPath = "/@react-refresh";
|
|
8
10
|
var preambleCode = `import { injectIntoGlobalHook } from "__PATH__";
|
|
@@ -21,6 +23,14 @@ var react = (_options) => {
|
|
|
21
23
|
plugins: (_options == null ? void 0 : _options.plugins) ? _options == null ? void 0 : _options.plugins.map((el) => [resolve(el[0]), el[1]]) : void 0
|
|
22
24
|
};
|
|
23
25
|
return [
|
|
26
|
+
{
|
|
27
|
+
name: "vite:react-swc:resolve-runtime",
|
|
28
|
+
apply: "serve",
|
|
29
|
+
enforce: "pre",
|
|
30
|
+
// Run before Vite default resolve to avoid syscalls
|
|
31
|
+
resolveId: (id) => id === runtimePublicPath ? id : void 0,
|
|
32
|
+
load: (id) => id === runtimePublicPath ? readFileSync(join(_dirname, "refresh-runtime.js"), "utf-8") : void 0
|
|
33
|
+
},
|
|
24
34
|
{
|
|
25
35
|
name: "vite:react-swc",
|
|
26
36
|
apply: "serve",
|
|
@@ -30,8 +40,6 @@ var react = (_options) => {
|
|
|
30
40
|
include: [`${options.jsxImportSource}/jsx-dev-runtime`]
|
|
31
41
|
}
|
|
32
42
|
}),
|
|
33
|
-
resolveId: (id) => id === runtimePublicPath ? id : void 0,
|
|
34
|
-
load: (id) => id === runtimePublicPath ? readFileSync(join(_dirname, "refresh-runtime.js"), "utf-8") : void 0,
|
|
35
43
|
transformIndexHtml: (_, config) => [
|
|
36
44
|
{
|
|
37
45
|
tag: "script",
|
|
@@ -44,10 +52,9 @@ var react = (_options) => {
|
|
|
44
52
|
],
|
|
45
53
|
async transform(code, _id, transformOptions) {
|
|
46
54
|
const id = _id.split("?")[0];
|
|
47
|
-
const result = await transformWithOptions(id, code, options, {
|
|
55
|
+
const result = await transformWithOptions(id, code, "es2020", options, {
|
|
48
56
|
refresh: !(transformOptions == null ? void 0 : transformOptions.ssr),
|
|
49
57
|
development: true,
|
|
50
|
-
useBuiltins: true,
|
|
51
58
|
runtime: "automatic",
|
|
52
59
|
importSource: options.jsxImportSource
|
|
53
60
|
});
|
|
@@ -68,7 +75,7 @@ ${result.code}
|
|
|
68
75
|
|
|
69
76
|
window.$RefreshReg$ = prevRefreshReg;
|
|
70
77
|
window.$RefreshSig$ = prevRefreshSig;
|
|
71
|
-
|
|
78
|
+
RefreshRuntime.__hmr_import(import.meta.url).then((currentExports) => {
|
|
72
79
|
RefreshRuntime.registerExportsForReactRefresh("${id}", currentExports);
|
|
73
80
|
import.meta.hot.accept((nextExports) => {
|
|
74
81
|
if (!nextExports) return;
|
|
@@ -87,15 +94,18 @@ import(/* @vite-ignore */ import.meta.url).then((currentExports) => {
|
|
|
87
94
|
apply: "build",
|
|
88
95
|
enforce: "pre",
|
|
89
96
|
// Run before esbuild
|
|
90
|
-
|
|
91
|
-
|
|
97
|
+
config: (userConfig) => ({
|
|
98
|
+
build: silenceUseClientWarning(userConfig)
|
|
99
|
+
}),
|
|
100
|
+
transform: (code, _id) => transformWithOptions(_id.split("?")[0], code, "esnext", options, {
|
|
92
101
|
runtime: "automatic",
|
|
93
102
|
importSource: options.jsxImportSource
|
|
94
103
|
})
|
|
95
104
|
} : {
|
|
96
105
|
name: "vite:react-swc",
|
|
97
106
|
apply: "build",
|
|
98
|
-
config: () => ({
|
|
107
|
+
config: (userConfig) => ({
|
|
108
|
+
build: silenceUseClientWarning(userConfig),
|
|
99
109
|
esbuild: {
|
|
100
110
|
jsx: "automatic",
|
|
101
111
|
jsxImportSource: options.jsxImportSource,
|
|
@@ -107,9 +117,7 @@ import(/* @vite-ignore */ import.meta.url).then((currentExports) => {
|
|
|
107
117
|
}
|
|
108
118
|
];
|
|
109
119
|
};
|
|
110
|
-
var transformWithOptions = async (id, code, options, reactConfig) => {
|
|
111
|
-
if (id.includes("node_modules"))
|
|
112
|
-
return;
|
|
120
|
+
var transformWithOptions = async (id, code, target, options, reactConfig) => {
|
|
113
121
|
const decorators = (options == null ? void 0 : options.tsDecorators) ?? false;
|
|
114
122
|
const parser = id.endsWith(".tsx") ? { syntax: "typescript", tsx: true, decorators } : id.endsWith(".ts") ? { syntax: "typescript", tsx: false, decorators } : id.endsWith(".jsx") ? { syntax: "ecmascript", jsx: true } : id.endsWith(".mdx") ? (
|
|
115
123
|
// JSX is required to trigger fast refresh transformations, even if MDX already transforms it
|
|
@@ -125,7 +133,7 @@ var transformWithOptions = async (id, code, options, reactConfig) => {
|
|
|
125
133
|
configFile: false,
|
|
126
134
|
sourceMaps: true,
|
|
127
135
|
jsc: {
|
|
128
|
-
target
|
|
136
|
+
target,
|
|
129
137
|
parser,
|
|
130
138
|
experimental: { plugins: options.plugins },
|
|
131
139
|
transform: {
|
|
@@ -148,6 +156,21 @@ var transformWithOptions = async (id, code, options, reactConfig) => {
|
|
|
148
156
|
}
|
|
149
157
|
return result;
|
|
150
158
|
};
|
|
159
|
+
var silenceUseClientWarning = (userConfig) => ({
|
|
160
|
+
rollupOptions: {
|
|
161
|
+
onwarn(warning, defaultHandler) {
|
|
162
|
+
var _a, _b;
|
|
163
|
+
if (warning.code === "MODULE_LEVEL_DIRECTIVE" && warning.message.includes("use client")) {
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
if ((_b = (_a = userConfig.build) == null ? void 0 : _a.rollupOptions) == null ? void 0 : _b.onwarn) {
|
|
167
|
+
userConfig.build.rollupOptions.onwarn(warning, defaultHandler);
|
|
168
|
+
} else {
|
|
169
|
+
defaultHandler(warning);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
});
|
|
151
174
|
var src_default = react;
|
|
152
175
|
export {
|
|
153
176
|
src_default as default
|
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.3.0",
|
|
5
5
|
"author": "Arnaud Barré (https://github.com/ArnaudBarre)",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"repository": "github:vitejs/vite-plugin-react-swc",
|
|
@@ -27,6 +27,6 @@
|
|
|
27
27
|
"vite": "^4"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@swc/core": "^1.3.
|
|
30
|
+
"@swc/core": "^1.3.42"
|
|
31
31
|
}
|
|
32
32
|
}
|
package/refresh-runtime.js
CHANGED
|
@@ -364,6 +364,11 @@ function isLikelyComponentType(type) {
|
|
|
364
364
|
}
|
|
365
365
|
}
|
|
366
366
|
}
|
|
367
|
+
if (window.$RefreshReg$) {
|
|
368
|
+
throw new Error(
|
|
369
|
+
"React refresh runtime was loaded twice. Maybe you forgot the base path?"
|
|
370
|
+
);
|
|
371
|
+
}
|
|
367
372
|
function getRefreshReg(filename) {
|
|
368
373
|
return (type, id) => register(type, filename + " " + id);
|
|
369
374
|
}
|
|
@@ -373,7 +378,7 @@ function registerExportsForReactRefresh(filename, moduleExports) {
|
|
|
373
378
|
continue;
|
|
374
379
|
const exportValue = moduleExports[key];
|
|
375
380
|
if (isLikelyComponentType(exportValue)) {
|
|
376
|
-
register(exportValue, filename + " " + key);
|
|
381
|
+
register(exportValue, filename + " export " + key);
|
|
377
382
|
}
|
|
378
383
|
}
|
|
379
384
|
}
|
|
@@ -419,8 +424,13 @@ function predicateOnExport(moduleExports, predicate) {
|
|
|
419
424
|
}
|
|
420
425
|
return true;
|
|
421
426
|
}
|
|
427
|
+
const __hmr_import = (module) => import(
|
|
428
|
+
/* @vite-ignore */
|
|
429
|
+
module
|
|
430
|
+
);
|
|
422
431
|
var refresh_runtime_default = { injectIntoGlobalHook };
|
|
423
432
|
export {
|
|
433
|
+
__hmr_import,
|
|
424
434
|
createSignatureFunctionForTransform,
|
|
425
435
|
refresh_runtime_default as default,
|
|
426
436
|
getRefreshReg,
|