@unpackjs/plugin-react 3.2.2 → 3.2.4

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
@@ -87,15 +87,14 @@ import '${(0, core_namespaceObject.getPathInJs)(external_node_path_default().res
87
87
  return null;
88
88
  })(external_node_path_default().join(pagesRoot, filename));
89
89
  if (indexFilePath) {
90
- var _unpackConfig_html, _unpackConfig_html1, _unpackConfig_html2, _unpackConfig_html3, _unpackConfig_html4, _unpackConfig_html5, _unpackConfig_html6, _unpackConfig_html7, _unpackConfig_html8;
91
90
  let filePath, pageConfig, pageConfig1 = (filePath = external_node_path_default().join(indexFilePath, '../config.json'), pageConfig = {}, external_node_fs_default().existsSync(filePath) && (pageConfig = JSON.parse(external_node_fs_default().readFileSync(filePath, 'utf-8'))), pageConfig), entryName = !0 === userOptions.lowerCase ? filename.toLowerCase() : filename;
92
91
  pageConfig1.filename && (entryName = pageConfig1.filename.slice(0, -5)), entry[entryName] = {
93
92
  import: [
94
93
  indexFilePath
95
94
  ]
96
95
  }, pageConfig1.template && (pageConfig1.template = external_node_path_default().join(indexFilePath, '../', pageConfig1.template)), html.push({
97
- template: (null == (_unpackConfig_html = unpackConfig.html) ? void 0 : _unpackConfig_html.template) || void 0,
98
- templateContent: (null == (_unpackConfig_html1 = unpackConfig.html) ? void 0 : _unpackConfig_html1.templateContent) || ((null == (_unpackConfig_html2 = unpackConfig.html) ? void 0 : _unpackConfig_html2.template) ? void 0 : core_namespaceObject.TEMPLATE_CONTENT),
96
+ template: unpackConfig.html?.template || void 0,
97
+ templateContent: unpackConfig.html?.templateContent || (unpackConfig.html?.template ? void 0 : core_namespaceObject.TEMPLATE_CONTENT),
99
98
  minify: !1,
100
99
  filename: `${entryName}.html`,
101
100
  chunks: [
@@ -103,12 +102,12 @@ import '${(0, core_namespaceObject.getPathInJs)(external_node_path_default().res
103
102
  ],
104
103
  ...pageConfig1,
105
104
  templateParameters: {
106
- mountId: null == (_unpackConfig_html3 = unpackConfig.html) ? void 0 : _unpackConfig_html3.mountId,
107
- title: (0, core_namespaceObject.isFunction)(null == (_unpackConfig_html4 = unpackConfig.html) ? void 0 : _unpackConfig_html4.title) ? null == (_unpackConfig_html5 = unpackConfig.html) ? void 0 : _unpackConfig_html5.title({
105
+ mountId: unpackConfig.html?.mountId || '',
106
+ title: (0, core_namespaceObject.isFunction)(unpackConfig.html?.title) ? unpackConfig.html?.title({
108
107
  entryName
109
- }) : (null == (_unpackConfig_html6 = unpackConfig.html) ? void 0 : _unpackConfig_html6.title) || '',
110
- headTag: (null == (_unpackConfig_html7 = unpackConfig.html) ? void 0 : _unpackConfig_html7.headTag) || '',
111
- ...null == (_unpackConfig_html8 = unpackConfig.html) ? void 0 : _unpackConfig_html8.templateParameters,
108
+ }) : unpackConfig.html?.title || '',
109
+ headTag: unpackConfig.html?.headTag || '',
110
+ ...unpackConfig.html?.templateParameters,
112
111
  ...pageConfig1.templateParameters
113
112
  }
114
113
  });
@@ -119,10 +118,9 @@ import '${(0, core_namespaceObject.getPathInJs)(external_node_path_default().res
119
118
  });
120
119
  return (0, core_namespaceObject.mergeConfig)(config, {
121
120
  entry: ((entry)=>{
122
- var _userOptions_globalImport, _unpackConfig_html;
123
121
  let root = unpackConfig.root;
124
122
  (0, core_namespaceObject.removeDir)(external_node_path_default().join(root, tempDirectory));
125
- let globalImport = (null == (_userOptions_globalImport = userOptions.globalImport) ? void 0 : _userOptions_globalImport.reduce((acc, curr)=>`${acc}\nimport '${(0, core_namespaceObject.getPathInJs)(external_node_path_default().resolve(root, curr))}'`, '')) || '', { layout } = userOptions, layoutImport = layout ? `import Layout from '${(0, core_namespaceObject.getPathInJs)(external_node_path_default().resolve(root, layout))}'` : '', layoutJSX = layout ? '<Layout><App /></Layout>' : '<App />', rootElement = `document.getElementById('${null == (_unpackConfig_html = unpackConfig.html) ? void 0 : _unpackConfig_html.mountId}')`, renderer = `ReactDOM.createRoot(${rootElement}).render(${layoutJSX})`;
123
+ let globalImport = userOptions.globalImport?.reduce((acc, curr)=>`${acc}\nimport '${(0, core_namespaceObject.getPathInJs)(external_node_path_default().resolve(root, curr))}'`, '') || '', { layout } = userOptions, layoutImport = layout ? `import Layout from '${(0, core_namespaceObject.getPathInJs)(external_node_path_default().resolve(root, layout))}'` : '', layoutJSX = layout ? '<Layout><App /></Layout>' : '<App />', rootElement = `document.getElementById('${unpackConfig.html?.mountId}')`, renderer = `ReactDOM.createRoot(${rootElement}).render(${layoutJSX})`;
126
124
  return Object.entries(entry).forEach(([entryName, entryConfig])=>{
127
125
  let filePath = external_node_path_default().join(root, tempDirectory, `${entryName}.jsx`), tpl = `
128
126
  import React from 'react'
@@ -139,7 +137,9 @@ ${renderer}
139
137
  plugins: html1.map((h)=>new core_namespaceObject.rspack.HtmlRspackPlugin(h))
140
138
  });
141
139
  }, applySplitChunksConfig = ({ config })=>{
142
- let currentConfig = config.optimization.splitChunks, extraGroups = {};
140
+ let currentSplitChunks = config.optimization?.splitChunks;
141
+ if (!currentSplitChunks) return config;
142
+ let extraGroups = {};
143
143
  return extraGroups.react = {
144
144
  name: 'lib-react',
145
145
  test: (0, core_namespaceObject.isDevServer)() ? /node_modules[\\/](?:react|react-dom|scheduler|react-refresh|@rspack[\\/]plugin-react-refresh)[\\/]/ : /node_modules[\\/](?:react|react-dom|scheduler)[\\/]/,
@@ -149,10 +149,10 @@ ${renderer}
149
149
  test: /node_modules[\\/](?:react-router|react-router-dom|history|@remix-run[\\/]router)[\\/]/,
150
150
  priority: 0
151
151
  }, config.optimization.splitChunks = {
152
- ...currentConfig,
152
+ ...currentSplitChunks,
153
153
  cacheGroups: {
154
154
  ...extraGroups,
155
- ...currentConfig.cacheGroups
155
+ ...currentSplitChunks.cacheGroups ?? {}
156
156
  }
157
157
  }, config;
158
158
  }, PLUGIN_NAME = 'unpack:react', pluginReact = (options = {})=>{
@@ -160,7 +160,6 @@ ${renderer}
160
160
  return {
161
161
  name: PLUGIN_NAME,
162
162
  bundlerConfig: async (originalConfig, { unpackConfig, mergeConfig })=>{
163
- var _unpackConfig_performance_chunkSplit, _unpackConfig_performance;
164
163
  let config = originalConfig;
165
164
  unpackConfig.mpa && (config = applyMpaConfig({
166
165
  config,
@@ -168,7 +167,7 @@ ${renderer}
168
167
  })), (0, core_namespaceObject.isDev)() && clickToComponent && (config = await applyClickToComponentConfig({
169
168
  config,
170
169
  unpackConfig
171
- })), (null == (_unpackConfig_performance = unpackConfig.performance) || null == (_unpackConfig_performance_chunkSplit = _unpackConfig_performance.chunkSplit) ? void 0 : _unpackConfig_performance_chunkSplit.strategy) === 'split-by-experience' && (config = applySplitChunksConfig({
170
+ })), unpackConfig.performance?.chunkSplit?.strategy === 'split-by-experience' && (config = applySplitChunksConfig({
172
171
  config
173
172
  }));
174
173
  let jsExclude = [
package/dist/index.js CHANGED
@@ -1,8 +1,6 @@
1
1
  import __rslib_shim_module__ from 'module';
2
2
  let require = __rslib_shim_module__.createRequire(import.meta.url);
3
3
  import { fileURLToPath as __webpack_fileURLToPath__ } from "node:url";
4
- import { dirname as __webpack_dirname__ } from "node:path";
5
- import node_path from "node:path";
6
4
  import plugin_react_refresh from "@rspack/plugin-react-refresh";
7
5
  import { TEMPLATE_CONTENT, TEMP_DIR, addRestartCleaner, colors, esVersionToBrowserslist, getPathInJs, getPort, isDev, isDevServer, isFunction, isPlainObject, launchEditor, logger, mergeConfig as core_mergeConfig, removeDir, rspack } from "@unpackjs/core";
8
6
  import node_fs from "node:fs";
@@ -55,7 +53,6 @@ import '${getPathInJs(node_path.resolve(Object.values(config.entry)[0]))}'
55
53
  return {
56
54
  name: PLUGIN_NAME,
57
55
  bundlerConfig: async (originalConfig, { unpackConfig, mergeConfig })=>{
58
- var _unpackConfig_performance_chunkSplit, _unpackConfig_performance;
59
56
  let config = originalConfig;
60
57
  unpackConfig.mpa && (config = (({ config, unpackConfig })=>{
61
58
  let start, entry, html, pagesRoot, tempDirectory = node_path.join(TEMP_DIR, 'mpa'), userOptions = isPlainObject(unpackConfig.mpa) ? unpackConfig.mpa : {}, { entry: entry1, html: html1 } = (start = performance.now(), entry = {}, html = [], pagesRoot = node_path.join(unpackConfig.root, 'src', 'pages'), node_fs.readdirSync(pagesRoot).forEach((filename)=>{
@@ -71,15 +68,14 @@ import '${getPathInJs(node_path.resolve(Object.values(config.entry)[0]))}'
71
68
  return null;
72
69
  })(node_path.join(pagesRoot, filename));
73
70
  if (indexFilePath) {
74
- var _unpackConfig_html, _unpackConfig_html1, _unpackConfig_html2, _unpackConfig_html3, _unpackConfig_html4, _unpackConfig_html5, _unpackConfig_html6, _unpackConfig_html7, _unpackConfig_html8;
75
71
  let filePath, pageConfig, pageConfig1 = (filePath = node_path.join(indexFilePath, '../config.json'), pageConfig = {}, node_fs.existsSync(filePath) && (pageConfig = JSON.parse(node_fs.readFileSync(filePath, 'utf-8'))), pageConfig), entryName = !0 === userOptions.lowerCase ? filename.toLowerCase() : filename;
76
72
  pageConfig1.filename && (entryName = pageConfig1.filename.slice(0, -5)), entry[entryName] = {
77
73
  import: [
78
74
  indexFilePath
79
75
  ]
80
76
  }, pageConfig1.template && (pageConfig1.template = node_path.join(indexFilePath, '../', pageConfig1.template)), html.push({
81
- template: (null == (_unpackConfig_html = unpackConfig.html) ? void 0 : _unpackConfig_html.template) || void 0,
82
- templateContent: (null == (_unpackConfig_html1 = unpackConfig.html) ? void 0 : _unpackConfig_html1.templateContent) || ((null == (_unpackConfig_html2 = unpackConfig.html) ? void 0 : _unpackConfig_html2.template) ? void 0 : TEMPLATE_CONTENT),
77
+ template: unpackConfig.html?.template || void 0,
78
+ templateContent: unpackConfig.html?.templateContent || (unpackConfig.html?.template ? void 0 : TEMPLATE_CONTENT),
83
79
  minify: !1,
84
80
  filename: `${entryName}.html`,
85
81
  chunks: [
@@ -87,12 +83,12 @@ import '${getPathInJs(node_path.resolve(Object.values(config.entry)[0]))}'
87
83
  ],
88
84
  ...pageConfig1,
89
85
  templateParameters: {
90
- mountId: null == (_unpackConfig_html3 = unpackConfig.html) ? void 0 : _unpackConfig_html3.mountId,
91
- title: isFunction(null == (_unpackConfig_html4 = unpackConfig.html) ? void 0 : _unpackConfig_html4.title) ? null == (_unpackConfig_html5 = unpackConfig.html) ? void 0 : _unpackConfig_html5.title({
86
+ mountId: unpackConfig.html?.mountId || '',
87
+ title: isFunction(unpackConfig.html?.title) ? unpackConfig.html?.title({
92
88
  entryName
93
- }) : (null == (_unpackConfig_html6 = unpackConfig.html) ? void 0 : _unpackConfig_html6.title) || '',
94
- headTag: (null == (_unpackConfig_html7 = unpackConfig.html) ? void 0 : _unpackConfig_html7.headTag) || '',
95
- ...null == (_unpackConfig_html8 = unpackConfig.html) ? void 0 : _unpackConfig_html8.templateParameters,
89
+ }) : unpackConfig.html?.title || '',
90
+ headTag: unpackConfig.html?.headTag || '',
91
+ ...unpackConfig.html?.templateParameters,
96
92
  ...pageConfig1.templateParameters
97
93
  }
98
94
  });
@@ -103,10 +99,9 @@ import '${getPathInJs(node_path.resolve(Object.values(config.entry)[0]))}'
103
99
  });
104
100
  return core_mergeConfig(config, {
105
101
  entry: ((entry)=>{
106
- var _userOptions_globalImport, _unpackConfig_html;
107
102
  let root = unpackConfig.root;
108
103
  removeDir(node_path.join(root, tempDirectory));
109
- let globalImport = (null == (_userOptions_globalImport = userOptions.globalImport) ? void 0 : _userOptions_globalImport.reduce((acc, curr)=>`${acc}\nimport '${getPathInJs(node_path.resolve(root, curr))}'`, '')) || '', { layout } = userOptions, layoutImport = layout ? `import Layout from '${getPathInJs(node_path.resolve(root, layout))}'` : '', layoutJSX = layout ? '<Layout><App /></Layout>' : '<App />', rootElement = `document.getElementById('${null == (_unpackConfig_html = unpackConfig.html) ? void 0 : _unpackConfig_html.mountId}')`, renderer = `ReactDOM.createRoot(${rootElement}).render(${layoutJSX})`;
104
+ let globalImport = userOptions.globalImport?.reduce((acc, curr)=>`${acc}\nimport '${getPathInJs(node_path.resolve(root, curr))}'`, '') || '', { layout } = userOptions, layoutImport = layout ? `import Layout from '${getPathInJs(node_path.resolve(root, layout))}'` : '', layoutJSX = layout ? '<Layout><App /></Layout>' : '<App />', rootElement = `document.getElementById('${unpackConfig.html?.mountId}')`, renderer = `ReactDOM.createRoot(${rootElement}).render(${layoutJSX})`;
110
105
  return Object.entries(entry).forEach(([entryName, entryConfig])=>{
111
106
  let filePath = node_path.join(root, tempDirectory, `${entryName}.jsx`), tpl = `
112
107
  import React from 'react'
@@ -128,8 +123,10 @@ ${renderer}
128
123
  })), isDev() && clickToComponent && (config = await applyClickToComponentConfig({
129
124
  config,
130
125
  unpackConfig
131
- })), (null == (_unpackConfig_performance = unpackConfig.performance) || null == (_unpackConfig_performance_chunkSplit = _unpackConfig_performance.chunkSplit) ? void 0 : _unpackConfig_performance_chunkSplit.strategy) === 'split-by-experience' && (config = (({ config })=>{
132
- let currentConfig = config.optimization.splitChunks, extraGroups = {};
126
+ })), unpackConfig.performance?.chunkSplit?.strategy === 'split-by-experience' && (config = (({ config })=>{
127
+ let currentSplitChunks = config.optimization?.splitChunks;
128
+ if (!currentSplitChunks) return config;
129
+ let extraGroups = {};
133
130
  return extraGroups.react = {
134
131
  name: 'lib-react',
135
132
  test: isDevServer() ? /node_modules[\\/](?:react|react-dom|scheduler|react-refresh|@rspack[\\/]plugin-react-refresh)[\\/]/ : /node_modules[\\/](?:react|react-dom|scheduler)[\\/]/,
@@ -139,10 +136,10 @@ ${renderer}
139
136
  test: /node_modules[\\/](?:react-router|react-router-dom|history|@remix-run[\\/]router)[\\/]/,
140
137
  priority: 0
141
138
  }, config.optimization.splitChunks = {
142
- ...currentConfig,
139
+ ...currentSplitChunks,
143
140
  cacheGroups: {
144
141
  ...extraGroups,
145
- ...currentConfig.cacheGroups
142
+ ...currentSplitChunks.cacheGroups ?? {}
146
143
  }
147
144
  }, config;
148
145
  })({
@@ -230,4 +227,5 @@ ${renderer}
230
227
  }
231
228
  };
232
229
  };
230
+ import node_path, { dirname as __webpack_dirname__ } from "node:path";
233
231
  export { PLUGIN_NAME, pluginReact };
@@ -1 +1 @@
1
- {"version":3,"file":"mpa.d.ts","sourceRoot":"","sources":["../src/mpa.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,KAAK,oBAAoB,EAYzB,KAAK,YAAY,EAClB,MAAM,gBAAgB,CAAA;AAYvB,eAAO,MAAM,cAAc,GAAI,2BAG5B;IACD,MAAM,EAAE,oBAAoB,CAAA;IAC5B,YAAY,EAAE,YAAY,CAAA;CAC3B,KAAG,oBA4GH,CAAA"}
1
+ {"version":3,"file":"mpa.d.ts","sourceRoot":"","sources":["../src/mpa.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,KAAK,oBAAoB,EAYzB,KAAK,YAAY,EAClB,MAAM,gBAAgB,CAAA;AAYvB,eAAO,MAAM,cAAc,GAAI,2BAG5B;IACD,MAAM,EAAE,oBAAoB,CAAA;IAC5B,YAAY,EAAE,YAAY,CAAA;CAC3B,KAAG,oBA2GH,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"splitChunks.d.ts","sourceRoot":"","sources":["../src/splitChunks.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,oBAAoB,EAAiC,MAAM,gBAAgB,CAAA;AAEzF,eAAO,MAAM,sBAAsB,GAAI,YAAY;IAAE,MAAM,EAAE,oBAAoB,CAAA;CAAE,yCAwBlF,CAAA"}
1
+ {"version":3,"file":"splitChunks.d.ts","sourceRoot":"","sources":["../src/splitChunks.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,oBAAoB,EAAiC,MAAM,gBAAgB,CAAA;AAEzF,eAAO,MAAM,sBAAsB,GAAI,YAAY;IAAE,MAAM,EAAE,oBAAoB,CAAA;CAAE,yCA4BlF,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unpackjs/plugin-react",
3
- "version": "3.2.2",
3
+ "version": "3.2.4",
4
4
  "description": "React plugin for Unpack",
5
5
  "type": "module",
6
6
  "exports": {
@@ -24,13 +24,13 @@
24
24
  "access": "public"
25
25
  },
26
26
  "dependencies": {
27
- "@rspack/plugin-react-refresh": "1.5.1",
27
+ "@rspack/plugin-react-refresh": "1.5.3",
28
28
  "@svgr/webpack": "8.1.0",
29
29
  "@swc/helpers": "0.5.17",
30
30
  "react-refresh": "0.18.0"
31
31
  },
32
32
  "devDependencies": {
33
- "@unpackjs/core": "3.3.4"
33
+ "@unpackjs/core": "3.5.0"
34
34
  },
35
35
  "peerDependencies": {
36
36
  "@unpackjs/core": "3.x"