@unpackjs/plugin-react 1.6.4 → 1.7.1

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.
@@ -27,7 +27,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
27
27
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
28
  var click_to_component_exports = {};
29
29
  __export(click_to_component_exports, {
30
- addClickToComponentSupport: () => addClickToComponentSupport
30
+ applyClickToComponentConfig: () => applyClickToComponentConfig
31
31
  });
32
32
  module.exports = __toCommonJS(click_to_component_exports);
33
33
  var import_node_fs = __toESM(require("node:fs"));
@@ -60,7 +60,7 @@ const createServer = () => {
60
60
  });
61
61
  });
62
62
  };
63
- const addClickToComponentSupport = async ({
63
+ const applyClickToComponentConfig = async ({
64
64
  config,
65
65
  unpackConfig
66
66
  }) => {
@@ -99,5 +99,5 @@ import '${(0, import_core.getPathInJs)(import_node_path.default.resolve(Object.v
99
99
  };
100
100
  // Annotate the CommonJS export names for ESM import in node:
101
101
  0 && (module.exports = {
102
- addClickToComponentSupport
102
+ applyClickToComponentConfig
103
103
  });
@@ -1,5 +1,5 @@
1
1
  import { type BundlerConfiguration, type UnpackConfig } from '@unpackjs/core';
2
- export declare const addClickToComponentSupport: ({ config, unpackConfig, }: {
2
+ export declare const applyClickToComponentConfig: ({ config, unpackConfig, }: {
3
3
  config: BundlerConfiguration;
4
4
  unpackConfig: UnpackConfig;
5
5
  }) => Promise<BundlerConfiguration>;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/click-to-component/index.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,KAAK,oBAAoB,EAEzB,KAAK,YAAY,EAGlB,MAAM,gBAAgB,CAAA;AA4BvB,eAAO,MAAM,0BAA0B,8BAGpC;IACD,MAAM,EAAE,oBAAoB,CAAA;IAC5B,YAAY,EAAE,YAAY,CAAA;CAC3B,KAAG,OAAO,CAAC,oBAAoB,CA+B/B,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/click-to-component/index.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,KAAK,oBAAoB,EAEzB,KAAK,YAAY,EAGlB,MAAM,gBAAgB,CAAA;AA4BvB,eAAO,MAAM,2BAA2B,8BAGrC;IACD,MAAM,EAAE,oBAAoB,CAAA;IAC5B,YAAY,EAAE,YAAY,CAAA;CAC3B,KAAG,OAAO,CAAC,oBAAoB,CA+B/B,CAAA"}
@@ -41,7 +41,7 @@ const createServer = () => {
41
41
  });
42
42
  });
43
43
  };
44
- const addClickToComponentSupport = async ({
44
+ const applyClickToComponentConfig = async ({
45
45
  config,
46
46
  unpackConfig
47
47
  }) => {
@@ -79,5 +79,5 @@ import '${getPathInJs(path2.resolve(Object.values(config.entry)[0]))}'
79
79
  return config;
80
80
  };
81
81
  export {
82
- addClickToComponentSupport
82
+ applyClickToComponentConfig
83
83
  };
package/dist/index.cjs CHANGED
@@ -42,17 +42,18 @@ const pluginReact = (options = {}) => {
42
42
  const { clickToComponent, reactCompiler } = options;
43
43
  return {
44
44
  name: PLUGIN_NAME,
45
- bundlerConfig: async (originalConfig, { unpackConfig, mergeConfig }) => {
45
+ bundlerConfig: async (originalConfig, { unpackConfig, mergeConfig, bundler }) => {
46
46
  let config = originalConfig;
47
- config = (0, import_mpa.addMpaSupport)({ config, unpackConfig, mergeConfig });
47
+ const isRspack = unpackConfig.bundler === "rspack";
48
+ const HtmlPlugin = isRspack ? bundler.HtmlRspackPlugin : import_core.HtmlWebpackPlugin;
49
+ config = (0, import_mpa.applyMpaConfig)({ config, unpackConfig, mergeConfig, HtmlPlugin });
48
50
  if ((0, import_core.isDev)() && clickToComponent) {
49
- config = await (0, import_click_to_component.addClickToComponentSupport)({ config, unpackConfig });
51
+ config = await (0, import_click_to_component.applyClickToComponentConfig)({ config, unpackConfig });
50
52
  }
51
53
  if (reactCompiler && !(0, import_core.getUserDepPath)(unpackConfig.root, "react-compiler-runtime")) {
52
54
  import_core.logger.error('Dependency "react-compiler-runtime" not found. Did you install it?');
53
55
  process.exit(1);
54
56
  }
55
- const isRspack = unpackConfig.bundler === "rspack";
56
57
  const jsExclude = [/node_modules[\\/](?!\.unpack)/];
57
58
  const swcLoader = isRspack ? "builtin:swc-loader" : require.resolve("swc-loader");
58
59
  const ReactRefreshPlugin = isRspack ? import_plugin_react_refresh.default : import_react_refresh_webpack_plugin.default;
@@ -84,8 +85,12 @@ const pluginReact = (options = {}) => {
84
85
  {
85
86
  test: /\.(j|t)s$/,
86
87
  exclude: jsExclude,
87
- loader: swcLoader,
88
- options: getSwcOptions({ tsx: false })
88
+ use: [
89
+ {
90
+ loader: swcLoader,
91
+ options: getSwcOptions({ tsx: false })
92
+ }
93
+ ]
89
94
  },
90
95
  {
91
96
  test: /\.(j|t)sx$/,
@@ -1 +1 @@
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"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAIL,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,YA4F9D,CAAA"}
package/dist/index.js CHANGED
@@ -12,6 +12,7 @@ import WebpackReactRefreshPlugin from "@pmmmwh/react-refresh-webpack-plugin";
12
12
  import RspackReactRefreshPlugin from "@rspack/plugin-react-refresh";
13
13
  import {
14
14
  DEFAULT_BROWSERSLIST,
15
+ HtmlWebpackPlugin,
15
16
  THREAD_OPTIONS,
16
17
  getUserDepPath,
17
18
  getUserDepVersion,
@@ -19,24 +20,25 @@ import {
19
20
  isDevServer,
20
21
  logger
21
22
  } from "@unpackjs/core";
22
- import { addClickToComponentSupport } from "./click-to-component/index.js";
23
- import { addMpaSupport } from "./mpa.js";
23
+ import { applyClickToComponentConfig } from "./click-to-component/index.js";
24
+ import { applyMpaConfig } from "./mpa.js";
24
25
  const PLUGIN_NAME = "unpack:react";
25
26
  const pluginReact = (options = {}) => {
26
27
  const { clickToComponent, reactCompiler } = options;
27
28
  return {
28
29
  name: PLUGIN_NAME,
29
- bundlerConfig: async (originalConfig, { unpackConfig, mergeConfig }) => {
30
+ bundlerConfig: async (originalConfig, { unpackConfig, mergeConfig, bundler }) => {
30
31
  let config = originalConfig;
31
- config = addMpaSupport({ config, unpackConfig, mergeConfig });
32
+ const isRspack = unpackConfig.bundler === "rspack";
33
+ const HtmlPlugin = isRspack ? bundler.HtmlRspackPlugin : HtmlWebpackPlugin;
34
+ config = applyMpaConfig({ config, unpackConfig, mergeConfig, HtmlPlugin });
32
35
  if (isDev() && clickToComponent) {
33
- config = await addClickToComponentSupport({ config, unpackConfig });
36
+ config = await applyClickToComponentConfig({ config, unpackConfig });
34
37
  }
35
38
  if (reactCompiler && !getUserDepPath(unpackConfig.root, "react-compiler-runtime")) {
36
39
  logger.error('Dependency "react-compiler-runtime" not found. Did you install it?');
37
40
  process.exit(1);
38
41
  }
39
- const isRspack = unpackConfig.bundler === "rspack";
40
42
  const jsExclude = [/node_modules[\\/](?!\.unpack)/];
41
43
  const swcLoader = isRspack ? "builtin:swc-loader" : require.resolve("swc-loader");
42
44
  const ReactRefreshPlugin = isRspack ? RspackReactRefreshPlugin : WebpackReactRefreshPlugin;
@@ -68,8 +70,12 @@ const pluginReact = (options = {}) => {
68
70
  {
69
71
  test: /\.(j|t)s$/,
70
72
  exclude: jsExclude,
71
- loader: swcLoader,
72
- options: getSwcOptions({ tsx: false })
73
+ use: [
74
+ {
75
+ loader: swcLoader,
76
+ options: getSwcOptions({ tsx: false })
77
+ }
78
+ ]
73
79
  },
74
80
  {
75
81
  test: /\.(j|t)sx$/,
package/dist/mpa.cjs CHANGED
@@ -27,20 +27,21 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
27
27
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
28
  var mpa_exports = {};
29
29
  __export(mpa_exports, {
30
- addMpaSupport: () => addMpaSupport
30
+ applyMpaConfig: () => applyMpaConfig
31
31
  });
32
32
  module.exports = __toCommonJS(mpa_exports);
33
33
  var import_node_fs = __toESM(require("node:fs"));
34
34
  var import_node_path = __toESM(require("node:path"));
35
35
  var import_core = require("@unpackjs/core");
36
- var import_html_webpack_plugin = __toESM(require("html-webpack-plugin"));
37
- const addMpaSupport = ({
36
+ const applyMpaConfig = ({
38
37
  config,
39
38
  unpackConfig,
40
- mergeConfig
39
+ mergeConfig,
40
+ HtmlPlugin
41
41
  }) => {
42
42
  if (!unpackConfig.mpa)
43
43
  return config;
44
+ const isRspack = unpackConfig.bundler === "rspack";
44
45
  const tempDirectory = import_node_path.default.join(import_core.TEMP_DIR, "mpa");
45
46
  const userOptions = (0, import_core.isPlainObject)(unpackConfig.mpa) ? unpackConfig.mpa : {};
46
47
  const getPageConfig = (indexPath) => {
@@ -52,7 +53,7 @@ const addMpaSupport = ({
52
53
  return pageConfig;
53
54
  };
54
55
  const createTempFile = (entry2) => {
55
- import_node_fs.default.rmSync(import_node_path.default.join(unpackConfig.root, tempDirectory), { recursive: true, force: true });
56
+ (0, import_core.removeDir)(import_node_path.default.join(unpackConfig.root, tempDirectory));
56
57
  const globalImport = userOptions.globalImport?.reduce((acc, curr) => {
57
58
  return `${acc}
58
59
  import '${(0, import_core.getPathInJs)(import_node_path.default.resolve(unpackConfig.root, curr))}'`;
@@ -114,16 +115,17 @@ ${renderer}
114
115
  pageConfig.template = import_node_path.default.join(indexFilePath, "../", pageConfig.template);
115
116
  }
116
117
  html2.push({
117
- template: unpackConfig.html?.template || "",
118
- templateContent: unpackConfig.html?.templateContent || import_core.TEMPLATE_CONTENT,
118
+ template: unpackConfig.html?.template || (isRspack ? void 0 : ""),
119
+ // @ts-expect-error
120
+ templateContent: unpackConfig.html?.templateContent || (!unpackConfig.html?.template ? import_core.TEMPLATE_CONTENT : isRspack ? void 0 : false),
119
121
  minify: false,
120
122
  filename: `${entryName}.html`,
121
123
  chunks: [entryName],
122
124
  ...pageConfig,
123
125
  templateParameters: {
124
126
  mountId: unpackConfig.html?.mountId,
125
- title: (0, import_core.isFunction)(unpackConfig.html?.title) ? unpackConfig.html?.title({ entryName }) : unpackConfig.html?.title,
126
- headTag: unpackConfig.html?.headTag,
127
+ title: (0, import_core.isFunction)(unpackConfig.html?.title) ? unpackConfig.html?.title({ entryName }) : unpackConfig.html?.title || "",
128
+ headTag: unpackConfig.html?.headTag || "",
127
129
  ...unpackConfig.html?.templateParameters,
128
130
  ...pageConfig.templateParameters
129
131
  }
@@ -138,11 +140,11 @@ ${renderer}
138
140
  const { entry, html } = collectEntry();
139
141
  config = mergeConfig(config, {
140
142
  entry: createTempFile(entry),
141
- plugins: html.map((h) => new import_html_webpack_plugin.default(h))
143
+ plugins: html.map((h) => new HtmlPlugin(h))
142
144
  });
143
145
  return config;
144
146
  };
145
147
  // Annotate the CommonJS export names for ESM import in node:
146
148
  0 && (module.exports = {
147
- addMpaSupport
149
+ applyMpaConfig
148
150
  });
package/dist/mpa.d.ts CHANGED
@@ -1,7 +1,8 @@
1
1
  import { type BundlerConfiguration, type UnpackConfig } from '@unpackjs/core';
2
- export declare const addMpaSupport: ({ config, unpackConfig, mergeConfig, }: {
2
+ export declare const applyMpaConfig: ({ config, unpackConfig, mergeConfig, HtmlPlugin, }: {
3
3
  config: BundlerConfiguration;
4
4
  unpackConfig: UnpackConfig;
5
5
  mergeConfig: (...configs: BundlerConfiguration[]) => BundlerConfiguration;
6
+ HtmlPlugin: any;
6
7
  }) => BundlerConfiguration;
7
8
  //# sourceMappingURL=mpa.d.ts.map
package/dist/mpa.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"mpa.d.ts","sourceRoot":"","sources":["../src/mpa.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,KAAK,oBAAoB,EAGzB,KAAK,YAAY,EAOlB,MAAM,gBAAgB,CAAA;AAavB,eAAO,MAAM,aAAa,2CAIvB;IACD,MAAM,EAAE,oBAAoB,CAAA;IAC5B,YAAY,EAAE,YAAY,CAAA;IAC1B,WAAW,EAAE,CAAC,GAAG,OAAO,EAAE,oBAAoB,EAAE,KAAK,oBAAoB,CAAA;CAC1E,KAAG,oBAyGH,CAAA"}
1
+ {"version":3,"file":"mpa.d.ts","sourceRoot":"","sources":["../src/mpa.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,KAAK,oBAAoB,EAGzB,KAAK,YAAY,EAQlB,MAAM,gBAAgB,CAAA;AAYvB,eAAO,MAAM,cAAc,uDAKxB;IACD,MAAM,EAAE,oBAAoB,CAAA;IAC5B,YAAY,EAAE,YAAY,CAAA;IAC1B,WAAW,EAAE,CAAC,GAAG,OAAO,EAAE,oBAAoB,EAAE,KAAK,oBAAoB,CAAA;IACzE,UAAU,EAAE,GAAG,CAAA;CAChB,KAAG,oBA6GH,CAAA"}
package/dist/mpa.js CHANGED
@@ -17,16 +17,18 @@ import {
17
17
  isDevServer,
18
18
  isFunction,
19
19
  isPlainObject,
20
- logger
20
+ logger,
21
+ removeDir
21
22
  } from "@unpackjs/core";
22
- import HtmlWebpackPlugin from "html-webpack-plugin";
23
- const addMpaSupport = ({
23
+ const applyMpaConfig = ({
24
24
  config,
25
25
  unpackConfig,
26
- mergeConfig
26
+ mergeConfig,
27
+ HtmlPlugin
27
28
  }) => {
28
29
  if (!unpackConfig.mpa)
29
30
  return config;
31
+ const isRspack = unpackConfig.bundler === "rspack";
30
32
  const tempDirectory = path2.join(TEMP_DIR, "mpa");
31
33
  const userOptions = isPlainObject(unpackConfig.mpa) ? unpackConfig.mpa : {};
32
34
  const getPageConfig = (indexPath) => {
@@ -38,7 +40,7 @@ const addMpaSupport = ({
38
40
  return pageConfig;
39
41
  };
40
42
  const createTempFile = (entry2) => {
41
- fs.rmSync(path2.join(unpackConfig.root, tempDirectory), { recursive: true, force: true });
43
+ removeDir(path2.join(unpackConfig.root, tempDirectory));
42
44
  const globalImport = userOptions.globalImport?.reduce((acc, curr) => {
43
45
  return `${acc}
44
46
  import '${getPathInJs(path2.resolve(unpackConfig.root, curr))}'`;
@@ -100,16 +102,17 @@ ${renderer}
100
102
  pageConfig.template = path2.join(indexFilePath, "../", pageConfig.template);
101
103
  }
102
104
  html2.push({
103
- template: unpackConfig.html?.template || "",
104
- templateContent: unpackConfig.html?.templateContent || TEMPLATE_CONTENT,
105
+ template: unpackConfig.html?.template || (isRspack ? void 0 : ""),
106
+ // @ts-expect-error
107
+ templateContent: unpackConfig.html?.templateContent || (!unpackConfig.html?.template ? TEMPLATE_CONTENT : isRspack ? void 0 : false),
105
108
  minify: false,
106
109
  filename: `${entryName}.html`,
107
110
  chunks: [entryName],
108
111
  ...pageConfig,
109
112
  templateParameters: {
110
113
  mountId: unpackConfig.html?.mountId,
111
- title: isFunction(unpackConfig.html?.title) ? unpackConfig.html?.title({ entryName }) : unpackConfig.html?.title,
112
- headTag: unpackConfig.html?.headTag,
114
+ title: isFunction(unpackConfig.html?.title) ? unpackConfig.html?.title({ entryName }) : unpackConfig.html?.title || "",
115
+ headTag: unpackConfig.html?.headTag || "",
113
116
  ...unpackConfig.html?.templateParameters,
114
117
  ...pageConfig.templateParameters
115
118
  }
@@ -124,10 +127,10 @@ ${renderer}
124
127
  const { entry, html } = collectEntry();
125
128
  config = mergeConfig(config, {
126
129
  entry: createTempFile(entry),
127
- plugins: html.map((h) => new HtmlWebpackPlugin(h))
130
+ plugins: html.map((h) => new HtmlPlugin(h))
128
131
  });
129
132
  return config;
130
133
  };
131
134
  export {
132
- addMpaSupport
135
+ applyMpaConfig
133
136
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unpackjs/plugin-react",
3
- "version": "1.6.4",
3
+ "version": "1.7.1",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "exports": {
@@ -28,14 +28,13 @@
28
28
  "@babel/plugin-transform-class-properties": "7.25.9",
29
29
  "@pmmmwh/react-refresh-webpack-plugin": "0.5.15",
30
30
  "@rspack/plugin-react-refresh": "1.0.0",
31
- "@swc/core": "1.9.1",
32
- "@swc/helpers": "0.5.13",
31
+ "@swc/core": "1.9.2",
32
+ "@swc/helpers": "0.5.15",
33
33
  "babel-plugin-react-compiler": "latest",
34
- "html-webpack-plugin": "5.6.3",
35
34
  "launch-editor": "2.9.1",
36
35
  "react-refresh": "0.14.2",
37
36
  "swc-loader": "0.2.6",
38
- "@unpackjs/core": "^1.6.4"
37
+ "@unpackjs/core": "^1.7.1"
39
38
  },
40
39
  "scripts": {
41
40
  "dev": "modern build --watch",