@rspack/plugin-react-refresh 0.3.4 → 0.3.5
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/client/reactRefreshEntry.js +51 -3
- package/package.json +14 -4
- package/src/index.js +33 -3
- package/src/options.js +17 -0
- package/src/options.json +33 -0
@@ -1,4 +1,52 @@
|
|
1
|
-
|
1
|
+
/**
|
2
|
+
* The following code is modified based on
|
3
|
+
* https://github.com/pmmmwh/react-refresh-webpack-plugin/blob/0b960573797bf38926937994c481e4fec9ed8aa6/client/ReactRefreshEntry.js
|
4
|
+
*
|
5
|
+
* MIT Licensed
|
6
|
+
* Author Michael Mok
|
7
|
+
* Copyright (c) 2019 Michael Mok
|
8
|
+
* https://github.com/pmmmwh/react-refresh-webpack-plugin/blob/0b960573797bf38926937994c481e4fec9ed8aa6/LICENSE
|
9
|
+
*/
|
2
10
|
|
3
|
-
RefreshRuntime
|
4
|
-
|
11
|
+
var RefreshRuntime = require("react-refresh/runtime");
|
12
|
+
var safeThis = (function () {
|
13
|
+
// copied from core-js-pure/features/global-this
|
14
|
+
"use strict";
|
15
|
+
|
16
|
+
var check = function (it) {
|
17
|
+
return it && it.Math == Math && it;
|
18
|
+
};
|
19
|
+
|
20
|
+
// https://github.com/zloirock/core-js/issues/86#issuecomment-115759028
|
21
|
+
// eslint-disable-next-line es/no-global-this -- safe
|
22
|
+
return (
|
23
|
+
check(typeof globalThis == "object" && globalThis) ||
|
24
|
+
check(typeof window == "object" && window) ||
|
25
|
+
// eslint-disable-next-line no-restricted-globals -- safe
|
26
|
+
check(typeof self == "object" && self) ||
|
27
|
+
check(typeof __webpack_require__.g == "object" && __webpack_require__.g) ||
|
28
|
+
// eslint-disable-next-line no-new-func -- fallback
|
29
|
+
(function () {
|
30
|
+
return this;
|
31
|
+
})() ||
|
32
|
+
this ||
|
33
|
+
Function("return this")()
|
34
|
+
);
|
35
|
+
})();
|
36
|
+
|
37
|
+
if (process.env.NODE_ENV !== "production") {
|
38
|
+
if (typeof safeThis !== "undefined") {
|
39
|
+
var $RefreshInjected$ = "__reactRefreshInjected";
|
40
|
+
// Only inject the runtime if it hasn't been injected
|
41
|
+
if (!safeThis[$RefreshInjected$]) {
|
42
|
+
RefreshRuntime.injectIntoGlobalHook(safeThis);
|
43
|
+
|
44
|
+
// Empty implementation to avoid "ReferenceError: variable is not defined" in module which didn't pass builtin:react-refresh-loader
|
45
|
+
safeThis.$RefreshSig$ = () => type => type;
|
46
|
+
safeThis.$RefreshReg$ = () => {};
|
47
|
+
|
48
|
+
// Mark the runtime as injected to prevent double-injection
|
49
|
+
safeThis[$RefreshInjected$] = true;
|
50
|
+
}
|
51
|
+
}
|
52
|
+
}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@rspack/plugin-react-refresh",
|
3
|
-
"version": "0.3.
|
3
|
+
"version": "0.3.5",
|
4
4
|
"license": "MIT",
|
5
5
|
"description": "React refresh plugin for rspack",
|
6
6
|
"main": "src/index.js",
|
@@ -24,10 +24,13 @@
|
|
24
24
|
"directory": "packages/rspack-plugin-react-refresh"
|
25
25
|
},
|
26
26
|
"dependencies": {
|
27
|
-
"@pmmmwh/react-refresh-webpack-plugin": "0.5.10"
|
27
|
+
"@pmmmwh/react-refresh-webpack-plugin": "0.5.10",
|
28
|
+
"schema-utils": "^4.0.0"
|
28
29
|
},
|
29
30
|
"devDependencies": {
|
30
|
-
"react-refresh": "0.14.0"
|
31
|
+
"react-refresh": "0.14.0",
|
32
|
+
"@rspack/core": "0.3.5",
|
33
|
+
"@rspack/plugin-react-refresh": "0.3.5"
|
31
34
|
},
|
32
35
|
"peerDependencies": {
|
33
36
|
"react-refresh": ">=0.10.0 <1.0.0"
|
@@ -37,7 +40,14 @@
|
|
37
40
|
"optional": true
|
38
41
|
}
|
39
42
|
},
|
43
|
+
"jest": {
|
44
|
+
"watchPathIgnorePatterns": [
|
45
|
+
"<rootDir>/dist",
|
46
|
+
"<rootDir>/tests/dist"
|
47
|
+
],
|
48
|
+
"testEnvironment": "../../scripts/test/patch-node-env.cjs"
|
49
|
+
},
|
40
50
|
"scripts": {
|
41
|
-
"test": "
|
51
|
+
"test": "jest --runInBand"
|
42
52
|
}
|
43
53
|
}
|
package/src/index.js
CHANGED
@@ -1,6 +1,11 @@
|
|
1
1
|
const path = require("path");
|
2
|
+
const { validate: validateOptions } = require("schema-utils");
|
3
|
+
|
2
4
|
const reactRefreshPath = require.resolve("../client/reactRefresh.js");
|
3
5
|
const reactRefreshEntryPath = require.resolve("../client/reactRefreshEntry.js");
|
6
|
+
const schema = require("./options.json");
|
7
|
+
const { normalizeOptions } = require("./options");
|
8
|
+
|
4
9
|
const refreshUtilsPath = require.resolve(
|
5
10
|
"@pmmmwh/react-refresh-webpack-plugin/lib/runtime/RefreshUtils",
|
6
11
|
{
|
@@ -13,12 +18,32 @@ const refreshRuntimeDirPath = path.dirname(
|
|
13
18
|
})
|
14
19
|
);
|
15
20
|
const runtimePaths = [
|
21
|
+
reactRefreshEntryPath,
|
16
22
|
reactRefreshPath,
|
17
23
|
refreshUtilsPath,
|
18
24
|
refreshRuntimeDirPath
|
19
25
|
];
|
20
26
|
|
27
|
+
/**
|
28
|
+
* @typedef {Object} Options
|
29
|
+
* @property {(string | RegExp | (string | RegExp)[] | null)=} include included resourcePath for loader
|
30
|
+
* @property {(string | RegExp | (string | RegExp)[] | null)=} exclude excluded resourcePath for loader
|
31
|
+
*/
|
32
|
+
|
21
33
|
module.exports = class ReactRefreshRspackPlugin {
|
34
|
+
/**
|
35
|
+
* @param {Options} options
|
36
|
+
*/
|
37
|
+
constructor(options = {}) {
|
38
|
+
validateOptions(schema, options, {
|
39
|
+
name: "React Refresh Rspack Plugin",
|
40
|
+
baseDataPath: "options"
|
41
|
+
});
|
42
|
+
/**
|
43
|
+
* @type {Options}
|
44
|
+
*/
|
45
|
+
this.options = normalizeOptions(options);
|
46
|
+
}
|
22
47
|
apply(compiler) {
|
23
48
|
new compiler.webpack.EntryPlugin(compiler.context, reactRefreshEntryPath, {
|
24
49
|
name: undefined
|
@@ -27,9 +52,14 @@ module.exports = class ReactRefreshRspackPlugin {
|
|
27
52
|
$ReactRefreshRuntime$: reactRefreshPath
|
28
53
|
}).apply(compiler);
|
29
54
|
|
30
|
-
compiler.options.module.rules.
|
31
|
-
include:
|
32
|
-
|
55
|
+
compiler.options.module.rules.unshift({
|
56
|
+
include: this.options.include,
|
57
|
+
exclude: {
|
58
|
+
or: [this.options.exclude, [...runtimePaths]].filter(Boolean)
|
59
|
+
},
|
60
|
+
use: "builtin:react-refresh-loader"
|
33
61
|
});
|
34
62
|
}
|
35
63
|
};
|
64
|
+
|
65
|
+
module.exports.deprecated_runtimePaths = runtimePaths;
|
package/src/options.js
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
const d = (object, property, defaultValue) => {
|
2
|
+
if (
|
3
|
+
typeof object[property] === "undefined" &&
|
4
|
+
typeof defaultValue !== "undefined"
|
5
|
+
) {
|
6
|
+
object[property] = defaultValue;
|
7
|
+
}
|
8
|
+
return object[property];
|
9
|
+
};
|
10
|
+
|
11
|
+
const normalizeOptions = function (options) {
|
12
|
+
d(options, "exclude", /node_modules/i);
|
13
|
+
d(options, "include", /\.([cm]js|[jt]sx?|flow)$/i);
|
14
|
+
return options;
|
15
|
+
};
|
16
|
+
|
17
|
+
module.exports = { normalizeOptions };
|
package/src/options.json
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
{
|
2
|
+
"additionalProperties": false,
|
3
|
+
"type": "object",
|
4
|
+
"definitions": {
|
5
|
+
"Path": { "type": "string" },
|
6
|
+
"MatchCondition": {
|
7
|
+
"anyOf": [
|
8
|
+
{ "instanceof": "RegExp" },
|
9
|
+
{ "$ref": "#/definitions/Path" },
|
10
|
+
{ "type": "null" }
|
11
|
+
]
|
12
|
+
},
|
13
|
+
"MatchConditions": {
|
14
|
+
"type": "array",
|
15
|
+
"items": { "$ref": "#/definitions/MatchCondition" },
|
16
|
+
"minItems": 1
|
17
|
+
}
|
18
|
+
},
|
19
|
+
"properties": {
|
20
|
+
"exclude": {
|
21
|
+
"anyOf": [
|
22
|
+
{ "$ref": "#/definitions/MatchCondition" },
|
23
|
+
{ "$ref": "#/definitions/MatchConditions" }
|
24
|
+
]
|
25
|
+
},
|
26
|
+
"include": {
|
27
|
+
"anyOf": [
|
28
|
+
{ "$ref": "#/definitions/MatchCondition" },
|
29
|
+
{ "$ref": "#/definitions/MatchConditions" }
|
30
|
+
]
|
31
|
+
}
|
32
|
+
}
|
33
|
+
}
|