react-cosmos-plugin-rspack 0.2.0 → 0.3.0

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.
@@ -161,87 +161,16 @@ import {
161
161
  moduleExists
162
162
  } from "react-cosmos";
163
163
 
164
+ // src/server/rspackConfig/getDefaultRspackConfig.ts
165
+ import {
166
+ HtmlRspackPlugin
167
+ } from "@rspack/core";
168
+
164
169
  // src/server/rspackConfig/getRspackNodeEnv.ts
165
170
  function getRspackNodeEnv() {
166
171
  return process.env.NODE_ENV === "production" ? "production" : "development";
167
172
  }
168
173
 
169
- // src/server/utils/omit.ts
170
- function omit(o, fields) {
171
- const result = { ...o };
172
- for (const field of fields) {
173
- delete result[field];
174
- }
175
- return result;
176
- }
177
-
178
- // src/server/rspackConfig/plugins.ts
179
- function getGlobalsPlugin({ publicUrl }, userRspack, devServerOn) {
180
- const cleanPublicUrl = removeTrailingSlash(publicUrl);
181
- return new userRspack.DefinePlugin({
182
- // "if (__DEV__)" blocks get stripped when compiling a static export build
183
- __DEV__: JSON.stringify(devServerOn),
184
- "process.env.NODE_ENV": JSON.stringify(getRspackNodeEnv()),
185
- "process.env.PUBLIC_URL": JSON.stringify(cleanPublicUrl)
186
- });
187
- }
188
- function hasPlugin(plugins, pluginName) {
189
- return plugins && plugins.filter((p) => isInstanceOfRspackPlugin(p, pluginName)).length > 0;
190
- }
191
- function isInstanceOfRspackPlugin(plugin, constructorName) {
192
- return plugin.constructor && plugin.constructor.name === constructorName;
193
- }
194
- function ignoreEmptyRspackPlugins(plugins = []) {
195
- return plugins.filter(Boolean);
196
- }
197
- function removeTrailingSlash(url) {
198
- return url.replace(/\/$/, "");
199
- }
200
-
201
- // src/server/rspackConfig/htmlPlugin.ts
202
- function ensureHtmlWebpackPlugin({ rootDir }, plugins) {
203
- if (hasPlugin(plugins, "HtmlWebpackPlugin")) {
204
- return plugins.map(
205
- (plugin) => isHtmlWebpackPlugin(plugin) ? changeHtmlPluginFilename(plugin) : plugin
206
- );
207
- }
208
- const htmlWebpackPlugin = getHtmlWebpackPlugin(rootDir);
209
- if (!htmlWebpackPlugin) {
210
- return plugins;
211
- }
212
- return [
213
- ...plugins,
214
- new htmlWebpackPlugin({
215
- title: "React Cosmos",
216
- filename: RENDERER_FILENAME
217
- })
218
- ];
219
- }
220
- function getHtmlWebpackPlugin(rootDir) {
221
- return requireFromSilent(
222
- rootDir,
223
- "html-webpack-plugin"
224
- );
225
- }
226
- function isHtmlWebpackPlugin(plugin) {
227
- return isInstanceOfRspackPlugin(plugin, "HtmlWebpackPlugin");
228
- }
229
- function changeHtmlPluginFilename(htmlPlugin) {
230
- if (!isIndexHtmlWebpackPlugin(htmlPlugin)) {
231
- return htmlPlugin;
232
- }
233
- const options = htmlPlugin.userOptions || htmlPlugin.options;
234
- const safeOptions = omit(options, ["chunks"]);
235
- return new htmlPlugin.constructor({
236
- ...safeOptions,
237
- filename: RENDERER_FILENAME
238
- });
239
- }
240
- function isIndexHtmlWebpackPlugin(htmlPlugin) {
241
- const { filename } = htmlPlugin.userOptions || htmlPlugin.options;
242
- return filename === "index.html" || typeof filename !== "string" || filename.endsWith("/index.html");
243
- }
244
-
245
174
  // src/server/rspackConfig/getDefaultRspackConfig.ts
246
175
  function getDefaultRspackConfig(rootDir) {
247
176
  const postcssLoaderPath = resolveFromSilent(rootDir, "postcss-loader");
@@ -286,15 +215,9 @@ function getDefaultRspackConfig(rootDir) {
286
215
  exclude: [/[\\/]node_modules[\\/]/]
287
216
  });
288
217
  }
289
- const htmlWebpackPlugin = getHtmlWebpackPlugin(rootDir);
290
- if (htmlWebpackPlugin) {
291
- plugins.push(
292
- new htmlWebpackPlugin({
293
- title: "React Cosmos",
294
- filename: RENDERER_FILENAME
295
- })
296
- );
297
- }
218
+ plugins.push(
219
+ new HtmlRspackPlugin({ title: "React Cosmos", filename: RENDERER_FILENAME })
220
+ );
298
221
  const config = {
299
222
  // Besides other advantages, cheap-module-source-map is compatible with
300
223
  // React.componentDidCatch https://github.com/facebook/react/issues/10441
@@ -445,6 +368,77 @@ function addAlias(alias, name, value) {
445
368
  return { ...alias, [name]: value };
446
369
  }
447
370
 
371
+ // src/server/rspackConfig/htmlPlugin.ts
372
+ import {
373
+ HtmlRspackPlugin as HtmlRspackPlugin2
374
+ } from "@rspack/core";
375
+
376
+ // src/server/utils/omit.ts
377
+ function omit(o, fields) {
378
+ const result = { ...o };
379
+ for (const field of fields) {
380
+ delete result[field];
381
+ }
382
+ return result;
383
+ }
384
+
385
+ // src/server/rspackConfig/plugins.ts
386
+ function getGlobalsPlugin({ publicUrl }, userRspack, devServerOn) {
387
+ const cleanPublicUrl = removeTrailingSlash(publicUrl);
388
+ return new userRspack.DefinePlugin({
389
+ // "if (__DEV__)" blocks get stripped when compiling a static export build
390
+ __DEV__: JSON.stringify(devServerOn),
391
+ "process.env.NODE_ENV": JSON.stringify(getRspackNodeEnv()),
392
+ "process.env.PUBLIC_URL": JSON.stringify(cleanPublicUrl)
393
+ });
394
+ }
395
+ function hasPlugin(plugins, pluginName) {
396
+ return plugins && plugins.filter((p) => isInstanceOfRspackPlugin(p, pluginName)).length > 0;
397
+ }
398
+ function isInstanceOfRspackPlugin(plugin, constructorName) {
399
+ return plugin.constructor && plugin.constructor.name === constructorName;
400
+ }
401
+ function ignoreEmptyRspackPlugins(plugins = []) {
402
+ return plugins.filter(Boolean);
403
+ }
404
+ function removeTrailingSlash(url) {
405
+ return url.replace(/\/$/, "");
406
+ }
407
+
408
+ // src/server/rspackConfig/htmlPlugin.ts
409
+ function ensureHtmlWebpackPlugin(plugins) {
410
+ if (hasPlugin(plugins, "HtmlWebpackPlugin")) {
411
+ return plugins.map(
412
+ (plugin) => isHtmlWebpackPlugin(plugin) ? changeHtmlPluginFilename(plugin) : plugin
413
+ );
414
+ }
415
+ return [
416
+ ...plugins,
417
+ new HtmlRspackPlugin2({
418
+ title: "React Cosmos",
419
+ filename: RENDERER_FILENAME
420
+ })
421
+ ];
422
+ }
423
+ function isHtmlWebpackPlugin(plugin) {
424
+ return isInstanceOfRspackPlugin(plugin, "HtmlWebpackPlugin");
425
+ }
426
+ function changeHtmlPluginFilename(htmlPlugin) {
427
+ if (!isIndexHtmlWebpackPlugin(htmlPlugin)) {
428
+ return htmlPlugin;
429
+ }
430
+ const options = htmlPlugin.userOptions || htmlPlugin.options;
431
+ const safeOptions = omit(options, ["chunks"]);
432
+ return new htmlPlugin.constructor({
433
+ ...safeOptions,
434
+ filename: RENDERER_FILENAME
435
+ });
436
+ }
437
+ function isIndexHtmlWebpackPlugin(htmlPlugin) {
438
+ const { filename } = htmlPlugin.userOptions || htmlPlugin.options;
439
+ return filename === "index.html" || typeof filename !== "string" || filename.endsWith("/index.html");
440
+ }
441
+
448
442
  // src/server/rspackConfig/rspackConfigTopLevelAwait.ts
449
443
  function ensureRspackConfigTopLevelAwait(baseWebpackConfig) {
450
444
  const experiments = baseWebpackConfig.experiments || {};
@@ -496,7 +490,7 @@ function getPlugins(cosmosConfig, baseRspackConfig, userRspack) {
496
490
  const hmrPlugin = new userRspack.HotModuleReplacementPlugin();
497
491
  plugins = [...plugins, hmrPlugin];
498
492
  }
499
- return ensureHtmlWebpackPlugin(cosmosConfig, plugins);
493
+ return ensureHtmlWebpackPlugin(plugins);
500
494
  }
501
495
  function getHotMiddlewareEntry(reloadOnFail) {
502
496
  const clientPath = resolve("webpack-hot-middleware/client");
@@ -625,10 +619,7 @@ function getOutput2(cosmosConfig) {
625
619
  function getPlugins2(cosmosConfig, baseRspackConfig, userRspack) {
626
620
  const existingPlugins = ignoreEmptyRspackPlugins(baseRspackConfig.plugins);
627
621
  const globalsPlugin = getGlobalsPlugin(cosmosConfig, userRspack, false);
628
- return ensureHtmlWebpackPlugin(cosmosConfig, [
629
- ...existingPlugins,
630
- globalsPlugin
631
- ]);
622
+ return ensureHtmlWebpackPlugin([...existingPlugins, globalsPlugin]);
632
623
  }
633
624
  function getExperiments2(baseWebpackConfig) {
634
625
  return ensureRspackConfigTopLevelAwait(baseWebpackConfig);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-cosmos-plugin-rspack",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "description": "rspack plugin for React Cosmos",
5
5
  "repository": "https://github.com/birchill/react-cosmos-plugin-rspack/",
6
6
  "author": "Birchill, Inc.",
@@ -18,10 +18,9 @@
18
18
  },
19
19
  "devDependencies": {
20
20
  "@release-it/conventional-changelog": "8.0.1",
21
- "@rspack/core": "1.0.0-beta.4",
21
+ "@rspack/core": "1.0.0-beta.5",
22
22
  "@types/node": "20.14.9",
23
23
  "@types/webpack-hot-middleware": "2.25.9",
24
- "html-webpack-plugin": "5.6.0",
25
24
  "husky": "9.0.11",
26
25
  "knip": "5.23.3",
27
26
  "lint-staged": "15.2.7",