@vitejs/plugin-react-swc 3.0.0 → 3.0.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 +13 -0
- package/index.cjs +20 -32
- package/index.d.ts +8 -1
- package/index.mjs +16 -6
- package/package.json +3 -3
- package/refresh-runtime.js +7 -0
package/README.md
CHANGED
|
@@ -34,6 +34,19 @@ This plugin is only used in development and aims to be kept simple to enable goo
|
|
|
34
34
|
- JS files are not transformed
|
|
35
35
|
- tsconfig is not resolved, so properties other than the ones listed above behaves like TS defaults
|
|
36
36
|
|
|
37
|
+
## Changing the JSX import source
|
|
38
|
+
|
|
39
|
+
You can use the jsxImportSource option like this:
|
|
40
|
+
|
|
41
|
+
```ts
|
|
42
|
+
import { defineConfig } from "vite";
|
|
43
|
+
import react from "@vitejs/plugin-react-swc";
|
|
44
|
+
|
|
45
|
+
export default defineConfig({
|
|
46
|
+
plugins: [react({ jsxImportSource: "@emotion/react" })],
|
|
47
|
+
});
|
|
48
|
+
```
|
|
49
|
+
|
|
37
50
|
## Consistent components exports
|
|
38
51
|
|
|
39
52
|
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).
|
package/index.cjs
CHANGED
|
@@ -1,41 +1,17 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
1
|
// src/index.ts
|
|
21
|
-
var src_exports = {};
|
|
22
|
-
__export(src_exports, {
|
|
23
|
-
default: () => src_default
|
|
24
|
-
});
|
|
25
|
-
module.exports = __toCommonJS(src_exports);
|
|
26
2
|
var import_fs = require("fs");
|
|
27
3
|
var import_path = require("path");
|
|
28
4
|
var import_url = require("url");
|
|
29
5
|
var import_core = require("@swc/core");
|
|
30
6
|
var import_meta = {};
|
|
31
7
|
var runtimePublicPath = "/@react-refresh";
|
|
32
|
-
var preambleCode = `import { injectIntoGlobalHook } from "
|
|
8
|
+
var preambleCode = `import { injectIntoGlobalHook } from "__PATH__";
|
|
33
9
|
injectIntoGlobalHook(window);
|
|
34
10
|
window.$RefreshReg$ = () => {};
|
|
35
11
|
window.$RefreshSig$ = () => (type) => type;`;
|
|
36
12
|
var _dirname = typeof __dirname !== "undefined" ? __dirname : (0, import_path.dirname)((0, import_url.fileURLToPath)(import_meta.url));
|
|
37
13
|
var refreshContentRE = /\$Refresh(?:Reg|Sig)\$\(/;
|
|
38
|
-
var react = () => [
|
|
14
|
+
var react = (options) => [
|
|
39
15
|
{
|
|
40
16
|
name: "vite:react-swc",
|
|
41
17
|
apply: "serve",
|
|
@@ -45,10 +21,18 @@ var react = () => [
|
|
|
45
21
|
}),
|
|
46
22
|
resolveId: (id) => id === runtimePublicPath ? id : void 0,
|
|
47
23
|
load: (id) => id === runtimePublicPath ? (0, import_fs.readFileSync)((0, import_path.join)(_dirname, "refresh-runtime.js"), "utf-8") : void 0,
|
|
48
|
-
transformIndexHtml: () => [
|
|
49
|
-
{
|
|
24
|
+
transformIndexHtml: (_, config) => [
|
|
25
|
+
{
|
|
26
|
+
tag: "script",
|
|
27
|
+
attrs: { type: "module" },
|
|
28
|
+
children: preambleCode.replace(
|
|
29
|
+
"__PATH__",
|
|
30
|
+
config.server.config.base + runtimePublicPath.slice(1)
|
|
31
|
+
)
|
|
32
|
+
}
|
|
50
33
|
],
|
|
51
|
-
async transform(code,
|
|
34
|
+
async transform(code, _id, transformOptions) {
|
|
35
|
+
const id = _id.split("?")[0];
|
|
52
36
|
if (id.includes("node_modules"))
|
|
53
37
|
return;
|
|
54
38
|
const parser = id.endsWith(".tsx") ? { syntax: "typescript", tsx: true } : id.endsWith(".ts") ? { syntax: "typescript", tsx: false } : id.endsWith(".jsx") ? { syntax: "ecmascript", jsx: true } : void 0;
|
|
@@ -70,7 +54,8 @@ var react = () => [
|
|
|
70
54
|
refresh: !(transformOptions == null ? void 0 : transformOptions.ssr),
|
|
71
55
|
development: true,
|
|
72
56
|
useBuiltins: true,
|
|
73
|
-
runtime: "automatic"
|
|
57
|
+
runtime: "automatic",
|
|
58
|
+
importSource: options == null ? void 0 : options.jsxImportSource
|
|
74
59
|
}
|
|
75
60
|
}
|
|
76
61
|
}
|
|
@@ -121,11 +106,14 @@ var react = () => [
|
|
|
121
106
|
config: () => ({
|
|
122
107
|
esbuild: {
|
|
123
108
|
jsx: "automatic",
|
|
109
|
+
jsxImportSource: options == null ? void 0 : options.jsxImportSource,
|
|
124
110
|
tsconfigRaw: { compilerOptions: { useDefineForClassFields: true } }
|
|
125
111
|
}
|
|
126
112
|
})
|
|
127
113
|
}
|
|
128
114
|
];
|
|
129
115
|
var src_default = react;
|
|
130
|
-
|
|
131
|
-
|
|
116
|
+
|
|
117
|
+
// <stdin>
|
|
118
|
+
module.exports = src_default;
|
|
119
|
+
module.exports.default = src_default;
|
package/index.d.ts
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
1
|
import { PluginOption } from "vite";
|
|
2
|
-
|
|
2
|
+
type Options = {
|
|
3
|
+
/**
|
|
4
|
+
* Control where the JSX factory is imported from.
|
|
5
|
+
* @default "react"
|
|
6
|
+
*/
|
|
7
|
+
jsxImportSource?: string;
|
|
8
|
+
};
|
|
9
|
+
declare const react: (options?: Options) => PluginOption[];
|
|
3
10
|
export default react;
|
package/index.mjs
CHANGED
|
@@ -4,13 +4,13 @@ import { dirname, join } from "path";
|
|
|
4
4
|
import { fileURLToPath } from "url";
|
|
5
5
|
import { transform } from "@swc/core";
|
|
6
6
|
var runtimePublicPath = "/@react-refresh";
|
|
7
|
-
var preambleCode = `import { injectIntoGlobalHook } from "
|
|
7
|
+
var preambleCode = `import { injectIntoGlobalHook } from "__PATH__";
|
|
8
8
|
injectIntoGlobalHook(window);
|
|
9
9
|
window.$RefreshReg$ = () => {};
|
|
10
10
|
window.$RefreshSig$ = () => (type) => type;`;
|
|
11
11
|
var _dirname = typeof __dirname !== "undefined" ? __dirname : dirname(fileURLToPath(import.meta.url));
|
|
12
12
|
var refreshContentRE = /\$Refresh(?:Reg|Sig)\$\(/;
|
|
13
|
-
var react = () => [
|
|
13
|
+
var react = (options) => [
|
|
14
14
|
{
|
|
15
15
|
name: "vite:react-swc",
|
|
16
16
|
apply: "serve",
|
|
@@ -20,10 +20,18 @@ var react = () => [
|
|
|
20
20
|
}),
|
|
21
21
|
resolveId: (id) => id === runtimePublicPath ? id : void 0,
|
|
22
22
|
load: (id) => id === runtimePublicPath ? readFileSync(join(_dirname, "refresh-runtime.js"), "utf-8") : void 0,
|
|
23
|
-
transformIndexHtml: () => [
|
|
24
|
-
{
|
|
23
|
+
transformIndexHtml: (_, config) => [
|
|
24
|
+
{
|
|
25
|
+
tag: "script",
|
|
26
|
+
attrs: { type: "module" },
|
|
27
|
+
children: preambleCode.replace(
|
|
28
|
+
"__PATH__",
|
|
29
|
+
config.server.config.base + runtimePublicPath.slice(1)
|
|
30
|
+
)
|
|
31
|
+
}
|
|
25
32
|
],
|
|
26
|
-
async transform(code,
|
|
33
|
+
async transform(code, _id, transformOptions) {
|
|
34
|
+
const id = _id.split("?")[0];
|
|
27
35
|
if (id.includes("node_modules"))
|
|
28
36
|
return;
|
|
29
37
|
const parser = id.endsWith(".tsx") ? { syntax: "typescript", tsx: true } : id.endsWith(".ts") ? { syntax: "typescript", tsx: false } : id.endsWith(".jsx") ? { syntax: "ecmascript", jsx: true } : void 0;
|
|
@@ -45,7 +53,8 @@ var react = () => [
|
|
|
45
53
|
refresh: !(transformOptions == null ? void 0 : transformOptions.ssr),
|
|
46
54
|
development: true,
|
|
47
55
|
useBuiltins: true,
|
|
48
|
-
runtime: "automatic"
|
|
56
|
+
runtime: "automatic",
|
|
57
|
+
importSource: options == null ? void 0 : options.jsxImportSource
|
|
49
58
|
}
|
|
50
59
|
}
|
|
51
60
|
}
|
|
@@ -96,6 +105,7 @@ var react = () => [
|
|
|
96
105
|
config: () => ({
|
|
97
106
|
esbuild: {
|
|
98
107
|
jsx: "automatic",
|
|
108
|
+
jsxImportSource: options == null ? void 0 : options.jsxImportSource,
|
|
99
109
|
tsconfigRaw: { compilerOptions: { useDefineForClassFields: true } }
|
|
100
110
|
}
|
|
101
111
|
})
|
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.0.
|
|
4
|
+
"version": "3.0.1",
|
|
5
5
|
"author": "Arnaud Barré (https://github.com/ArnaudBarre)",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"repository": "github:vitejs/vite-plugin-react-swc",
|
|
@@ -24,9 +24,9 @@
|
|
|
24
24
|
"fast refresh"
|
|
25
25
|
],
|
|
26
26
|
"peerDependencies": {
|
|
27
|
-
"vite": "^4
|
|
27
|
+
"vite": "^4"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@swc/core": "^1.3.
|
|
30
|
+
"@swc/core": "^1.3.22"
|
|
31
31
|
}
|
|
32
32
|
}
|
package/refresh-runtime.js
CHANGED
|
@@ -409,8 +409,15 @@ function predicateOnExport(moduleExports, predicate) {
|
|
|
409
409
|
}
|
|
410
410
|
return true;
|
|
411
411
|
}
|
|
412
|
+
var refresh_runtime_default = {
|
|
413
|
+
getRefreshReg,
|
|
414
|
+
injectIntoGlobalHook,
|
|
415
|
+
createSignatureFunctionForTransform,
|
|
416
|
+
validateRefreshBoundaryAndEnqueueUpdate
|
|
417
|
+
};
|
|
412
418
|
export {
|
|
413
419
|
createSignatureFunctionForTransform,
|
|
420
|
+
refresh_runtime_default as default,
|
|
414
421
|
getRefreshReg,
|
|
415
422
|
injectIntoGlobalHook,
|
|
416
423
|
validateRefreshBoundaryAndEnqueueUpdate
|