@unpackjs/plugin-react 1.7.5 → 1.7.7

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
@@ -1,133 +1,160 @@
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 src_exports = {};
29
- __export(src_exports, {
30
- PLUGIN_NAME: () => PLUGIN_NAME,
31
- pluginReact: () => pluginReact
1
+ "use strict";
2
+ var __webpack_require__ = {};
3
+ (()=>{
4
+ __webpack_require__.n = function(module) {
5
+ var getter = module && module.__esModule ? function() {
6
+ return module['default'];
7
+ } : function() {
8
+ return module;
9
+ };
10
+ __webpack_require__.d(getter, {
11
+ a: getter
12
+ });
13
+ return getter;
14
+ };
15
+ })();
16
+ (()=>{
17
+ __webpack_require__.d = function(exports1, definition) {
18
+ for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
19
+ enumerable: true,
20
+ get: definition[key]
21
+ });
22
+ };
23
+ })();
24
+ (()=>{
25
+ __webpack_require__.o = function(obj, prop) {
26
+ return Object.prototype.hasOwnProperty.call(obj, prop);
27
+ };
28
+ })();
29
+ (()=>{
30
+ __webpack_require__.r = function(exports1) {
31
+ if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
32
+ value: 'Module'
33
+ });
34
+ Object.defineProperty(exports1, '__esModule', {
35
+ value: true
36
+ });
37
+ };
38
+ })();
39
+ var __webpack_exports__ = {};
40
+ __webpack_require__.r(__webpack_exports__);
41
+ __webpack_require__.d(__webpack_exports__, {
42
+ pluginReact: ()=>pluginReact,
43
+ PLUGIN_NAME: ()=>PLUGIN_NAME
32
44
  });
33
- module.exports = __toCommonJS(src_exports);
34
- var import_node_path = __toESM(require("node:path"));
35
- var import_react_refresh_webpack_plugin = __toESM(require("@pmmmwh/react-refresh-webpack-plugin"));
36
- var import_plugin_react_refresh = __toESM(require("@rspack/plugin-react-refresh"));
37
- var import_core = require("@unpackjs/core");
38
- var import_click_to_component = require("./click-to-component/index.cjs");
39
- var import_mpa = require("./mpa.cjs");
40
- var import_splitChunks = require("./splitChunks.cjs");
41
- const PLUGIN_NAME = "unpack:react";
42
- const pluginReact = (options = {}) => {
43
- const { clickToComponent, reactCompiler } = options;
44
- return {
45
- name: PLUGIN_NAME,
46
- bundlerConfig: async (originalConfig, { unpackConfig, mergeConfig, bundler }) => {
47
- let config = originalConfig;
48
- const isRspack = unpackConfig.bundler === "rspack";
49
- const HtmlPlugin = isRspack ? bundler.HtmlRspackPlugin : import_core.HtmlWebpackPlugin;
50
- config = (0, import_mpa.applyMpaConfig)({ config, unpackConfig, mergeConfig, HtmlPlugin });
51
- if ((0, import_core.isDev)() && clickToComponent) {
52
- config = await (0, import_click_to_component.applyClickToComponentConfig)({ config, unpackConfig });
53
- }
54
- config = (0, import_splitChunks.applySplitChunksConfig)({ config, unpackConfig });
55
- if (reactCompiler && !(0, import_core.getUserDepPath)(unpackConfig.root, "react-compiler-runtime")) {
56
- import_core.logger.error('Dependency "react-compiler-runtime" not found. Did you install it?');
57
- process.exit(1);
58
- }
59
- const jsExclude = [/node_modules[\\/](?!\.unpack)/];
60
- const swcLoader = isRspack ? "builtin:swc-loader" : require.resolve("swc-loader");
61
- const ReactRefreshPlugin = isRspack ? import_plugin_react_refresh.default : import_react_refresh_webpack_plugin.default;
62
- const getSwcOptions = ({ tsx }) => {
63
- return {
64
- jsc: {
65
- parser: {
66
- tsx,
67
- syntax: "typescript",
68
- dynamicImport: true,
69
- decorators: true
70
- },
71
- externalHelpers: true,
72
- transform: {
73
- react: {
74
- runtime: "automatic",
75
- refresh: (0, import_core.isDevServer)()
76
- }
45
+ const external_node_path_namespaceObject = require("node:path");
46
+ var external_node_path_default = /*#__PURE__*/ __webpack_require__.n(external_node_path_namespaceObject);
47
+ const react_refresh_webpack_plugin_namespaceObject = require("@pmmmwh/react-refresh-webpack-plugin");
48
+ var react_refresh_webpack_plugin_default = /*#__PURE__*/ __webpack_require__.n(react_refresh_webpack_plugin_namespaceObject);
49
+ const plugin_react_refresh_namespaceObject = require("@rspack/plugin-react-refresh");
50
+ var plugin_react_refresh_default = /*#__PURE__*/ __webpack_require__.n(plugin_react_refresh_namespaceObject);
51
+ const core_namespaceObject = require("@unpackjs/core");
52
+ const index_cjs_namespaceObject = require("./click-to-component/index.cjs");
53
+ const external_mpa_cjs_namespaceObject = require("./mpa.cjs");
54
+ const external_splitChunks_cjs_namespaceObject = require("./splitChunks.cjs");
55
+ const PLUGIN_NAME = 'unpack:react';
56
+ const pluginReact = (options = {})=>{
57
+ const { clickToComponent, reactCompiler } = options;
58
+ return {
59
+ name: PLUGIN_NAME,
60
+ bundlerConfig: async (originalConfig, { unpackConfig, mergeConfig, bundler })=>{
61
+ let config = originalConfig;
62
+ const isRspack = 'rspack' === unpackConfig.bundler;
63
+ const HtmlPlugin = isRspack ? bundler.HtmlRspackPlugin : core_namespaceObject.HtmlWebpackPlugin;
64
+ config = (0, external_mpa_cjs_namespaceObject.applyMpaConfig)({
65
+ config,
66
+ unpackConfig,
67
+ mergeConfig,
68
+ HtmlPlugin
69
+ });
70
+ if ((0, core_namespaceObject.isDev)() && clickToComponent) config = await (0, index_cjs_namespaceObject.applyClickToComponentConfig)({
71
+ config,
72
+ unpackConfig
73
+ });
74
+ config = (0, external_splitChunks_cjs_namespaceObject.applySplitChunksConfig)({
75
+ config,
76
+ unpackConfig
77
+ });
78
+ if (reactCompiler && !(0, core_namespaceObject.getUserDepPath)(unpackConfig.root, 'react-compiler-runtime')) {
79
+ core_namespaceObject.logger.error('Dependency "react-compiler-runtime" not found. Did you install it?');
80
+ process.exit(1);
77
81
  }
78
- },
79
- env: {
80
- targets: import_core.DEFAULT_BROWSERSLIST
81
- }
82
- };
83
- };
84
- return mergeConfig(config, {
85
- module: {
86
- rules: [
87
- {
88
- test: /\.(j|t)s$/,
89
- exclude: jsExclude,
90
- use: [
91
- {
92
- loader: swcLoader,
93
- options: getSwcOptions({ tsx: false })
94
- }
95
- ]
96
- },
97
- {
98
- test: /\.(j|t)sx$/,
99
- exclude: jsExclude,
100
- use: [
101
- {
102
- loader: swcLoader,
103
- options: getSwcOptions({ tsx: true })
82
+ const jsExclude = [
83
+ /node_modules[\\/](?!\.unpack)/
84
+ ];
85
+ const swcLoader = isRspack ? 'builtin:swc-loader' : require.resolve('swc-loader');
86
+ const ReactRefreshPlugin = isRspack ? plugin_react_refresh_default() : react_refresh_webpack_plugin_default();
87
+ const getSwcOptions = ({ tsx })=>({
88
+ jsc: {
89
+ parser: {
90
+ tsx,
91
+ syntax: "typescript",
92
+ dynamicImport: true,
93
+ decorators: true
94
+ },
95
+ externalHelpers: true,
96
+ transform: {
97
+ react: {
98
+ runtime: 'automatic',
99
+ refresh: (0, core_namespaceObject.isDevServer)()
100
+ }
101
+ }
102
+ },
103
+ env: {
104
+ targets: core_namespaceObject.DEFAULT_BROWSERSLIST
105
+ }
106
+ });
107
+ return mergeConfig(config, {
108
+ module: {
109
+ rules: [
110
+ {
111
+ test: /\.(j|t)s$/,
112
+ exclude: jsExclude,
113
+ use: [
114
+ {
115
+ loader: swcLoader,
116
+ options: getSwcOptions({
117
+ tsx: false
118
+ })
119
+ }
120
+ ]
121
+ },
122
+ {
123
+ test: /\.(j|t)sx$/,
124
+ exclude: jsExclude,
125
+ use: [
126
+ {
127
+ loader: swcLoader,
128
+ options: getSwcOptions({
129
+ tsx: true
130
+ })
131
+ },
132
+ reactCompiler && {
133
+ loader: external_node_path_default().resolve(__dirname, './react-compiler-loader/index.cjs'),
134
+ options: {
135
+ target: (0, core_namespaceObject.getUserDepVersion)(unpackConfig.root, 'react').split('.')[0]
136
+ }
137
+ }
138
+ ].filter(Boolean)
139
+ }
140
+ ]
104
141
  },
105
- reactCompiler && {
106
- loader: import_node_path.default.resolve(__dirname, "./react-compiler-loader/index.cjs"),
107
- options: {
108
- target: (0, import_core.getUserDepVersion)(unpackConfig.root, "react").split(".")[0]
109
- }
142
+ plugins: [
143
+ (0, core_namespaceObject.isDevServer)() && new ReactRefreshPlugin({
144
+ overlay: false
145
+ })
146
+ ].filter(Boolean),
147
+ resolve: {
148
+ alias: {
149
+ '@swc/helpers': external_node_path_default().dirname(require.resolve('@swc/helpers/package.json'))
150
+ }
110
151
  }
111
- ].filter(Boolean)
112
- }
113
- ]
114
- },
115
- plugins: [
116
- (0, import_core.isDevServer)() && new ReactRefreshPlugin({
117
- overlay: false
118
- })
119
- ].filter(Boolean),
120
- resolve: {
121
- alias: {
122
- "@swc/helpers": import_node_path.default.dirname(require.resolve("@swc/helpers/package.json"))
123
- }
152
+ });
124
153
  }
125
- });
126
- }
127
- };
154
+ };
128
155
  };
129
- // Annotate the CommonJS export names for ESM import in node:
130
- 0 && (module.exports = {
131
- PLUGIN_NAME,
132
- pluginReact
156
+ var __webpack_export_target__ = exports;
157
+ for(var __webpack_i__ in __webpack_exports__)__webpack_export_target__[__webpack_i__] = __webpack_exports__[__webpack_i__];
158
+ if (__webpack_exports__.__esModule) Object.defineProperty(__webpack_export_target__, '__esModule', {
159
+ value: true
133
160
  });
package/dist/index.js CHANGED
@@ -1,116 +1,114 @@
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 path2 from "node:path";
11
- import WebpackReactRefreshPlugin from "@pmmmwh/react-refresh-webpack-plugin";
12
- import RspackReactRefreshPlugin from "@rspack/plugin-react-refresh";
13
- import {
14
- DEFAULT_BROWSERSLIST,
15
- HtmlWebpackPlugin,
16
- getUserDepPath,
17
- getUserDepVersion,
18
- isDev,
19
- isDevServer,
20
- logger
21
- } from "@unpackjs/core";
22
- import { applyClickToComponentConfig } from "./click-to-component/index.js";
23
- import { applyMpaConfig } from "./mpa.js";
24
- import { applySplitChunksConfig } from "./splitChunks.js";
25
- const PLUGIN_NAME = "unpack:react";
26
- const pluginReact = (options = {}) => {
27
- const { clickToComponent, reactCompiler } = options;
28
- return {
29
- name: PLUGIN_NAME,
30
- bundlerConfig: async (originalConfig, { unpackConfig, mergeConfig, bundler }) => {
31
- let config = originalConfig;
32
- const isRspack = unpackConfig.bundler === "rspack";
33
- const HtmlPlugin = isRspack ? bundler.HtmlRspackPlugin : HtmlWebpackPlugin;
34
- config = applyMpaConfig({ config, unpackConfig, mergeConfig, HtmlPlugin });
35
- if (isDev() && clickToComponent) {
36
- config = await applyClickToComponentConfig({ config, unpackConfig });
37
- }
38
- config = applySplitChunksConfig({ config, unpackConfig });
39
- if (reactCompiler && !getUserDepPath(unpackConfig.root, "react-compiler-runtime")) {
40
- logger.error('Dependency "react-compiler-runtime" not found. Did you install it?');
41
- process.exit(1);
42
- }
43
- const jsExclude = [/node_modules[\\/](?!\.unpack)/];
44
- const swcLoader = isRspack ? "builtin:swc-loader" : require.resolve("swc-loader");
45
- const ReactRefreshPlugin = isRspack ? RspackReactRefreshPlugin : WebpackReactRefreshPlugin;
46
- const getSwcOptions = ({ tsx }) => {
47
- return {
48
- jsc: {
49
- parser: {
50
- tsx,
51
- syntax: "typescript",
52
- dynamicImport: true,
53
- decorators: true
54
- },
55
- externalHelpers: true,
56
- transform: {
57
- react: {
58
- runtime: "automatic",
59
- refresh: isDevServer()
60
- }
1
+ import __rslib_shim_module__ from 'module';
2
+ const require = /*#__PURE__*/ __rslib_shim_module__.createRequire(import.meta.url);
3
+ import { fileURLToPath as __webpack_fileURLToPath__ } from "node:url";
4
+ import { dirname as __webpack_dirname__ } from "node:path";
5
+ import * as __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__ from "node:path";
6
+ import * as __WEBPACK_EXTERNAL_MODULE__pmmmwh_react_refresh_webpack_plugin_143c1848__ from "@pmmmwh/react-refresh-webpack-plugin";
7
+ import * as __WEBPACK_EXTERNAL_MODULE__rspack_plugin_react_refresh_db0cf031__ from "@rspack/plugin-react-refresh";
8
+ import * as __WEBPACK_EXTERNAL_MODULE__unpackjs_core_a401ca19__ from "@unpackjs/core";
9
+ import * as __WEBPACK_EXTERNAL_MODULE__click_to_component_index_js_1f068bff__ from "./click-to-component/index.js";
10
+ import * as __WEBPACK_EXTERNAL_MODULE__mpa_js_c5cf22d9__ from "./mpa.js";
11
+ import * as __WEBPACK_EXTERNAL_MODULE__splitChunks_js_b23140d8__ from "./splitChunks.js";
12
+ var src_rslib_entry_dirname = __webpack_dirname__(__webpack_fileURLToPath__(import.meta.url));
13
+ const PLUGIN_NAME = 'unpack:react';
14
+ const pluginReact = (options = {})=>{
15
+ const { clickToComponent, reactCompiler } = options;
16
+ return {
17
+ name: PLUGIN_NAME,
18
+ bundlerConfig: async (originalConfig, { unpackConfig, mergeConfig, bundler })=>{
19
+ let config = originalConfig;
20
+ const isRspack = 'rspack' === unpackConfig.bundler;
21
+ const HtmlPlugin = isRspack ? bundler.HtmlRspackPlugin : __WEBPACK_EXTERNAL_MODULE__unpackjs_core_a401ca19__.HtmlWebpackPlugin;
22
+ config = (0, __WEBPACK_EXTERNAL_MODULE__mpa_js_c5cf22d9__.applyMpaConfig)({
23
+ config,
24
+ unpackConfig,
25
+ mergeConfig,
26
+ HtmlPlugin
27
+ });
28
+ if ((0, __WEBPACK_EXTERNAL_MODULE__unpackjs_core_a401ca19__.isDev)() && clickToComponent) config = await (0, __WEBPACK_EXTERNAL_MODULE__click_to_component_index_js_1f068bff__.applyClickToComponentConfig)({
29
+ config,
30
+ unpackConfig
31
+ });
32
+ config = (0, __WEBPACK_EXTERNAL_MODULE__splitChunks_js_b23140d8__.applySplitChunksConfig)({
33
+ config,
34
+ unpackConfig
35
+ });
36
+ if (reactCompiler && !(0, __WEBPACK_EXTERNAL_MODULE__unpackjs_core_a401ca19__.getUserDepPath)(unpackConfig.root, 'react-compiler-runtime')) {
37
+ __WEBPACK_EXTERNAL_MODULE__unpackjs_core_a401ca19__.logger.error('Dependency "react-compiler-runtime" not found. Did you install it?');
38
+ process.exit(1);
61
39
  }
62
- },
63
- env: {
64
- targets: DEFAULT_BROWSERSLIST
65
- }
66
- };
67
- };
68
- return mergeConfig(config, {
69
- module: {
70
- rules: [
71
- {
72
- test: /\.(j|t)s$/,
73
- exclude: jsExclude,
74
- use: [
75
- {
76
- loader: swcLoader,
77
- options: getSwcOptions({ tsx: false })
78
- }
79
- ]
80
- },
81
- {
82
- test: /\.(j|t)sx$/,
83
- exclude: jsExclude,
84
- use: [
85
- {
86
- loader: swcLoader,
87
- options: getSwcOptions({ tsx: true })
40
+ const jsExclude = [
41
+ /node_modules[\\/](?!\.unpack)/
42
+ ];
43
+ const swcLoader = isRspack ? 'builtin:swc-loader' : require.resolve('swc-loader');
44
+ const ReactRefreshPlugin = isRspack ? __WEBPACK_EXTERNAL_MODULE__rspack_plugin_react_refresh_db0cf031__["default"] : __WEBPACK_EXTERNAL_MODULE__pmmmwh_react_refresh_webpack_plugin_143c1848__["default"];
45
+ const getSwcOptions = ({ tsx })=>({
46
+ jsc: {
47
+ parser: {
48
+ tsx,
49
+ syntax: "typescript",
50
+ dynamicImport: true,
51
+ decorators: true
52
+ },
53
+ externalHelpers: true,
54
+ transform: {
55
+ react: {
56
+ runtime: 'automatic',
57
+ refresh: (0, __WEBPACK_EXTERNAL_MODULE__unpackjs_core_a401ca19__.isDevServer)()
58
+ }
59
+ }
60
+ },
61
+ env: {
62
+ targets: __WEBPACK_EXTERNAL_MODULE__unpackjs_core_a401ca19__.DEFAULT_BROWSERSLIST
63
+ }
64
+ });
65
+ return mergeConfig(config, {
66
+ module: {
67
+ rules: [
68
+ {
69
+ test: /\.(j|t)s$/,
70
+ exclude: jsExclude,
71
+ use: [
72
+ {
73
+ loader: swcLoader,
74
+ options: getSwcOptions({
75
+ tsx: false
76
+ })
77
+ }
78
+ ]
79
+ },
80
+ {
81
+ test: /\.(j|t)sx$/,
82
+ exclude: jsExclude,
83
+ use: [
84
+ {
85
+ loader: swcLoader,
86
+ options: getSwcOptions({
87
+ tsx: true
88
+ })
89
+ },
90
+ reactCompiler && {
91
+ loader: __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].resolve(src_rslib_entry_dirname, './react-compiler-loader/index.cjs'),
92
+ options: {
93
+ target: (0, __WEBPACK_EXTERNAL_MODULE__unpackjs_core_a401ca19__.getUserDepVersion)(unpackConfig.root, 'react').split('.')[0]
94
+ }
95
+ }
96
+ ].filter(Boolean)
97
+ }
98
+ ]
88
99
  },
89
- reactCompiler && {
90
- loader: path2.resolve(__dirname, "./react-compiler-loader/index.cjs"),
91
- options: {
92
- target: getUserDepVersion(unpackConfig.root, "react").split(".")[0]
93
- }
100
+ plugins: [
101
+ (0, __WEBPACK_EXTERNAL_MODULE__unpackjs_core_a401ca19__.isDevServer)() && new ReactRefreshPlugin({
102
+ overlay: false
103
+ })
104
+ ].filter(Boolean),
105
+ resolve: {
106
+ alias: {
107
+ '@swc/helpers': __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].dirname(require.resolve('@swc/helpers/package.json'))
108
+ }
94
109
  }
95
- ].filter(Boolean)
96
- }
97
- ]
98
- },
99
- plugins: [
100
- isDevServer() && new ReactRefreshPlugin({
101
- overlay: false
102
- })
103
- ].filter(Boolean),
104
- resolve: {
105
- alias: {
106
- "@swc/helpers": path2.dirname(require.resolve("@swc/helpers/package.json"))
107
- }
110
+ });
108
111
  }
109
- });
110
- }
111
- };
112
- };
113
- export {
114
- PLUGIN_NAME,
115
- pluginReact
112
+ };
116
113
  };
114
+ export { PLUGIN_NAME, pluginReact };