@rsbuild/plugin-react 1.0.1 → 1.0.3

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.cjs CHANGED
@@ -37,49 +37,38 @@ module.exports = __toCommonJS(src_exports);
37
37
 
38
38
  // src/react.ts
39
39
  var import_node_path = __toESM(require("path"));
40
- var modifySwcLoaderOptions = ({
41
- chain,
42
- CHAIN_ID,
43
- modifier
44
- }) => {
45
- const ruleIds = [CHAIN_ID.RULE.JS, CHAIN_ID.RULE.JS_DATA_URI];
46
- for (const ruleId of ruleIds) {
47
- if (chain.module.rules.has(ruleId)) {
48
- const rule = chain.module.rule(ruleId);
49
- if (rule.uses.has(CHAIN_ID.USE.SWC)) {
50
- rule.use(CHAIN_ID.USE.SWC).tap(modifier);
51
- }
52
- }
53
- }
54
- };
55
40
  var applyBasicReactSupport = (api, options) => {
56
41
  const REACT_REFRESH_PATH = require.resolve("react-refresh");
42
+ api.modifyEnvironmentConfig((userConfig, { mergeEnvironmentConfig }) => {
43
+ const isDev = userConfig.mode === "development";
44
+ const reactOptions = {
45
+ development: isDev,
46
+ refresh: isDev && userConfig.dev.hmr && userConfig.output.target === "web",
47
+ runtime: "automatic",
48
+ ...options.swcReactOptions
49
+ };
50
+ const extraConfig = {
51
+ tools: {
52
+ swc: {
53
+ jsc: {
54
+ parser: {
55
+ syntax: "typescript",
56
+ // enable supports for JSX/TSX compilation
57
+ tsx: true
58
+ },
59
+ transform: {
60
+ react: reactOptions
61
+ }
62
+ }
63
+ }
64
+ }
65
+ };
66
+ return mergeEnvironmentConfig(extraConfig, userConfig);
67
+ });
57
68
  api.modifyBundlerChain(
58
- async (chain, { CHAIN_ID, environment, isDev, isProd, target }) => {
69
+ async (chain, { CHAIN_ID, environment, isDev, target }) => {
59
70
  const { config } = environment;
60
- const usingHMR = !isProd && config.dev.hmr && target === "web";
61
- const reactOptions = {
62
- development: isDev,
63
- refresh: usingHMR,
64
- runtime: "automatic",
65
- ...options.swcReactOptions
66
- };
67
- modifySwcLoaderOptions({
68
- chain,
69
- CHAIN_ID,
70
- modifier: (opts) => {
71
- opts.jsc ||= {};
72
- opts.jsc.transform ||= {};
73
- opts.jsc.transform.react = reactOptions;
74
- opts.jsc.parser = {
75
- ...opts.jsc.parser,
76
- syntax: "typescript",
77
- // enable supports for React JSX/TSX compilation
78
- tsx: true
79
- };
80
- return opts;
81
- }
82
- });
71
+ const usingHMR = isDev && config.dev.hmr && target === "web";
83
72
  if (!usingHMR) {
84
73
  return;
85
74
  }
@@ -89,9 +78,11 @@ var applyBasicReactSupport = (api, options) => {
89
78
  );
90
79
  const { default: ReactRefreshRspackPlugin } = await import("@rspack/plugin-react-refresh");
91
80
  const SCRIPT_REGEX = /\.(?:js|jsx|mjs|cjs|ts|tsx|mts|cts)$/;
81
+ const NODE_MODULES_REGEX = /[\\/]node_modules[\\/]/;
92
82
  chain.plugin(CHAIN_ID.PLUGIN.REACT_FAST_REFRESH).use(ReactRefreshRspackPlugin, [
93
83
  {
94
84
  include: [SCRIPT_REGEX],
85
+ exclude: [NODE_MODULES_REGEX],
95
86
  ...options.reactRefreshOptions
96
87
  }
97
88
  ]);
package/dist/index.js CHANGED
@@ -9,55 +9,44 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
9
9
  throw Error('Dynamic require of "' + x + '" is not supported');
10
10
  });
11
11
 
12
- // ../../node_modules/.pnpm/@modern-js+module-tools@2.59.0_typescript@5.5.2/node_modules/@modern-js/module-tools/shims/esm.js
12
+ // ../../node_modules/.pnpm/@modern-js+module-tools@2.60.1_typescript@5.5.2/node_modules/@modern-js/module-tools/shims/esm.js
13
13
  import path from "path";
14
14
  import { fileURLToPath } from "url";
15
15
 
16
16
  // src/react.ts
17
17
  import path2 from "path";
18
- var modifySwcLoaderOptions = ({
19
- chain,
20
- CHAIN_ID,
21
- modifier
22
- }) => {
23
- const ruleIds = [CHAIN_ID.RULE.JS, CHAIN_ID.RULE.JS_DATA_URI];
24
- for (const ruleId of ruleIds) {
25
- if (chain.module.rules.has(ruleId)) {
26
- const rule = chain.module.rule(ruleId);
27
- if (rule.uses.has(CHAIN_ID.USE.SWC)) {
28
- rule.use(CHAIN_ID.USE.SWC).tap(modifier);
29
- }
30
- }
31
- }
32
- };
33
18
  var applyBasicReactSupport = (api, options) => {
34
19
  const REACT_REFRESH_PATH = __require.resolve("react-refresh");
20
+ api.modifyEnvironmentConfig((userConfig, { mergeEnvironmentConfig }) => {
21
+ const isDev = userConfig.mode === "development";
22
+ const reactOptions = {
23
+ development: isDev,
24
+ refresh: isDev && userConfig.dev.hmr && userConfig.output.target === "web",
25
+ runtime: "automatic",
26
+ ...options.swcReactOptions
27
+ };
28
+ const extraConfig = {
29
+ tools: {
30
+ swc: {
31
+ jsc: {
32
+ parser: {
33
+ syntax: "typescript",
34
+ // enable supports for JSX/TSX compilation
35
+ tsx: true
36
+ },
37
+ transform: {
38
+ react: reactOptions
39
+ }
40
+ }
41
+ }
42
+ }
43
+ };
44
+ return mergeEnvironmentConfig(extraConfig, userConfig);
45
+ });
35
46
  api.modifyBundlerChain(
36
- async (chain, { CHAIN_ID, environment, isDev, isProd, target }) => {
47
+ async (chain, { CHAIN_ID, environment, isDev, target }) => {
37
48
  const { config } = environment;
38
- const usingHMR = !isProd && config.dev.hmr && target === "web";
39
- const reactOptions = {
40
- development: isDev,
41
- refresh: usingHMR,
42
- runtime: "automatic",
43
- ...options.swcReactOptions
44
- };
45
- modifySwcLoaderOptions({
46
- chain,
47
- CHAIN_ID,
48
- modifier: (opts) => {
49
- opts.jsc ||= {};
50
- opts.jsc.transform ||= {};
51
- opts.jsc.transform.react = reactOptions;
52
- opts.jsc.parser = {
53
- ...opts.jsc.parser,
54
- syntax: "typescript",
55
- // enable supports for React JSX/TSX compilation
56
- tsx: true
57
- };
58
- return opts;
59
- }
60
- });
49
+ const usingHMR = isDev && config.dev.hmr && target === "web";
61
50
  if (!usingHMR) {
62
51
  return;
63
52
  }
@@ -67,9 +56,11 @@ var applyBasicReactSupport = (api, options) => {
67
56
  );
68
57
  const { default: ReactRefreshRspackPlugin } = await import("@rspack/plugin-react-refresh");
69
58
  const SCRIPT_REGEX = /\.(?:js|jsx|mjs|cjs|ts|tsx|mts|cts)$/;
59
+ const NODE_MODULES_REGEX = /[\\/]node_modules[\\/]/;
70
60
  chain.plugin(CHAIN_ID.PLUGIN.REACT_FAST_REFRESH).use(ReactRefreshRspackPlugin, [
71
61
  {
72
62
  include: [SCRIPT_REGEX],
63
+ exclude: [NODE_MODULES_REGEX],
73
64
  ...options.reactRefreshOptions
74
65
  }
75
66
  ]);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rsbuild/plugin-react",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
4
4
  "description": "React plugin for Rsbuild",
5
5
  "repository": {
6
6
  "type": "git",
@@ -29,7 +29,7 @@
29
29
  "devDependencies": {
30
30
  "@types/node": "18.x",
31
31
  "typescript": "^5.5.2",
32
- "@rsbuild/core": "1.0.1",
32
+ "@rsbuild/core": "1.0.8",
33
33
  "@scripts/test-helper": "1.0.1"
34
34
  },
35
35
  "peerDependencies": {