@unpackjs/plugin-react 1.6.1 → 1.6.2

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
@@ -39,14 +39,19 @@ var import_click_to_component = require("./click-to-component/index.cjs");
39
39
  var import_mpa = require("./mpa.cjs");
40
40
  const PLUGIN_NAME = "unpack:react";
41
41
  const pluginReact = (options = {}) => {
42
+ const { clickToComponent, reactCompiler } = options;
42
43
  return {
43
44
  name: PLUGIN_NAME,
44
45
  bundlerConfig: async (originalConfig, { unpackConfig, mergeConfig }) => {
45
46
  let config = originalConfig;
46
47
  config = (0, import_mpa.addMpaSupport)({ config, unpackConfig, mergeConfig });
47
- if ((0, import_core.isDev)() && options.clickToComponent) {
48
+ if ((0, import_core.isDev)() && clickToComponent) {
48
49
  config = await (0, import_click_to_component.addClickToComponentSupport)({ config, unpackConfig });
49
50
  }
51
+ if (reactCompiler && !(0, import_core.getUserDepPath)(unpackConfig.root, "react-compiler-runtime")) {
52
+ import_core.logger.error('Dependency "react-compiler-runtime" not found. Did you install it?');
53
+ process.exit(1);
54
+ }
50
55
  const isRspack = unpackConfig.bundler === "rspack";
51
56
  const jsExclude = [/node_modules[\\/](?!\.unpack)/];
52
57
  const swcLoader = isRspack ? "builtin:swc-loader" : require.resolve("swc-loader");
@@ -85,8 +90,22 @@ const pluginReact = (options = {}) => {
85
90
  {
86
91
  test: /\.(j|t)sx$/,
87
92
  exclude: jsExclude,
88
- loader: swcLoader,
89
- options: getSwcOptions({ tsx: true })
93
+ use: [
94
+ {
95
+ loader: swcLoader,
96
+ options: getSwcOptions({ tsx: true })
97
+ },
98
+ reactCompiler && unpackConfig.build?.parallel && {
99
+ loader: import_node_path.default.resolve(__dirname, "../../core/dist/thread-loader/index.cjs"),
100
+ options: import_core.THREAD_OPTIONS
101
+ },
102
+ reactCompiler && {
103
+ loader: import_node_path.default.resolve(__dirname, "./react-compiler-loader/index.cjs"),
104
+ options: {
105
+ target: (0, import_core.getUserDepVersion)(unpackConfig.root, "react").split(".")[0]
106
+ }
107
+ }
108
+ ].filter(Boolean)
90
109
  }
91
110
  ]
92
111
  },
package/dist/index.d.ts CHANGED
@@ -2,6 +2,7 @@ import { type UnpackPlugin } from '@unpackjs/core';
2
2
  export declare const PLUGIN_NAME = "unpack:react";
3
3
  export type PluginReactOptions = {
4
4
  clickToComponent?: boolean;
5
+ reactCompiler?: boolean;
5
6
  };
6
7
  export declare const pluginReact: (options?: PluginReactOptions) => UnpackPlugin;
7
8
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAwB,KAAK,YAAY,EAAsB,MAAM,gBAAgB,CAAA;AAI5F,eAAO,MAAM,WAAW,iBAAiB,CAAA;AAEzC,MAAM,MAAM,kBAAkB,GAAG;IAC/B,gBAAgB,CAAC,EAAE,OAAO,CAAA;CAC3B,CAAA;AACD,eAAO,MAAM,WAAW,aAAa,kBAAkB,KAAQ,YAkE9D,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAGL,KAAK,YAAY,EAMlB,MAAM,gBAAgB,CAAA;AAIvB,eAAO,MAAM,WAAW,iBAAiB,CAAA;AAEzC,MAAM,MAAM,kBAAkB,GAAG;IAC/B,gBAAgB,CAAC,EAAE,OAAO,CAAA;IAC1B,aAAa,CAAC,EAAE,OAAO,CAAA;CACxB,CAAA;AACD,eAAO,MAAM,WAAW,aAAa,kBAAkB,KAAQ,YAsF9D,CAAA"}
package/dist/index.js CHANGED
@@ -10,19 +10,32 @@ var __filename = /* @__PURE__ */ getFilename();
10
10
  import path2 from "node:path";
11
11
  import WebpackReactRefreshPlugin from "@pmmmwh/react-refresh-webpack-plugin";
12
12
  import RspackReactRefreshPlugin from "@rspack/plugin-react-refresh";
13
- import { DEFAULT_BROWSERSLIST, isDev, isDevServer } from "@unpackjs/core";
13
+ import {
14
+ DEFAULT_BROWSERSLIST,
15
+ THREAD_OPTIONS,
16
+ getUserDepPath,
17
+ getUserDepVersion,
18
+ isDev,
19
+ isDevServer,
20
+ logger
21
+ } from "@unpackjs/core";
14
22
  import { addClickToComponentSupport } from "./click-to-component/index.js";
15
23
  import { addMpaSupport } from "./mpa.js";
16
24
  const PLUGIN_NAME = "unpack:react";
17
25
  const pluginReact = (options = {}) => {
26
+ const { clickToComponent, reactCompiler } = options;
18
27
  return {
19
28
  name: PLUGIN_NAME,
20
29
  bundlerConfig: async (originalConfig, { unpackConfig, mergeConfig }) => {
21
30
  let config = originalConfig;
22
31
  config = addMpaSupport({ config, unpackConfig, mergeConfig });
23
- if (isDev() && options.clickToComponent) {
32
+ if (isDev() && clickToComponent) {
24
33
  config = await addClickToComponentSupport({ config, unpackConfig });
25
34
  }
35
+ if (reactCompiler && !getUserDepPath(unpackConfig.root, "react-compiler-runtime")) {
36
+ logger.error('Dependency "react-compiler-runtime" not found. Did you install it?');
37
+ process.exit(1);
38
+ }
26
39
  const isRspack = unpackConfig.bundler === "rspack";
27
40
  const jsExclude = [/node_modules[\\/](?!\.unpack)/];
28
41
  const swcLoader = isRspack ? "builtin:swc-loader" : require.resolve("swc-loader");
@@ -61,8 +74,22 @@ const pluginReact = (options = {}) => {
61
74
  {
62
75
  test: /\.(j|t)sx$/,
63
76
  exclude: jsExclude,
64
- loader: swcLoader,
65
- options: getSwcOptions({ tsx: true })
77
+ use: [
78
+ {
79
+ loader: swcLoader,
80
+ options: getSwcOptions({ tsx: true })
81
+ },
82
+ reactCompiler && unpackConfig.build?.parallel && {
83
+ loader: path2.resolve(__dirname, "../../core/dist/thread-loader/index.cjs"),
84
+ options: THREAD_OPTIONS
85
+ },
86
+ reactCompiler && {
87
+ loader: path2.resolve(__dirname, "./react-compiler-loader/index.cjs"),
88
+ options: {
89
+ target: getUserDepVersion(unpackConfig.root, "react").split(".")[0]
90
+ }
91
+ }
92
+ ].filter(Boolean)
66
93
  }
67
94
  ]
68
95
  },
@@ -0,0 +1,67 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
24
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
+ mod
26
+ ));
27
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
+ var react_compiler_loader_exports = {};
29
+ __export(react_compiler_loader_exports, {
30
+ default: () => reactCompilerLoader
31
+ });
32
+ module.exports = __toCommonJS(react_compiler_loader_exports);
33
+ var babel = __toESM(require("@babel/core"));
34
+ var import_plugin_proposal_decorators = __toESM(require("@babel/plugin-proposal-decorators"));
35
+ var import_plugin_transform_class_properties = __toESM(require("@babel/plugin-transform-class-properties"));
36
+ var import_babel_plugin_react_compiler = __toESM(require("babel-plugin-react-compiler"));
37
+ const defaultBabelParsePlugins = ["jsx", "typescript"];
38
+ async function reactCompilerLoader(input, _inputSourceMap) {
39
+ const callback = this.async();
40
+ try {
41
+ const options = this.getOptions();
42
+ const result = await babel.transformAsync(input, {
43
+ sourceFileName: this.resourcePath,
44
+ filename: this.resourcePath,
45
+ cloneInputAst: false,
46
+ plugins: [
47
+ [import_babel_plugin_react_compiler.default, options],
48
+ [import_plugin_proposal_decorators.default, { legacy: true }],
49
+ [import_plugin_transform_class_properties.default]
50
+ ],
51
+ parserOpts: {
52
+ plugins: [...defaultBabelParsePlugins]
53
+ },
54
+ ast: false,
55
+ sourceMaps: true,
56
+ configFile: false,
57
+ babelrc: false
58
+ });
59
+ if (!result) {
60
+ throw new TypeError("babel.transformAsync with react compiler plugin returns null");
61
+ }
62
+ const { code, map } = result;
63
+ callback(null, code ?? void 0, map ?? void 0);
64
+ } catch (e) {
65
+ callback(e);
66
+ }
67
+ }
@@ -0,0 +1,5 @@
1
+ export type ReactCompilerLoaderOption = {
2
+ target: '17' | '18' | '19';
3
+ };
4
+ export default function reactCompilerLoader(this: any, input: string, _inputSourceMap: any): Promise<void>;
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/react-compiler-loader/index.ts"],"names":[],"mappings":"AAKA,MAAM,MAAM,yBAAyB,GAAG;IACtC,MAAM,EAAE,IAAI,GAAG,IAAI,GAAG,IAAI,CAAA;CAC3B,CAAA;AAMD,wBAA8B,mBAAmB,CAAC,IAAI,KAAA,EAAE,KAAK,EAAE,MAAM,EAAE,eAAe,EAAE,GAAG,iBAiC1F"}
@@ -0,0 +1,47 @@
1
+ import { createRequire } from 'node:module';
2
+ var require = createRequire(import.meta['url']);
3
+
4
+ import path from "path";
5
+ import { fileURLToPath } from "url";
6
+ var getFilename = () => fileURLToPath(import.meta.url);
7
+ var getDirname = () => path.dirname(getFilename());
8
+ var __dirname = /* @__PURE__ */ getDirname();
9
+ var __filename = /* @__PURE__ */ getFilename();
10
+ import * as babel from "@babel/core";
11
+ import PluginProposalDecorators from "@babel/plugin-proposal-decorators";
12
+ import PluginTransformClassProperties from "@babel/plugin-transform-class-properties";
13
+ import BabelPluginReactCompiler from "babel-plugin-react-compiler";
14
+ const defaultBabelParsePlugins = ["jsx", "typescript"];
15
+ async function reactCompilerLoader(input, _inputSourceMap) {
16
+ const callback = this.async();
17
+ try {
18
+ const options = this.getOptions();
19
+ const result = await babel.transformAsync(input, {
20
+ sourceFileName: this.resourcePath,
21
+ filename: this.resourcePath,
22
+ cloneInputAst: false,
23
+ plugins: [
24
+ [BabelPluginReactCompiler, options],
25
+ [PluginProposalDecorators, { legacy: true }],
26
+ [PluginTransformClassProperties]
27
+ ],
28
+ parserOpts: {
29
+ plugins: [...defaultBabelParsePlugins]
30
+ },
31
+ ast: false,
32
+ sourceMaps: true,
33
+ configFile: false,
34
+ babelrc: false
35
+ });
36
+ if (!result) {
37
+ throw new TypeError("babel.transformAsync with react compiler plugin returns null");
38
+ }
39
+ const { code, map } = result;
40
+ callback(null, code ?? void 0, map ?? void 0);
41
+ } catch (e) {
42
+ callback(e);
43
+ }
44
+ }
45
+ export {
46
+ reactCompilerLoader as default
47
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unpackjs/plugin-react",
3
- "version": "1.6.1",
3
+ "version": "1.6.2",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "exports": {
@@ -23,15 +23,19 @@
23
23
  "access": "public"
24
24
  },
25
25
  "dependencies": {
26
+ "@babel/core": "7.26.0",
27
+ "@babel/plugin-proposal-decorators": "7.25.9",
28
+ "@babel/plugin-transform-class-properties": "7.25.9",
26
29
  "@pmmmwh/react-refresh-webpack-plugin": "0.5.15",
27
30
  "@rspack/plugin-react-refresh": "1.0.0",
28
- "react-refresh": "0.14.2",
29
- "swc-loader": "0.2.6",
30
- "@swc/core": "1.7.39",
31
+ "@swc/core": "1.7.40",
31
32
  "@swc/helpers": "0.5.13",
32
- "launch-editor": "2.9.1",
33
+ "babel-plugin-react-compiler": "19.0.0-beta-8a03594-20241020",
33
34
  "html-webpack-plugin": "5.6.3",
34
- "@unpackjs/core": "^1.6.1"
35
+ "launch-editor": "2.9.1",
36
+ "react-refresh": "0.14.2",
37
+ "swc-loader": "0.2.6",
38
+ "@unpackjs/core": "^1.6.2"
35
39
  },
36
40
  "scripts": {
37
41
  "dev": "modern build --watch",