@rspack/plugin-react-refresh 0.3.9 → 0.3.10
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/dist/index.d.ts +15 -0
- package/dist/index.js +58 -0
- package/dist/options.d.ts +5 -0
- package/dist/options.js +16 -0
- package/package.json +13 -6
- package/src/index.js +0 -75
- package/src/options.js +0 -17
- /package/{src/options.json → options.json} +0 -0
package/dist/index.d.ts
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
import type { Compiler } from "@rspack/core";
|
2
|
+
import { type PluginOptions } from "./options";
|
3
|
+
export type { PluginOptions };
|
4
|
+
/**
|
5
|
+
* @typedef {Object} Options
|
6
|
+
* @property {(string | RegExp | (string | RegExp)[] | null)=} include included resourcePath for loader
|
7
|
+
* @property {(string | RegExp | (string | RegExp)[] | null)=} exclude excluded resourcePath for loader
|
8
|
+
*/
|
9
|
+
declare class ReactRefreshRspackPlugin {
|
10
|
+
options: PluginOptions;
|
11
|
+
static deprecated_runtimePaths: string[];
|
12
|
+
constructor(options?: PluginOptions);
|
13
|
+
apply(compiler: Compiler): void;
|
14
|
+
}
|
15
|
+
export = ReactRefreshRspackPlugin;
|
package/dist/index.js
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
|
+
};
|
5
|
+
const path_1 = __importDefault(require("path"));
|
6
|
+
const options_1 = require("./options");
|
7
|
+
const schema_utils_1 = require("schema-utils");
|
8
|
+
const reactRefreshPath = require.resolve("../client/reactRefresh.js");
|
9
|
+
const reactRefreshEntryPath = require.resolve("../client/reactRefreshEntry.js");
|
10
|
+
const schema = require("../options.json");
|
11
|
+
const refreshUtilsPath = require.resolve("@pmmmwh/react-refresh-webpack-plugin/lib/runtime/RefreshUtils", {
|
12
|
+
paths: [reactRefreshPath]
|
13
|
+
});
|
14
|
+
const refreshRuntimeDirPath = path_1.default.dirname(require.resolve("react-refresh", {
|
15
|
+
paths: [reactRefreshPath]
|
16
|
+
}));
|
17
|
+
const runtimePaths = [
|
18
|
+
reactRefreshEntryPath,
|
19
|
+
reactRefreshPath,
|
20
|
+
refreshUtilsPath,
|
21
|
+
refreshRuntimeDirPath
|
22
|
+
];
|
23
|
+
/**
|
24
|
+
* @typedef {Object} Options
|
25
|
+
* @property {(string | RegExp | (string | RegExp)[] | null)=} include included resourcePath for loader
|
26
|
+
* @property {(string | RegExp | (string | RegExp)[] | null)=} exclude excluded resourcePath for loader
|
27
|
+
*/
|
28
|
+
class ReactRefreshRspackPlugin {
|
29
|
+
constructor(options = {}) {
|
30
|
+
(0, schema_utils_1.validate)(schema, options, {
|
31
|
+
name: "React Refresh Rspack Plugin",
|
32
|
+
baseDataPath: "options"
|
33
|
+
});
|
34
|
+
this.options = (0, options_1.normalizeOptions)(options);
|
35
|
+
}
|
36
|
+
apply(compiler) {
|
37
|
+
new compiler.webpack.EntryPlugin(compiler.context, reactRefreshEntryPath, {
|
38
|
+
name: undefined
|
39
|
+
}).apply(compiler);
|
40
|
+
new compiler.webpack.ProvidePlugin({
|
41
|
+
$ReactRefreshRuntime$: reactRefreshPath
|
42
|
+
}).apply(compiler);
|
43
|
+
compiler.options.module.rules.unshift({
|
44
|
+
include: this.options.include,
|
45
|
+
exclude: {
|
46
|
+
or: [this.options.exclude, [...runtimePaths]].filter(Boolean)
|
47
|
+
},
|
48
|
+
use: "builtin:react-refresh-loader"
|
49
|
+
});
|
50
|
+
const refreshPath = path_1.default.dirname(require.resolve("react-refresh"));
|
51
|
+
compiler.options.resolve.alias = {
|
52
|
+
"react-refresh": refreshPath,
|
53
|
+
...compiler.options.resolve.alias
|
54
|
+
};
|
55
|
+
}
|
56
|
+
}
|
57
|
+
ReactRefreshRspackPlugin.deprecated_runtimePaths = runtimePaths;
|
58
|
+
module.exports = ReactRefreshRspackPlugin;
|
package/dist/options.js
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.normalizeOptions = void 0;
|
4
|
+
const d = (object, property, defaultValue) => {
|
5
|
+
if (typeof object[property] === "undefined" &&
|
6
|
+
typeof defaultValue !== "undefined") {
|
7
|
+
object[property] = defaultValue;
|
8
|
+
}
|
9
|
+
return object[property];
|
10
|
+
};
|
11
|
+
function normalizeOptions(options) {
|
12
|
+
d(options, "exclude", /node_modules/i);
|
13
|
+
d(options, "include", /\.([cm]js|[jt]sx?|flow)$/i);
|
14
|
+
return options;
|
15
|
+
}
|
16
|
+
exports.normalizeOptions = normalizeOptions;
|
package/package.json
CHANGED
@@ -1,17 +1,22 @@
|
|
1
1
|
{
|
2
2
|
"name": "@rspack/plugin-react-refresh",
|
3
|
-
"version": "0.3.
|
3
|
+
"version": "0.3.10",
|
4
4
|
"license": "MIT",
|
5
5
|
"description": "React refresh plugin for rspack",
|
6
|
-
"main": "
|
6
|
+
"main": "dist/index.js",
|
7
|
+
"types": "dist/index.d.ts",
|
7
8
|
"exports": {
|
8
|
-
".":
|
9
|
+
".": {
|
10
|
+
"types": "./dist/index.d.ts",
|
11
|
+
"default": "./dist/index.js"
|
12
|
+
},
|
9
13
|
"./react-refresh": "./client/reactRefresh.js",
|
10
14
|
"./react-refresh-entry": "./client/reactRefreshEntry.js"
|
11
15
|
},
|
12
16
|
"files": [
|
13
17
|
"client",
|
14
|
-
"
|
18
|
+
"dist",
|
19
|
+
"options.json"
|
15
20
|
],
|
16
21
|
"publishConfig": {
|
17
22
|
"access": "public"
|
@@ -29,8 +34,8 @@
|
|
29
34
|
},
|
30
35
|
"devDependencies": {
|
31
36
|
"react-refresh": "0.14.0",
|
32
|
-
"@rspack/core": "0.3.
|
33
|
-
"@rspack/plugin-react-refresh": "0.3.
|
37
|
+
"@rspack/core": "0.3.10",
|
38
|
+
"@rspack/plugin-react-refresh": "0.3.10"
|
34
39
|
},
|
35
40
|
"peerDependencies": {
|
36
41
|
"react-refresh": ">=0.10.0 <1.0.0"
|
@@ -48,6 +53,8 @@
|
|
48
53
|
"testEnvironment": "../../scripts/test/patch-node-env.cjs"
|
49
54
|
},
|
50
55
|
"scripts": {
|
56
|
+
"build": "rimraf dist/ && tsc -b ./tsconfig.build.json --force",
|
57
|
+
"dev": "tsc -b -w",
|
51
58
|
"test": "jest --runInBand"
|
52
59
|
}
|
53
60
|
}
|
package/src/index.js
DELETED
@@ -1,75 +0,0 @@
|
|
1
|
-
const path = require("path");
|
2
|
-
const { validate: validateOptions } = require("schema-utils");
|
3
|
-
|
4
|
-
const reactRefreshPath = require.resolve("../client/reactRefresh.js");
|
5
|
-
const reactRefreshEntryPath = require.resolve("../client/reactRefreshEntry.js");
|
6
|
-
const schema = require("./options.json");
|
7
|
-
const { normalizeOptions } = require("./options");
|
8
|
-
|
9
|
-
const refreshUtilsPath = require.resolve(
|
10
|
-
"@pmmmwh/react-refresh-webpack-plugin/lib/runtime/RefreshUtils",
|
11
|
-
{
|
12
|
-
paths: [reactRefreshPath]
|
13
|
-
}
|
14
|
-
);
|
15
|
-
const refreshRuntimeDirPath = path.dirname(
|
16
|
-
require.resolve("react-refresh", {
|
17
|
-
paths: [reactRefreshPath]
|
18
|
-
})
|
19
|
-
);
|
20
|
-
const runtimePaths = [
|
21
|
-
reactRefreshEntryPath,
|
22
|
-
reactRefreshPath,
|
23
|
-
refreshUtilsPath,
|
24
|
-
refreshRuntimeDirPath
|
25
|
-
];
|
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
|
-
|
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
|
-
}
|
47
|
-
|
48
|
-
/**
|
49
|
-
* @param {import("@rspack/core").Compiler} compiler
|
50
|
-
*/
|
51
|
-
apply(compiler) {
|
52
|
-
new compiler.webpack.EntryPlugin(compiler.context, reactRefreshEntryPath, {
|
53
|
-
name: undefined
|
54
|
-
}).apply(compiler);
|
55
|
-
new compiler.webpack.ProvidePlugin({
|
56
|
-
$ReactRefreshRuntime$: reactRefreshPath
|
57
|
-
}).apply(compiler);
|
58
|
-
|
59
|
-
compiler.options.module.rules.unshift({
|
60
|
-
include: this.options.include,
|
61
|
-
exclude: {
|
62
|
-
or: [this.options.exclude, [...runtimePaths]].filter(Boolean)
|
63
|
-
},
|
64
|
-
use: "builtin:react-refresh-loader"
|
65
|
-
});
|
66
|
-
|
67
|
-
const refreshPath = path.dirname(require.resolve("react-refresh"));
|
68
|
-
compiler.options.resolve.alias = {
|
69
|
-
"react-refresh": refreshPath,
|
70
|
-
...compiler.options.resolve.alias
|
71
|
-
};
|
72
|
-
}
|
73
|
-
};
|
74
|
-
|
75
|
-
module.exports.deprecated_runtimePaths = runtimePaths;
|
package/src/options.js
DELETED
@@ -1,17 +0,0 @@
|
|
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 };
|
File without changes
|