react-cosmos-plugin-rspack 0.1.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");
@@ -275,10 +204,9 @@ function getDefaultRspackConfig(rootDir) {
275
204
  type: "javascript/auto"
276
205
  });
277
206
  rules.push({
278
- test: /\.css?$/,
279
- exclude: [/[\\/]node_modules[\\/]/],
280
- use: postcssLoaderPath ? [{ loader: postcssLoaderPath }] : void 0,
281
- type: "css"
207
+ test: /\.css$/,
208
+ use: postcssLoaderPath ? [{ loader: postcssLoaderPath }] : [{ loader: "builtin:lightningcss-loader" }],
209
+ type: "css/auto"
282
210
  });
283
211
  if (mdxLoaderPath) {
284
212
  rules.push({
@@ -287,15 +215,9 @@ function getDefaultRspackConfig(rootDir) {
287
215
  exclude: [/[\\/]node_modules[\\/]/]
288
216
  });
289
217
  }
290
- const htmlWebpackPlugin = getHtmlWebpackPlugin(rootDir);
291
- if (htmlWebpackPlugin) {
292
- plugins.push(
293
- new htmlWebpackPlugin({
294
- title: "React Cosmos",
295
- filename: RENDERER_FILENAME
296
- })
297
- );
298
- }
218
+ plugins.push(
219
+ new HtmlRspackPlugin({ title: "React Cosmos", filename: RENDERER_FILENAME })
220
+ );
299
221
  const config = {
300
222
  // Besides other advantages, cheap-module-source-map is compatible with
301
223
  // React.componentDidCatch https://github.com/facebook/react/issues/10441
@@ -446,6 +368,77 @@ function addAlias(alias, name, value) {
446
368
  return { ...alias, [name]: value };
447
369
  }
448
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
+
449
442
  // src/server/rspackConfig/rspackConfigTopLevelAwait.ts
450
443
  function ensureRspackConfigTopLevelAwait(baseWebpackConfig) {
451
444
  const experiments = baseWebpackConfig.experiments || {};
@@ -497,7 +490,7 @@ function getPlugins(cosmosConfig, baseRspackConfig, userRspack) {
497
490
  const hmrPlugin = new userRspack.HotModuleReplacementPlugin();
498
491
  plugins = [...plugins, hmrPlugin];
499
492
  }
500
- return ensureHtmlWebpackPlugin(cosmosConfig, plugins);
493
+ return ensureHtmlWebpackPlugin(plugins);
501
494
  }
502
495
  function getHotMiddlewareEntry(reloadOnFail) {
503
496
  const clientPath = resolve("webpack-hot-middleware/client");
@@ -626,10 +619,7 @@ function getOutput2(cosmosConfig) {
626
619
  function getPlugins2(cosmosConfig, baseRspackConfig, userRspack) {
627
620
  const existingPlugins = ignoreEmptyRspackPlugins(baseRspackConfig.plugins);
628
621
  const globalsPlugin = getGlobalsPlugin(cosmosConfig, userRspack, false);
629
- return ensureHtmlWebpackPlugin(cosmosConfig, [
630
- ...existingPlugins,
631
- globalsPlugin
632
- ]);
622
+ return ensureHtmlWebpackPlugin([...existingPlugins, globalsPlugin]);
633
623
  }
634
624
  function getExperiments2(baseWebpackConfig) {
635
625
  return ensureRspackConfigTopLevelAwait(baseWebpackConfig);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-cosmos-plugin-rspack",
3
- "version": "0.1.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": "0.7.5",
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",
@@ -48,7 +47,7 @@
48
47
  "prepare": "husky"
49
48
  },
50
49
  "peerDependencies": {
51
- "@rspack/core": ">=0.6.0",
50
+ "@rspack/core": ">=1.0.0-beta.0",
52
51
  "react-cosmos": ">=6.0.0"
53
52
  },
54
53
  "lint-staged": {