@unpackjs/plugin-react 1.7.0 → 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,19 +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
- const addMpaSupport = ({
36
+ const applyMpaConfig = ({
37
37
  config,
38
38
  unpackConfig,
39
- mergeConfig
39
+ mergeConfig,
40
+ HtmlPlugin
40
41
  }) => {
41
42
  if (!unpackConfig.mpa)
42
43
  return config;
44
+ const isRspack = unpackConfig.bundler === "rspack";
43
45
  const tempDirectory = import_node_path.default.join(import_core.TEMP_DIR, "mpa");
44
46
  const userOptions = (0, import_core.isPlainObject)(unpackConfig.mpa) ? unpackConfig.mpa : {};
45
47
  const getPageConfig = (indexPath) => {
@@ -51,7 +53,7 @@ const addMpaSupport = ({
51
53
  return pageConfig;
52
54
  };
53
55
  const createTempFile = (entry2) => {
54
- 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));
55
57
  const globalImport = userOptions.globalImport?.reduce((acc, curr) => {
56
58
  return `${acc}
57
59
  import '${(0, import_core.getPathInJs)(import_node_path.default.resolve(unpackConfig.root, curr))}'`;
@@ -113,16 +115,17 @@ ${renderer}
113
115
  pageConfig.template = import_node_path.default.join(indexFilePath, "../", pageConfig.template);
114
116
  }
115
117
  html2.push({
116
- template: unpackConfig.html?.template || "",
117
- templateContent: unpackConfig.html?.templateContent || !unpackConfig.html?.template && 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),
118
121
  minify: false,
119
122
  filename: `${entryName}.html`,
120
123
  chunks: [entryName],
121
124
  ...pageConfig,
122
125
  templateParameters: {
123
126
  mountId: unpackConfig.html?.mountId,
124
- title: (0, import_core.isFunction)(unpackConfig.html?.title) ? unpackConfig.html?.title({ entryName }) : unpackConfig.html?.title,
125
- 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 || "",
126
129
  ...unpackConfig.html?.templateParameters,
127
130
  ...pageConfig.templateParameters
128
131
  }
@@ -137,11 +140,11 @@ ${renderer}
137
140
  const { entry, html } = collectEntry();
138
141
  config = mergeConfig(config, {
139
142
  entry: createTempFile(entry),
140
- plugins: html.map((h) => new import_core.HtmlPlugin(h))
143
+ plugins: html.map((h) => new HtmlPlugin(h))
141
144
  });
142
145
  return config;
143
146
  };
144
147
  // Annotate the CommonJS export names for ESM import in node:
145
148
  0 && (module.exports = {
146
- addMpaSupport
149
+ applyMpaConfig
147
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,EAIzB,KAAK,YAAY,EAOlB,MAAM,gBAAgB,CAAA;AAYvB,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,oBA2GH,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
@@ -10,7 +10,6 @@ var __filename = /* @__PURE__ */ getFilename();
10
10
  import fs from "node:fs";
11
11
  import path2 from "node:path";
12
12
  import {
13
- HtmlPlugin,
14
13
  TEMPLATE_CONTENT,
15
14
  TEMP_DIR,
16
15
  colors,
@@ -18,15 +17,18 @@ import {
18
17
  isDevServer,
19
18
  isFunction,
20
19
  isPlainObject,
21
- logger
20
+ logger,
21
+ removeDir
22
22
  } from "@unpackjs/core";
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 || !unpackConfig.html?.template && 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
  }
@@ -129,5 +132,5 @@ ${renderer}
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.7.0",
3
+ "version": "1.7.1",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "exports": {
@@ -34,7 +34,7 @@
34
34
  "launch-editor": "2.9.1",
35
35
  "react-refresh": "0.14.2",
36
36
  "swc-loader": "0.2.6",
37
- "@unpackjs/core": "^1.7.0"
37
+ "@unpackjs/core": "^1.7.1"
38
38
  },
39
39
  "scripts": {
40
40
  "dev": "modern build --watch",