@rsbuild/plugin-react 0.2.18 → 0.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/README.md +1 -1
- package/dist/index.js +7 -34
- package/dist/index.mjs +8 -41
- package/package.json +5 -5
package/README.md
CHANGED
package/dist/index.js
CHANGED
|
@@ -148,45 +148,17 @@ var applySplitChunksRule = (api, options = {
|
|
|
148
148
|
};
|
|
149
149
|
|
|
150
150
|
// src/react.ts
|
|
151
|
+
var import_node_path = __toESM(require("path"));
|
|
151
152
|
var import_shared4 = require("@rsbuild/shared");
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
const refresh = compiler.options.builtins?.react?.refresh ?? true;
|
|
155
|
-
if (hot && refresh) {
|
|
156
|
-
const reactRefreshEntryPath = require.resolve("@rspack/plugin-react-refresh/react-refresh-entry");
|
|
157
|
-
return reactRefreshEntryPath;
|
|
158
|
-
}
|
|
159
|
-
return null;
|
|
160
|
-
}
|
|
161
|
-
var setupCompiler = (compiler) => {
|
|
162
|
-
if (!(0, import_shared4.isClientCompiler)(compiler)) {
|
|
163
|
-
return;
|
|
164
|
-
}
|
|
165
|
-
const reactRefreshEntry = getReactRefreshEntry(compiler);
|
|
166
|
-
if (!reactRefreshEntry) {
|
|
167
|
-
return;
|
|
168
|
-
}
|
|
169
|
-
new compiler.webpack.EntryPlugin(compiler.context, reactRefreshEntry, {
|
|
170
|
-
name: void 0
|
|
171
|
-
}).apply(compiler);
|
|
172
|
-
};
|
|
153
|
+
var REACT_REFRESH_PATH = require.resolve("react-refresh");
|
|
154
|
+
var REACT_REFRESH_DIR_PATH = import_node_path.default.dirname(REACT_REFRESH_PATH);
|
|
173
155
|
var applyBasicReactSupport = (api, options) => {
|
|
174
|
-
api.
|
|
175
|
-
if ((0, import_shared4.isProd)()) {
|
|
176
|
-
return;
|
|
177
|
-
}
|
|
178
|
-
if (multiCompiler.compilers) {
|
|
179
|
-
multiCompiler.compilers.forEach(setupCompiler);
|
|
180
|
-
} else {
|
|
181
|
-
setupCompiler(multiCompiler);
|
|
182
|
-
}
|
|
183
|
-
});
|
|
184
|
-
api.modifyBundlerChain(async (chain, { CHAIN_ID, isProd: isProd3, target }) => {
|
|
156
|
+
api.modifyBundlerChain(async (chain, { CHAIN_ID, isProd: isProd2, target }) => {
|
|
185
157
|
const config = api.getNormalizedConfig();
|
|
186
|
-
const usingHMR = (0, import_shared4.isUsingHMR)(config, { isProd:
|
|
158
|
+
const usingHMR = (0, import_shared4.isUsingHMR)(config, { isProd: isProd2, target });
|
|
187
159
|
const rule = chain.module.rule(CHAIN_ID.RULE.JS);
|
|
188
160
|
const reactOptions = {
|
|
189
|
-
development: !
|
|
161
|
+
development: !isProd2,
|
|
190
162
|
refresh: usingHMR,
|
|
191
163
|
runtime: "automatic",
|
|
192
164
|
...options.swcReactOptions
|
|
@@ -208,6 +180,7 @@ var applyBasicReactSupport = (api, options) => {
|
|
|
208
180
|
if (!usingHMR) {
|
|
209
181
|
return;
|
|
210
182
|
}
|
|
183
|
+
chain.resolve.alias.set("react-refresh", REACT_REFRESH_DIR_PATH);
|
|
211
184
|
const { default: ReactRefreshRspackPlugin } = await import("@rspack/plugin-react-refresh");
|
|
212
185
|
chain.plugin(CHAIN_ID.PLUGIN.REACT_FAST_REFRESH).use(ReactRefreshRspackPlugin);
|
|
213
186
|
});
|
package/dist/index.mjs
CHANGED
|
@@ -134,51 +134,17 @@ var applySplitChunksRule = (api, options = {
|
|
|
134
134
|
};
|
|
135
135
|
|
|
136
136
|
// src/react.ts
|
|
137
|
-
import
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
} from "@rsbuild/shared";
|
|
142
|
-
function getReactRefreshEntry(compiler) {
|
|
143
|
-
const hot = compiler.options.devServer?.hot ?? true;
|
|
144
|
-
const refresh = compiler.options.builtins?.react?.refresh ?? true;
|
|
145
|
-
if (hot && refresh) {
|
|
146
|
-
const reactRefreshEntryPath = __require.resolve(
|
|
147
|
-
"@rspack/plugin-react-refresh/react-refresh-entry"
|
|
148
|
-
);
|
|
149
|
-
return reactRefreshEntryPath;
|
|
150
|
-
}
|
|
151
|
-
return null;
|
|
152
|
-
}
|
|
153
|
-
var setupCompiler = (compiler) => {
|
|
154
|
-
if (!isClientCompiler(compiler)) {
|
|
155
|
-
return;
|
|
156
|
-
}
|
|
157
|
-
const reactRefreshEntry = getReactRefreshEntry(compiler);
|
|
158
|
-
if (!reactRefreshEntry) {
|
|
159
|
-
return;
|
|
160
|
-
}
|
|
161
|
-
new compiler.webpack.EntryPlugin(compiler.context, reactRefreshEntry, {
|
|
162
|
-
name: void 0
|
|
163
|
-
}).apply(compiler);
|
|
164
|
-
};
|
|
137
|
+
import path2 from "path";
|
|
138
|
+
import { isUsingHMR } from "@rsbuild/shared";
|
|
139
|
+
var REACT_REFRESH_PATH = __require.resolve("react-refresh");
|
|
140
|
+
var REACT_REFRESH_DIR_PATH = path2.dirname(REACT_REFRESH_PATH);
|
|
165
141
|
var applyBasicReactSupport = (api, options) => {
|
|
166
|
-
api.
|
|
167
|
-
if (isProd2()) {
|
|
168
|
-
return;
|
|
169
|
-
}
|
|
170
|
-
if (multiCompiler.compilers) {
|
|
171
|
-
multiCompiler.compilers.forEach(setupCompiler);
|
|
172
|
-
} else {
|
|
173
|
-
setupCompiler(multiCompiler);
|
|
174
|
-
}
|
|
175
|
-
});
|
|
176
|
-
api.modifyBundlerChain(async (chain, { CHAIN_ID, isProd: isProd3, target }) => {
|
|
142
|
+
api.modifyBundlerChain(async (chain, { CHAIN_ID, isProd: isProd2, target }) => {
|
|
177
143
|
const config = api.getNormalizedConfig();
|
|
178
|
-
const usingHMR = isUsingHMR(config, { isProd:
|
|
144
|
+
const usingHMR = isUsingHMR(config, { isProd: isProd2, target });
|
|
179
145
|
const rule = chain.module.rule(CHAIN_ID.RULE.JS);
|
|
180
146
|
const reactOptions = {
|
|
181
|
-
development: !
|
|
147
|
+
development: !isProd2,
|
|
182
148
|
refresh: usingHMR,
|
|
183
149
|
runtime: "automatic",
|
|
184
150
|
...options.swcReactOptions
|
|
@@ -200,6 +166,7 @@ var applyBasicReactSupport = (api, options) => {
|
|
|
200
166
|
if (!usingHMR) {
|
|
201
167
|
return;
|
|
202
168
|
}
|
|
169
|
+
chain.resolve.alias.set("react-refresh", REACT_REFRESH_DIR_PATH);
|
|
203
170
|
const { default: ReactRefreshRspackPlugin } = await import("@rspack/plugin-react-refresh");
|
|
204
171
|
chain.plugin(CHAIN_ID.PLUGIN.REACT_FAST_REFRESH).use(ReactRefreshRspackPlugin);
|
|
205
172
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rsbuild/plugin-react",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "React plugin for Rsbuild",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -22,15 +22,15 @@
|
|
|
22
22
|
"dist"
|
|
23
23
|
],
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@rspack/plugin-react-refresh": "0.
|
|
25
|
+
"@rspack/plugin-react-refresh": "0.5.0",
|
|
26
26
|
"react-refresh": "^0.14.0",
|
|
27
|
-
"@rsbuild/shared": "0.
|
|
27
|
+
"@rsbuild/shared": "0.3.0"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
30
|
"@types/node": "16.x",
|
|
31
31
|
"typescript": "^5.3.0",
|
|
32
|
-
"@rsbuild/core": "0.
|
|
33
|
-
"@rsbuild/test-helper": "0.
|
|
32
|
+
"@rsbuild/core": "0.3.0",
|
|
33
|
+
"@rsbuild/test-helper": "0.3.0"
|
|
34
34
|
},
|
|
35
35
|
"publishConfig": {
|
|
36
36
|
"access": "public",
|