@rsbuild/plugin-preact 0.4.10 → 0.4.12

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.js CHANGED
@@ -28,33 +28,33 @@ var pluginPreact = (options = {}) => ({
28
28
  name: "rsbuild:preact",
29
29
  setup(api) {
30
30
  const { reactAliasesEnabled = true } = options;
31
- api.modifyBundlerChain(async (chain, { isDev }) => {
31
+ api.modifyRsbuildConfig((userConfig, { mergeRsbuildConfig }) => {
32
+ const reactOptions = {
33
+ development: (0, import_shared.getNodeEnv)() === "development",
34
+ runtime: "automatic",
35
+ importSource: "preact"
36
+ };
37
+ const extraConfig = {
38
+ tools: {
39
+ swc: {
40
+ jsc: {
41
+ transform: {
42
+ react: reactOptions
43
+ }
44
+ }
45
+ }
46
+ }
47
+ };
32
48
  if (reactAliasesEnabled) {
33
- chain.resolve.alias.merge({
49
+ extraConfig.source || (extraConfig.source = {});
50
+ extraConfig.source.alias = {
34
51
  react: "preact/compat",
35
52
  "react-dom/test-utils": "preact/test-utils",
36
53
  "react-dom": "preact/compat",
37
54
  "react/jsx-runtime": "preact/jsx-runtime"
38
- });
55
+ };
39
56
  }
40
- const reactOptions = {
41
- development: isDev,
42
- runtime: "automatic",
43
- importSource: "preact"
44
- };
45
- (0, import_shared.modifySwcLoaderOptions)({
46
- chain,
47
- modifier: (opts) => {
48
- var _a;
49
- opts.jsc ?? (opts.jsc = {});
50
- (_a = opts.jsc).transform ?? (_a.transform = {});
51
- opts.jsc.transform.react = {
52
- ...opts.jsc.transform.react,
53
- ...reactOptions
54
- };
55
- return opts;
56
- }
57
- });
57
+ return mergeRsbuildConfig(extraConfig, userConfig);
58
58
  });
59
59
  }
60
60
  });
package/dist/index.mjs CHANGED
@@ -7,38 +7,38 @@ import { fileURLToPath } from "url";
7
7
  import path from "path";
8
8
 
9
9
  // src/index.ts
10
- import { modifySwcLoaderOptions } from "@rsbuild/shared";
10
+ import { getNodeEnv } from "@rsbuild/shared";
11
11
  var pluginPreact = (options = {}) => ({
12
12
  name: "rsbuild:preact",
13
13
  setup(api) {
14
14
  const { reactAliasesEnabled = true } = options;
15
- api.modifyBundlerChain(async (chain, { isDev }) => {
15
+ api.modifyRsbuildConfig((userConfig, { mergeRsbuildConfig }) => {
16
+ const reactOptions = {
17
+ development: getNodeEnv() === "development",
18
+ runtime: "automatic",
19
+ importSource: "preact"
20
+ };
21
+ const extraConfig = {
22
+ tools: {
23
+ swc: {
24
+ jsc: {
25
+ transform: {
26
+ react: reactOptions
27
+ }
28
+ }
29
+ }
30
+ }
31
+ };
16
32
  if (reactAliasesEnabled) {
17
- chain.resolve.alias.merge({
33
+ extraConfig.source || (extraConfig.source = {});
34
+ extraConfig.source.alias = {
18
35
  react: "preact/compat",
19
36
  "react-dom/test-utils": "preact/test-utils",
20
37
  "react-dom": "preact/compat",
21
38
  "react/jsx-runtime": "preact/jsx-runtime"
22
- });
39
+ };
23
40
  }
24
- const reactOptions = {
25
- development: isDev,
26
- runtime: "automatic",
27
- importSource: "preact"
28
- };
29
- modifySwcLoaderOptions({
30
- chain,
31
- modifier: (opts) => {
32
- var _a;
33
- opts.jsc ?? (opts.jsc = {});
34
- (_a = opts.jsc).transform ?? (_a.transform = {});
35
- opts.jsc.transform.react = {
36
- ...opts.jsc.transform.react,
37
- ...reactOptions
38
- };
39
- return opts;
40
- }
41
- });
41
+ return mergeRsbuildConfig(extraConfig, userConfig);
42
42
  });
43
43
  }
44
44
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rsbuild/plugin-preact",
3
- "version": "0.4.10",
3
+ "version": "0.4.12",
4
4
  "description": "Preact plugin for Rsbuild",
5
5
  "repository": {
6
6
  "type": "git",
@@ -22,16 +22,15 @@
22
22
  "dist"
23
23
  ],
24
24
  "dependencies": {
25
- "@rsbuild/shared": "0.4.10"
25
+ "@rsbuild/shared": "0.4.12"
26
26
  },
27
27
  "devDependencies": {
28
28
  "@types/node": "16.x",
29
29
  "typescript": "^5.3.0",
30
- "@rsbuild/core": "0.4.10",
31
- "@scripts/test-helper": "0.4.10"
30
+ "@rsbuild/core": "0.4.12"
32
31
  },
33
32
  "peerDependencies": {
34
- "@rsbuild/core": "^0.4.10"
33
+ "@rsbuild/core": "^0.4.12"
35
34
  },
36
35
  "publishConfig": {
37
36
  "access": "public",