react-cosmos-plugin-rspack 2.0.0 → 2.0.2

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.
@@ -1,701 +1,554 @@
1
- // src/server/rspackConfigPlugin.ts
2
- import * as path from "path";
3
-
4
- // src/server/rspackConfig/constants.ts
5
- var RENDERER_FILENAME = "renderer.html";
6
-
7
- // src/server/rspackConfigPlugin.ts
8
- async function rspackConfigPlugin({
9
- config
10
- }) {
11
- if (config.rendererUrl) {
12
- return config;
13
- }
14
- return {
15
- ...config,
16
- rendererUrl: path.join(config.publicUrl, RENDERER_FILENAME)
17
- };
18
- }
19
-
20
- // src/server/rspackDevServerPlugin.ts
21
- import * as path8 from "path";
22
- import { serveStaticDir } from "react-cosmos";
1
+ import { createRequire } from "node:module";
2
+ import * as path from "node:path";
3
+ import { fileExists, getCliArgs, importModule, moduleExists, serveStaticDir } from "react-cosmos";
23
4
  import webpackHotMiddleware from "webpack-hot-middleware";
24
-
25
- // src/server/cosmosConfig/createRspackCosmosConfig.ts
26
- import * as path3 from "path";
27
- import { fileExists } from "react-cosmos";
28
-
29
- // src/server/utils/resolveLoose.ts
30
- import * as path2 from "path";
31
-
32
- // src/server/utils/isNodeError.ts
5
+ import rspack from "@rspack/core";
6
+ //#region src/server/rspackConfig/constants.ts
7
+ const RENDERER_FILENAME = "renderer.html";
8
+ //#endregion
9
+ //#region src/server/rspackConfigPlugin.ts
10
+ async function rspackConfigPlugin({ config }) {
11
+ if (config.rendererUrl) return config;
12
+ return {
13
+ ...config,
14
+ rendererUrl: path.join(config.publicUrl, RENDERER_FILENAME)
15
+ };
16
+ }
17
+ //#endregion
18
+ //#region src/server/utils/isNodeError.ts
33
19
  function isNodeError(err) {
34
- return err && err.stack && err.message;
20
+ return err && err.stack && err.message;
35
21
  }
36
-
37
- // src/server/utils/resolve.ts
38
- import { createRequire } from "module";
22
+ //#endregion
23
+ //#region src/server/utils/resolve.ts
39
24
  function resolve(moduleId) {
40
- const require2 = createRequire(import.meta.url);
41
- return require2.resolve(moduleId);
25
+ return createRequire(import.meta.url).resolve(moduleId);
42
26
  }
43
27
  function resolveFrom(fromDirectory, moduleId) {
44
- const require2 = createRequire(import.meta.url);
45
- return require2.resolve(moduleId, { paths: [fromDirectory] });
28
+ return createRequire(import.meta.url).resolve(moduleId, { paths: [fromDirectory] });
46
29
  }
47
-
48
- // src/server/utils/resolveSilent.ts
30
+ //#endregion
31
+ //#region src/server/utils/resolveSilent.ts
49
32
  function resolveFromSilent(fromDirectory, moduleId) {
50
- try {
51
- return resolveFrom(fromDirectory, moduleId);
52
- } catch (err) {
53
- if (!isNodeError(err) || err.code !== "MODULE_NOT_FOUND") console.log(err);
54
- return null;
55
- }
56
- }
57
-
58
- // src/server/utils/resolveLoose.ts
33
+ try {
34
+ return resolveFrom(fromDirectory, moduleId);
35
+ } catch (err) {
36
+ if (!isNodeError(err) || err.code !== "MODULE_NOT_FOUND") console.log(err);
37
+ return null;
38
+ }
39
+ }
40
+ //#endregion
41
+ //#region src/server/utils/resolveLoose.ts
59
42
  function resolveLoose(fromDirectory, moduleId) {
60
- return path2.isAbsolute(moduleId) ? moduleId : resolveFromSilent(fromDirectory, moduleId) || // Final attempt: Resolve relative paths that don't either
61
- // 1. Don't start with ./
62
- // 2. Don't point to an existing file
63
- path2.join(fromDirectory, moduleId);
43
+ return path.isAbsolute(moduleId) ? moduleId : resolveFromSilent(fromDirectory, moduleId) || path.join(fromDirectory, moduleId);
64
44
  }
65
-
66
- // src/server/cosmosConfig/createRspackCosmosConfig.ts
45
+ //#endregion
46
+ //#region src/server/cosmosConfig/createRspackCosmosConfig.ts
67
47
  function createRspackCosmosConfig(cosmosConfig) {
68
- const { rootDir } = cosmosConfig;
69
- const configInput = cosmosConfig.rspack || {};
70
- return {
71
- configPath: getRspackConfigPath(configInput, rootDir),
72
- overridePath: getRspackOverridePath(configInput, rootDir),
73
- includeHashInOutputFilename: getIncludeHashInOutputFilename(configInput),
74
- hotReload: getHotReload(configInput),
75
- reloadOnFail: getReloadOnFail(configInput)
76
- };
48
+ const { rootDir } = cosmosConfig;
49
+ const configInput = cosmosConfig.rspack || {};
50
+ return {
51
+ configPath: getRspackConfigPath(configInput, rootDir),
52
+ overridePath: getRspackOverridePath(configInput, rootDir),
53
+ includeHashInOutputFilename: getIncludeHashInOutputFilename(configInput),
54
+ hotReload: getHotReload(configInput),
55
+ reloadOnFail: getReloadOnFail(configInput)
56
+ };
77
57
  }
78
58
  function getRspackConfigPath({ configPath }, rootDir) {
79
- if (typeof configPath === "undefined") {
80
- return resolveLoose(rootDir, "rspack.config.js");
81
- }
82
- if (!configPath) {
83
- return null;
84
- }
85
- const absPath = resolveLoose(rootDir, configPath);
86
- if (!fileExists(absPath)) {
87
- const relPath = path3.relative(process.cwd(), absPath);
88
- throw new Error(`rspack config not found at path: ${relPath}`);
89
- }
90
- return absPath;
59
+ if (typeof configPath === "undefined") return resolveLoose(rootDir, "rspack.config.js");
60
+ if (!configPath) return null;
61
+ const absPath = resolveLoose(rootDir, configPath);
62
+ if (!fileExists(absPath)) {
63
+ const relPath = path.relative(process.cwd(), absPath);
64
+ throw new Error(`rspack config not found at path: ${relPath}`);
65
+ }
66
+ return absPath;
91
67
  }
92
68
  function getRspackOverridePath({ overridePath }, rootDir) {
93
- if (typeof overridePath === "undefined") {
94
- return resolveLoose(rootDir, "rspack.override.js");
95
- }
96
- if (!overridePath) {
97
- return null;
98
- }
99
- const absPath = resolveLoose(rootDir, overridePath);
100
- if (!fileExists(absPath)) {
101
- const relPath = path3.relative(process.cwd(), absPath);
102
- throw new Error(`rspack override module not found at path: ${relPath}`);
103
- }
104
- return absPath;
105
- }
106
- function getIncludeHashInOutputFilename({
107
- includeHashInOutputFilename = false
108
- }) {
109
- return includeHashInOutputFilename;
69
+ if (typeof overridePath === "undefined") return resolveLoose(rootDir, "rspack.override.js");
70
+ if (!overridePath) return null;
71
+ const absPath = resolveLoose(rootDir, overridePath);
72
+ if (!fileExists(absPath)) {
73
+ const relPath = path.relative(process.cwd(), absPath);
74
+ throw new Error(`rspack override module not found at path: ${relPath}`);
75
+ }
76
+ return absPath;
77
+ }
78
+ function getIncludeHashInOutputFilename({ includeHashInOutputFilename = false }) {
79
+ return includeHashInOutputFilename;
110
80
  }
111
81
  function getHotReload({ hotReload = true }) {
112
- return hotReload;
82
+ return hotReload;
113
83
  }
114
84
  function getReloadOnFail({ reloadOnFail = false }) {
115
- return reloadOnFail;
85
+ return reloadOnFail;
116
86
  }
117
-
118
- // src/server/utils/requireModule.ts
119
- import { createRequire as createRequire2 } from "module";
120
- import * as path4 from "path";
87
+ //#endregion
88
+ //#region src/server/utils/requireModule.ts
121
89
  function requireFrom(fromDirectory, moduleId) {
122
- const require2 = createRequire2(path4.resolve(fromDirectory, "noop.js"));
123
- return require2(moduleId);
90
+ return createRequire(path.resolve(fromDirectory, "noop.js"))(moduleId);
124
91
  }
125
-
126
- // src/server/utils/requireSilent.ts
92
+ //#endregion
93
+ //#region src/server/utils/requireSilent.ts
127
94
  function requireFromSilent(fromDirectory, moduleId) {
128
- try {
129
- return requireFrom(fromDirectory, moduleId);
130
- } catch (err) {
131
- if (!isNodeError(err) || err.code !== "MODULE_NOT_FOUND") {
132
- console.log(err);
133
- }
134
- }
135
- }
136
-
137
- // src/server/getRspack.ts
95
+ try {
96
+ return requireFrom(fromDirectory, moduleId);
97
+ } catch (err) {
98
+ if (!isNodeError(err) || err.code !== "MODULE_NOT_FOUND") console.log(err);
99
+ }
100
+ }
101
+ //#endregion
102
+ //#region src/server/getRspack.ts
138
103
  function getRspack(rootDir) {
139
- const userRspack = requireFromSilent(
140
- rootDir,
141
- "@rspack/core"
142
- );
143
- if (!userRspack) {
144
- console.warn("[Cosmos] rspack dependency missing!");
145
- console.log(
146
- 'Install using "yarn add --dev @rspack/core" or "npm install --save-dev @rspack/core"'
147
- );
148
- return;
149
- }
150
- return userRspack.rspack;
151
- }
152
-
153
- // src/server/rspackConfig/getDevRspackConfig.ts
154
- import * as path7 from "path";
155
-
156
- // src/server/rspackConfig/getUserRspackConfig.ts
157
- import * as path5 from "path";
158
- import {
159
- getCliArgs,
160
- importModule,
161
- moduleExists
162
- } from "react-cosmos";
163
-
164
- // src/server/rspackConfig/getDefaultRspackConfig.ts
165
- import rspack from "@rspack/core";
166
-
167
- // src/server/rspackConfig/getRspackNodeEnv.ts
104
+ const userRspack = requireFromSilent(rootDir, "@rspack/core");
105
+ if (!userRspack) {
106
+ console.warn("[Cosmos] rspack dependency missing!");
107
+ console.log("Install using \"yarn add --dev @rspack/core\" or \"npm install --save-dev @rspack/core\"");
108
+ return;
109
+ }
110
+ return userRspack.rspack;
111
+ }
112
+ //#endregion
113
+ //#region src/server/rspackConfig/getRspackNodeEnv.ts
168
114
  function getRspackNodeEnv() {
169
- return process.env.NODE_ENV === "production" ? "production" : "development";
115
+ return process.env.NODE_ENV === "production" ? "production" : "development";
170
116
  }
171
-
172
- // src/server/rspackConfig/getDefaultRspackConfig.ts
117
+ //#endregion
118
+ //#region src/server/rspackConfig/getDefaultRspackConfig.ts
173
119
  function getDefaultRspackConfig(rootDir) {
174
- const postcssLoaderPath = resolveFromSilent(rootDir, "postcss-loader");
175
- const mdxLoaderPath = resolveFromSilent(rootDir, "@mdx-js/loader");
176
- const rules = [];
177
- const plugins = [];
178
- rules.push({
179
- test: /\.(j|t)s$/,
180
- exclude: [/[\\/]node_modules[\\/]/],
181
- loader: "builtin:swc-loader",
182
- options: {
183
- sourceMaps: true,
184
- jsc: { parser: { syntax: "typescript" } }
185
- },
186
- type: "javascript/auto"
187
- });
188
- rules.push({
189
- test: /\.(j|t)sx$/,
190
- loader: "builtin:swc-loader",
191
- exclude: [/[\\/]node_modules[\\/]/],
192
- options: {
193
- sourceMaps: true,
194
- jsc: {
195
- parser: {
196
- syntax: "typescript",
197
- tsx: true
198
- },
199
- transform: { react: { runtime: "automatic" } }
200
- }
201
- },
202
- type: "javascript/auto"
203
- });
204
- rules.push({
205
- test: /\.css$/,
206
- use: postcssLoaderPath ? [{ loader: postcssLoaderPath }] : [{ loader: "builtin:lightningcss-loader" }],
207
- type: "css/auto"
208
- });
209
- if (mdxLoaderPath) {
210
- rules.push({
211
- test: /\.mdx$/,
212
- loader: mdxLoaderPath,
213
- exclude: [/[\\/]node_modules[\\/]/]
214
- });
215
- }
216
- plugins.push(
217
- new rspack.HtmlRspackPlugin({
218
- title: "React Cosmos",
219
- filename: RENDERER_FILENAME
220
- })
221
- );
222
- const config = {
223
- // Besides other advantages, cheap-module-source-map is compatible with
224
- // React.componentDidCatch https://github.com/facebook/react/issues/10441
225
- devtool: "cheap-module-source-map",
226
- resolve: {
227
- extensionAlias: {
228
- ".js": [".ts", ".tsx", ".js"]
229
- },
230
- extensions: [".js", ".jsx", ".ts", ".tsx"]
231
- },
232
- module: {
233
- rules
234
- },
235
- plugins,
236
- stats: {
237
- preset: "errors-only",
238
- builtAt: true
239
- },
240
- infrastructureLogging: { level: "warn" },
241
- experiments: {
242
- topLevelAwait: true
243
- }
244
- };
245
- return {
246
- ...config,
247
- mode: getRspackNodeEnv(),
248
- optimization: {
249
- // Cosmos reads component names at run-time, so it is crucial to not
250
- // minify even when building with production env (ie. when exporting)
251
- // https://github.com/react-cosmos/react-cosmos/issues/701
252
- minimize: false
253
- }
254
- };
255
- }
256
-
257
- // src/server/rspackConfig/getUserRspackConfig.ts
120
+ const postcssLoaderPath = resolveFromSilent(rootDir, "postcss-loader");
121
+ const mdxLoaderPath = resolveFromSilent(rootDir, "@mdx-js/loader");
122
+ const rules = [];
123
+ const plugins = [];
124
+ rules.push({
125
+ test: /\.(j|t)s$/,
126
+ exclude: [/[\\/]node_modules[\\/]/],
127
+ loader: "builtin:swc-loader",
128
+ options: {
129
+ sourceMaps: true,
130
+ jsc: { parser: { syntax: "typescript" } }
131
+ },
132
+ type: "javascript/auto"
133
+ });
134
+ rules.push({
135
+ test: /\.(j|t)sx$/,
136
+ loader: "builtin:swc-loader",
137
+ exclude: [/[\\/]node_modules[\\/]/],
138
+ options: {
139
+ sourceMaps: true,
140
+ jsc: {
141
+ parser: {
142
+ syntax: "typescript",
143
+ tsx: true
144
+ },
145
+ transform: { react: { runtime: "automatic" } }
146
+ }
147
+ },
148
+ type: "javascript/auto"
149
+ });
150
+ rules.push({
151
+ test: /\.css$/,
152
+ use: postcssLoaderPath ? [{ loader: postcssLoaderPath }] : [{ loader: "builtin:lightningcss-loader" }],
153
+ type: "css/auto"
154
+ });
155
+ if (mdxLoaderPath) rules.push({
156
+ test: /\.mdx$/,
157
+ loader: mdxLoaderPath,
158
+ exclude: [/[\\/]node_modules[\\/]/]
159
+ });
160
+ plugins.push(new rspack.HtmlRspackPlugin({
161
+ title: "React Cosmos",
162
+ filename: RENDERER_FILENAME
163
+ }));
164
+ return {
165
+ devtool: "cheap-module-source-map",
166
+ resolve: {
167
+ extensionAlias: { ".js": [
168
+ ".ts",
169
+ ".tsx",
170
+ ".js"
171
+ ] },
172
+ extensions: [
173
+ ".js",
174
+ ".jsx",
175
+ ".ts",
176
+ ".tsx"
177
+ ]
178
+ },
179
+ module: { rules },
180
+ plugins,
181
+ stats: {
182
+ preset: "errors-only",
183
+ builtAt: true
184
+ },
185
+ infrastructureLogging: { level: "warn" },
186
+ experiments: { topLevelAwait: true },
187
+ mode: getRspackNodeEnv(),
188
+ optimization: { minimize: false }
189
+ };
190
+ }
191
+ //#endregion
192
+ //#region src/server/rspackConfig/getUserRspackConfig.ts
258
193
  async function getUserRspackConfig(config) {
259
- const baseRspackConfig = await getBaseRspackConfig(config);
260
- const { overridePath } = createRspackCosmosConfig(config);
261
- if (!overridePath || !moduleExists(overridePath)) {
262
- console.log(
263
- `[Cosmos] Learn how to override rspack config for cosmos: https://github.com/react-cosmos/react-cosmos/tree/main/docs#webpack-config-override`
264
- );
265
- return baseRspackConfig;
266
- }
267
- const relPath = path5.relative(process.cwd(), overridePath);
268
- console.log(`[Cosmos] Overriding rspack config at ${relPath}`);
269
- const module = await importModule(overridePath);
270
- const rspackOverride = module.default;
271
- return rspackOverride(baseRspackConfig, getRspackNodeEnv());
194
+ const baseRspackConfig = await getBaseRspackConfig(config);
195
+ const { overridePath } = createRspackCosmosConfig(config);
196
+ if (!overridePath || !moduleExists(overridePath)) {
197
+ console.log(`[Cosmos] Learn how to override rspack config for cosmos: https://github.com/react-cosmos/react-cosmos/tree/main/docs#webpack-config-override`);
198
+ return baseRspackConfig;
199
+ }
200
+ const relPath = path.relative(process.cwd(), overridePath);
201
+ console.log(`[Cosmos] Overriding rspack config at ${relPath}`);
202
+ const rspackOverride = (await importModule(overridePath)).default;
203
+ return rspackOverride(baseRspackConfig, getRspackNodeEnv());
272
204
  }
273
205
  async function getBaseRspackConfig(confg) {
274
- const { rootDir } = confg;
275
- const { configPath } = createRspackCosmosConfig(confg);
276
- if (!configPath || !moduleExists(configPath)) {
277
- console.log("[Cosmos] Using default rspack config");
278
- return getDefaultRspackConfig(rootDir);
279
- }
280
- const relPath = path5.relative(process.cwd(), configPath);
281
- console.log(`[Cosmos] Using rspack config found at ${relPath}`);
282
- const module = await importModule(configPath);
283
- const rspackConfig = module.default;
284
- const cliArgs = getCliArgs();
285
- return typeof rspackConfig === "function" ? (
286
- // When cliargs.env is falsey, react-cosmos-plugin-webpack passes the result
287
- // of getRspackNodeEnv() which is the string "production" or "development"
288
- // but that doesn't seem to be what webpack does:
289
- //
290
- // https://github.com/webpack/webpack-cli/blob/79a969fb02c870667d8a3b7035405566d2b4d088/packages/webpack-cli/src/webpack-cli.ts#L1903C35-L1903C43
291
- await rspackConfig(cliArgs.env || {}, cliArgs)
292
- ) : rspackConfig;
293
- }
294
-
295
- // src/server/rspackConfig/resolveRspackClientPath.ts
296
- import { createRequire as createRequire3 } from "module";
206
+ const { rootDir } = confg;
207
+ const { configPath } = createRspackCosmosConfig(confg);
208
+ if (!configPath || !moduleExists(configPath)) {
209
+ console.log("[Cosmos] Using default rspack config");
210
+ return getDefaultRspackConfig(rootDir);
211
+ }
212
+ const relPath = path.relative(process.cwd(), configPath);
213
+ console.log(`[Cosmos] Using rspack config found at ${relPath}`);
214
+ const rspackConfig = (await importModule(configPath)).default;
215
+ const cliArgs = getCliArgs();
216
+ return typeof rspackConfig === "function" ? await rspackConfig(cliArgs.env || {}, cliArgs) : rspackConfig;
217
+ }
218
+ //#endregion
219
+ //#region src/server/rspackConfig/resolveRspackClientPath.ts
297
220
  function resolveRspackClientPath(relPath) {
298
- const require2 = createRequire3(import.meta.url);
299
- return require2.resolve(`../client/${relPath}`);
221
+ return createRequire(import.meta.url).resolve(`../client/${relPath}`);
300
222
  }
301
-
302
- // src/server/rspackConfig/resolveRspackLoaderPath.ts
303
- import { createRequire as createRequire4 } from "module";
223
+ //#endregion
224
+ //#region src/server/rspackConfig/resolveRspackLoaderPath.ts
304
225
  function resolveRspackLoaderPath() {
305
- const require2 = createRequire4(import.meta.url);
306
- return require2.resolve("./userImportsLoader.cjs");
226
+ return createRequire(import.meta.url).resolve("./userImportsLoader.cjs");
307
227
  }
308
-
309
- // src/server/rspackConfig/getRspackConfigModule.ts
228
+ //#endregion
229
+ //#region src/server/rspackConfig/getRspackConfigModule.ts
310
230
  function getRspackConfigModule(config, rspackConfig, mode) {
311
- return {
312
- ...rspackConfig.module,
313
- rules: getRules(config, rspackConfig, mode)
314
- };
231
+ return {
232
+ ...rspackConfig.module,
233
+ rules: getRules(config, rspackConfig, mode)
234
+ };
315
235
  }
316
236
  function getRules(config, { module }, mode) {
317
- const existingRules = module && module.rules || [];
318
- return [...existingRules, getUserImportsLoaderRule(config, mode)];
237
+ return [...module && module.rules || [], getUserImportsLoaderRule(config, mode)];
319
238
  }
320
239
  function getUserImportsLoaderRule(config, mode) {
321
- return {
322
- include: resolveRspackClientPath("userImports"),
323
- use: {
324
- loader: resolveRspackLoaderPath(),
325
- options: { config, mode }
326
- }
327
- };
328
- }
329
-
330
- // src/server/rspackConfig/getRspackConfigResolve.ts
331
- import * as path6 from "path";
240
+ return {
241
+ include: resolveRspackClientPath("userImports"),
242
+ use: {
243
+ loader: resolveRspackLoaderPath(),
244
+ options: {
245
+ config,
246
+ mode
247
+ }
248
+ }
249
+ };
250
+ }
251
+ //#endregion
252
+ //#region src/server/rspackConfig/getRspackConfigResolve.ts
332
253
  function getRspackConfigResolve(config, rspackConfig) {
333
- return resolveLocalReactDeps(config, rspackConfig.resolve);
334
- }
335
- function resolveLocalReactDeps(config, resolve6 = {}) {
336
- const { rootDir } = config;
337
- let alias = resolve6.alias || {};
338
- let reactAlias = hasAlias(alias, "react");
339
- let reactDomAlias = hasAlias(alias, "react-dom");
340
- if (reactAlias && reactDomAlias) {
341
- console.log("[Cosmos] React and React DOM aliases found in rspack config");
342
- return resolve6;
343
- }
344
- if (reactAlias) {
345
- console.log("[Cosmos] React alias found in rspack config");
346
- } else {
347
- const reactPath = resolveFromSilent(rootDir, "react");
348
- if (!reactPath)
349
- throw new Error(`[Cosmos] Local dependency not found: react`);
350
- alias = addAlias(alias, "react", path6.dirname(reactPath));
351
- }
352
- if (reactDomAlias) {
353
- console.log("[Cosmos] React DOM alias found in rspack config");
354
- } else {
355
- const reactDomPath = resolveFromSilent(rootDir, "react-dom");
356
- if (!reactDomPath)
357
- throw new Error(`[Cosmos] Local dependency not found: react-dom`);
358
- alias = addAlias(alias, "react-dom", path6.dirname(reactDomPath));
359
- }
360
- return { ...resolve6, alias };
254
+ return resolveLocalReactDeps(config, rspackConfig.resolve);
255
+ }
256
+ function resolveLocalReactDeps(config, resolve = {}) {
257
+ const { rootDir } = config;
258
+ let alias = resolve.alias || {};
259
+ let reactAlias = hasAlias(alias, "react");
260
+ let reactDomAlias = hasAlias(alias, "react-dom");
261
+ if (reactAlias && reactDomAlias) {
262
+ console.log("[Cosmos] React and React DOM aliases found in rspack config");
263
+ return resolve;
264
+ }
265
+ if (reactAlias) console.log("[Cosmos] React alias found in rspack config");
266
+ else {
267
+ const reactPath = resolveFromSilent(rootDir, "react");
268
+ if (!reactPath) throw new Error(`[Cosmos] Local dependency not found: react`);
269
+ alias = addAlias(alias, "react", path.dirname(reactPath));
270
+ }
271
+ if (reactDomAlias) console.log("[Cosmos] React DOM alias found in rspack config");
272
+ else {
273
+ const reactDomPath = resolveFromSilent(rootDir, "react-dom");
274
+ if (!reactDomPath) throw new Error(`[Cosmos] Local dependency not found: react-dom`);
275
+ alias = addAlias(alias, "react-dom", path.dirname(reactDomPath));
276
+ }
277
+ return {
278
+ ...resolve,
279
+ alias
280
+ };
361
281
  }
362
282
  function hasAlias(alias, name) {
363
- if (!alias) return false;
364
- const exactName = `${name}$`;
365
- const keys = Object.keys(alias);
366
- return keys.includes(name) || keys.includes(exactName);
283
+ if (!alias) return false;
284
+ const exactName = `${name}$`;
285
+ const keys = Object.keys(alias);
286
+ return keys.includes(name) || keys.includes(exactName);
367
287
  }
368
288
  function addAlias(alias, name, value) {
369
- return { ...alias, [name]: value };
370
- }
371
-
372
- // src/server/rspackConfig/htmlPlugin.ts
373
- import rspack2 from "@rspack/core";
374
-
375
- // src/server/utils/omit.ts
289
+ return {
290
+ ...alias,
291
+ [name]: value
292
+ };
293
+ }
294
+ //#endregion
295
+ //#region src/server/utils/omit.ts
296
+ /**
297
+ * A helper to strip certain fields from an object.
298
+ */
376
299
  function omit(o, fields) {
377
- const result = { ...o };
378
- for (const field of fields) {
379
- delete result[field];
380
- }
381
- return result;
382
- }
383
-
384
- // src/server/rspackConfig/plugins.ts
300
+ const result = { ...o };
301
+ for (const field of fields) delete result[field];
302
+ return result;
303
+ }
304
+ //#endregion
305
+ //#region src/server/rspackConfig/plugins.ts
385
306
  function getGlobalsPlugin({ publicUrl }, userRspack, devServerOn) {
386
- const cleanPublicUrl = removeTrailingSlash(publicUrl);
387
- return new userRspack.DefinePlugin({
388
- // "if (__DEV__)" blocks get stripped when compiling a static export build
389
- __DEV__: JSON.stringify(devServerOn),
390
- "process.env.NODE_ENV": JSON.stringify(getRspackNodeEnv()),
391
- "process.env.PUBLIC_URL": JSON.stringify(cleanPublicUrl)
392
- });
307
+ const cleanPublicUrl = removeTrailingSlash(publicUrl);
308
+ return new userRspack.DefinePlugin({
309
+ __DEV__: JSON.stringify(devServerOn),
310
+ "process.env.NODE_ENV": JSON.stringify(getRspackNodeEnv()),
311
+ "process.env.PUBLIC_URL": JSON.stringify(cleanPublicUrl)
312
+ });
393
313
  }
394
314
  function hasPlugin(plugins, pluginName) {
395
- return plugins && plugins.filter((p) => isInstanceOfRspackPlugin(p, pluginName)).length > 0;
315
+ return plugins && plugins.filter((p) => isInstanceOfRspackPlugin(p, pluginName)).length > 0;
396
316
  }
397
317
  function isInstanceOfRspackPlugin(plugin, constructorName) {
398
- return plugin.constructor && plugin.constructor.name === constructorName;
318
+ return plugin.constructor && plugin.constructor.name === constructorName;
399
319
  }
400
320
  function ignoreEmptyRspackPlugins(plugins = []) {
401
- return plugins.filter(Boolean);
321
+ return plugins.filter(Boolean);
402
322
  }
403
323
  function removeTrailingSlash(url) {
404
- return url.replace(/\/$/, "");
324
+ return url.replace(/\/$/, "");
405
325
  }
406
-
407
- // src/server/rspackConfig/htmlPlugin.ts
326
+ //#endregion
327
+ //#region src/server/rspackConfig/htmlPlugin.ts
408
328
  function ensureHtmlPlugin(plugins) {
409
- if (hasPlugin(plugins, "HtmlWebpackPlugin")) {
410
- return plugins.map(
411
- (plugin) => isHtmlWebpackPlugin(plugin) ? changeHtmlPluginFilename(plugin) : plugin
412
- );
413
- }
414
- const htmlRspackPlugin = plugins.find(isHtmlRspackPlugin);
415
- if (htmlRspackPlugin) {
416
- const options = htmlRspackPlugin._args[0];
417
- const safeOptions = omit(options, ["chunks"]);
418
- return [
419
- ...plugins.filter((plugin) => plugin !== htmlRspackPlugin),
420
- new rspack2.HtmlRspackPlugin({
421
- ...safeOptions,
422
- filename: RENDERER_FILENAME
423
- })
424
- ];
425
- }
426
- return [
427
- ...plugins,
428
- new rspack2.HtmlRspackPlugin({
429
- title: "React Cosmos",
430
- filename: RENDERER_FILENAME
431
- })
432
- ];
329
+ if (hasPlugin(plugins, "HtmlWebpackPlugin")) return plugins.map((plugin) => isHtmlWebpackPlugin(plugin) ? changeHtmlPluginFilename(plugin) : plugin);
330
+ const htmlRspackPlugin = plugins.find(isHtmlRspackPlugin);
331
+ if (htmlRspackPlugin) {
332
+ const options = htmlRspackPlugin._args[0];
333
+ const safeOptions = omit(options, ["chunks"]);
334
+ return [...plugins.filter((plugin) => plugin !== htmlRspackPlugin), new rspack.HtmlRspackPlugin({
335
+ ...safeOptions,
336
+ filename: RENDERER_FILENAME
337
+ })];
338
+ }
339
+ return [...plugins, new rspack.HtmlRspackPlugin({
340
+ title: "React Cosmos",
341
+ filename: RENDERER_FILENAME
342
+ })];
433
343
  }
434
344
  function isHtmlWebpackPlugin(plugin) {
435
- return isInstanceOfRspackPlugin(plugin, "HtmlWebpackPlugin");
345
+ return isInstanceOfRspackPlugin(plugin, "HtmlWebpackPlugin");
436
346
  }
437
347
  function isHtmlRspackPlugin(plugin) {
438
- return isInstanceOfRspackPlugin(plugin, "HtmlRspackPlugin");
348
+ return isInstanceOfRspackPlugin(plugin, "HtmlRspackPlugin");
439
349
  }
440
350
  function changeHtmlPluginFilename(htmlPlugin) {
441
- if (!isIndexHtmlWebpackPlugin(htmlPlugin)) {
442
- return htmlPlugin;
443
- }
444
- const options = htmlPlugin.userOptions || htmlPlugin.options;
445
- const safeOptions = omit(options, ["chunks"]);
446
- return new htmlPlugin.constructor({
447
- ...safeOptions,
448
- filename: RENDERER_FILENAME
449
- });
351
+ if (!isIndexHtmlWebpackPlugin(htmlPlugin)) return htmlPlugin;
352
+ const safeOptions = omit(htmlPlugin.userOptions || htmlPlugin.options, ["chunks"]);
353
+ return new htmlPlugin.constructor({
354
+ ...safeOptions,
355
+ filename: RENDERER_FILENAME
356
+ });
450
357
  }
451
358
  function isIndexHtmlWebpackPlugin(htmlPlugin) {
452
- const { filename } = htmlPlugin.userOptions || htmlPlugin.options;
453
- return filename === "index.html" || typeof filename !== "string" || filename.endsWith("/index.html");
359
+ const { filename } = htmlPlugin.userOptions || htmlPlugin.options;
360
+ return filename === "index.html" || typeof filename !== "string" || filename.endsWith("/index.html");
454
361
  }
455
-
456
- // src/server/rspackConfig/rspackConfigTopLevelAwait.ts
362
+ //#endregion
363
+ //#region src/server/rspackConfig/rspackConfigTopLevelAwait.ts
457
364
  function ensureRspackConfigTopLevelAwait(baseWebpackConfig) {
458
- const experiments = baseWebpackConfig.experiments || {};
459
- if (!experiments.topLevelAwait) {
460
- experiments.topLevelAwait = true;
461
- }
462
- return experiments;
463
- }
464
-
465
- // src/server/rspackConfig/getDevRspackConfig.ts
466
- async function getDevRspackConfig(config, userRspack) {
467
- const baseRspackConfig = await getUserRspackConfig(config);
468
- const rspackConfig = {
469
- ...baseRspackConfig,
470
- entry: getEntry(config),
471
- output: getOutput(config),
472
- module: getRspackConfigModule(config, baseRspackConfig, "dev"),
473
- resolve: getRspackConfigResolve(config, baseRspackConfig),
474
- plugins: getPlugins(config, baseRspackConfig, userRspack),
475
- experiments: getExperiments(baseRspackConfig)
476
- };
477
- if (rspackConfig.optimization?.splitChunks) {
478
- const { name } = rspackConfig.optimization.splitChunks;
479
- if (name === false) delete rspackConfig.optimization.splitChunks.name;
480
- }
481
- return rspackConfig;
482
- }
483
- function getEntry(config) {
484
- const { hotReload, reloadOnFail } = createRspackCosmosConfig(config);
485
- const devtoolsHook = resolveRspackClientPath("reactDevtoolsHook");
486
- const clientIndex = resolveRspackClientPath("index");
487
- return hotReload ? [devtoolsHook, getHotMiddlewareEntry(reloadOnFail), clientIndex] : [devtoolsHook, clientIndex];
488
- }
489
- function getOutput({ publicUrl }) {
490
- const filename = "[name].js";
491
- return {
492
- filename,
493
- publicPath: publicUrl,
494
- // Enable click-to-open source in react-error-overlay
495
- devtoolModuleFilenameTemplate: (info) => path7.resolve(info.absoluteResourcePath).replace(/\\/g, "/")
496
- };
365
+ const experiments = baseWebpackConfig.experiments || {};
366
+ if (!experiments.topLevelAwait) experiments.topLevelAwait = true;
367
+ return experiments;
497
368
  }
498
- function getPlugins(config, baseRspackConfig, userRspack) {
499
- const existingPlugins = ignoreEmptyRspackPlugins(baseRspackConfig.plugins);
500
- const globalsPlugin = getGlobalsPlugin(config, userRspack, true);
501
- const noEmitErrorsPlugin = new userRspack.NoEmitOnErrorsPlugin();
502
- let plugins = [...existingPlugins, globalsPlugin, noEmitErrorsPlugin];
503
- const { hotReload } = createRspackCosmosConfig(config);
504
- if (hotReload && !hasPlugin(plugins, "HotModuleReplacementPlugin")) {
505
- const hmrPlugin = new userRspack.HotModuleReplacementPlugin();
506
- plugins = [...plugins, hmrPlugin];
507
- }
508
- return ensureHtmlPlugin(plugins);
369
+ //#endregion
370
+ //#region src/server/rspackConfig/getDevRspackConfig.ts
371
+ async function getDevRspackConfig(config, userRspack) {
372
+ const baseRspackConfig = await getUserRspackConfig(config);
373
+ const rspackConfig = {
374
+ ...baseRspackConfig,
375
+ entry: getEntry$1(config),
376
+ output: getOutput$1(config),
377
+ module: getRspackConfigModule(config, baseRspackConfig, "dev"),
378
+ resolve: getRspackConfigResolve(config, baseRspackConfig),
379
+ plugins: getPlugins$1(config, baseRspackConfig, userRspack),
380
+ experiments: getExperiments$1(baseRspackConfig)
381
+ };
382
+ if (rspackConfig.optimization?.splitChunks) {
383
+ const { name } = rspackConfig.optimization.splitChunks;
384
+ if (name === false) delete rspackConfig.optimization.splitChunks.name;
385
+ }
386
+ return rspackConfig;
387
+ }
388
+ function getEntry$1(config) {
389
+ const { hotReload, reloadOnFail } = createRspackCosmosConfig(config);
390
+ const devtoolsHook = resolveRspackClientPath("reactDevtoolsHook");
391
+ const clientIndex = resolveRspackClientPath("index");
392
+ return hotReload ? [
393
+ devtoolsHook,
394
+ getHotMiddlewareEntry(reloadOnFail),
395
+ clientIndex
396
+ ] : [devtoolsHook, clientIndex];
397
+ }
398
+ function getOutput$1({ publicUrl }) {
399
+ return {
400
+ filename: "[name].js",
401
+ publicPath: publicUrl,
402
+ devtoolModuleFilenameTemplate: (info) => path.resolve(info.absoluteResourcePath).replace(/\\/g, "/")
403
+ };
404
+ }
405
+ function getPlugins$1(config, baseRspackConfig, userRspack) {
406
+ const existingPlugins = ignoreEmptyRspackPlugins(baseRspackConfig.plugins);
407
+ const globalsPlugin = getGlobalsPlugin(config, userRspack, true);
408
+ const noEmitErrorsPlugin = new userRspack.NoEmitOnErrorsPlugin();
409
+ let plugins = [
410
+ ...existingPlugins,
411
+ globalsPlugin,
412
+ noEmitErrorsPlugin
413
+ ];
414
+ const { hotReload } = createRspackCosmosConfig(config);
415
+ if (hotReload && !hasPlugin(plugins, "HotModuleReplacementPlugin")) {
416
+ const hmrPlugin = new userRspack.HotModuleReplacementPlugin();
417
+ plugins = [...plugins, hmrPlugin];
418
+ }
419
+ return ensureHtmlPlugin(plugins);
509
420
  }
510
421
  function getHotMiddlewareEntry(reloadOnFail) {
511
- const clientPath = resolve("webpack-hot-middleware/client");
512
- return `${clientPath}?reload=${reloadOnFail}&overlay=false`;
513
- }
514
- function getExperiments(baseWebpackConfig) {
515
- return ensureRspackConfigTopLevelAwait(baseWebpackConfig);
516
- }
517
-
518
- // src/server/rspackDevServerPlugin.ts
519
- async function rspackDevServerPlugin({
520
- config,
521
- platform,
522
- app,
523
- sendMessage
524
- }) {
525
- if (platform !== "web") {
526
- return;
527
- }
528
- const userRspack = getRspack(config.rootDir);
529
- if (!userRspack) {
530
- return;
531
- }
532
- const rspackConfig = await getDevRspackConfig(
533
- config,
534
- userRspack
535
- );
536
- if (config.staticPath === null) {
537
- const rspackDerivedStaticPath = getRspackStaticPath(rspackConfig);
538
- if (rspackDerivedStaticPath !== null) {
539
- serveStaticDir(
540
- app,
541
- path8.resolve(config.rootDir, rspackDerivedStaticPath),
542
- config.publicUrl
543
- );
544
- }
545
- }
546
- function sendBuildMessage(msg) {
547
- sendMessage(msg);
548
- }
549
- const rspackCompiler = userRspack(rspackConfig);
550
- rspackCompiler.hooks.invalid.tap("Cosmos", (filePath) => {
551
- if (typeof filePath === "string") {
552
- const relFilePath = path8.relative(process.cwd(), filePath);
553
- console.log("[Cosmos] rspack build invalidated by", relFilePath);
554
- } else {
555
- console.log("[Cosmos] rspack build invalidated by unknown file");
556
- }
557
- sendBuildMessage({ type: "buildStart" });
558
- });
559
- rspackCompiler.hooks.failed.tap("Cosmos", () => {
560
- sendBuildMessage({ type: "buildError" });
561
- });
562
- const onCompilationDone = new Promise((resolve6) => {
563
- rspackCompiler.hooks.done.tap("Cosmos", (stats) => {
564
- resolve6();
565
- if (stats.hasErrors()) {
566
- sendBuildMessage({ type: "buildError" });
567
- } else {
568
- sendBuildMessage({ type: "buildDone" });
569
- }
570
- });
571
- });
572
- console.log("[Cosmos] Building rspack...");
573
- const wdmModule = await import("webpack-dev-middleware");
574
- const wdmInst = wdmModule.default(
575
- // Rspack's Compiler type is pretty close to webpack's Compiler type, but
576
- // is missing a few members. Hopefully WDM doesn't need them, however.
577
- // @rspack/dev-server itself uses webpack-dev-middleware so it should be
578
- // fine.
579
- rspackCompiler,
580
- {
581
- // publicPath is the base path for the rspack assets and has to match
582
- // rspack.output.publicPath
583
- publicPath: config.publicUrl
584
- }
585
- );
586
- app.use(wdmInst);
587
- const { hotReload } = createRspackCosmosConfig(config);
588
- if (hotReload) {
589
- app.use(
590
- webpackHotMiddleware(
591
- // As above, rspack's Compiler type is pretty close to webpack's
592
- // Compiler type so this should be fine.
593
- rspackCompiler
594
- )
595
- );
596
- }
597
- await onCompilationDone;
598
- return async () => {
599
- await new Promise((res) => wdmInst.close(res));
600
- };
422
+ return `${resolve("webpack-hot-middleware/client")}?reload=${reloadOnFail}&overlay=false`;
423
+ }
424
+ function getExperiments$1(baseWebpackConfig) {
425
+ return ensureRspackConfigTopLevelAwait(baseWebpackConfig);
426
+ }
427
+ //#endregion
428
+ //#region src/server/rspackDevServerPlugin.ts
429
+ async function rspackDevServerPlugin({ config, platform, app, sendMessage }) {
430
+ if (platform !== "web") return;
431
+ const userRspack = getRspack(config.rootDir);
432
+ if (!userRspack) return;
433
+ const rspackConfig = await getDevRspackConfig(config, userRspack);
434
+ if (config.staticPath === null) {
435
+ const rspackDerivedStaticPath = getRspackStaticPath(rspackConfig);
436
+ if (rspackDerivedStaticPath !== null) serveStaticDir(app, path.resolve(config.rootDir, rspackDerivedStaticPath), config.publicUrl);
437
+ }
438
+ function sendBuildMessage(msg) {
439
+ sendMessage(msg);
440
+ }
441
+ const rspackCompiler = userRspack(rspackConfig);
442
+ rspackCompiler.hooks.invalid.tap("Cosmos", (filePath) => {
443
+ if (typeof filePath === "string") {
444
+ const relFilePath = path.relative(process.cwd(), filePath);
445
+ console.log("[Cosmos] rspack build invalidated by", relFilePath);
446
+ } else console.log("[Cosmos] rspack build invalidated by unknown file");
447
+ sendBuildMessage({ type: "buildStart" });
448
+ });
449
+ rspackCompiler.hooks.failed.tap("Cosmos", () => {
450
+ sendBuildMessage({ type: "buildError" });
451
+ });
452
+ const onCompilationDone = new Promise((resolve) => {
453
+ rspackCompiler.hooks.done.tap("Cosmos", (stats) => {
454
+ resolve();
455
+ if (stats.hasErrors()) sendBuildMessage({ type: "buildError" });
456
+ else sendBuildMessage({ type: "buildDone" });
457
+ });
458
+ });
459
+ console.log("[Cosmos] Building rspack...");
460
+ const wdmInst = (await import("webpack-dev-middleware")).default(rspackCompiler, { publicPath: config.publicUrl });
461
+ app.use(wdmInst);
462
+ const { hotReload } = createRspackCosmosConfig(config);
463
+ if (hotReload) app.use(webpackHotMiddleware(rspackCompiler));
464
+ await onCompilationDone;
465
+ return async () => {
466
+ await new Promise((res) => wdmInst.close(res));
467
+ };
601
468
  }
602
469
  function getRspackStaticPath({ devServer }) {
603
- return devServer && typeof devServer.contentBase === "string" ? devServer.contentBase : null;
470
+ return devServer && typeof devServer.contentBase === "string" ? devServer.contentBase : null;
604
471
  }
605
-
606
- // src/server/rspackConfig/getExportRspackConfig.ts
607
- import * as path9 from "path";
472
+ //#endregion
473
+ //#region src/server/rspackConfig/getExportRspackConfig.ts
608
474
  async function getExportRspackConfig(config, userRspack) {
609
- const baseRspackConfig = await getUserRspackConfig(config);
610
- return {
611
- ...baseRspackConfig,
612
- entry: getEntry2(),
613
- output: getOutput2(config),
614
- module: getRspackConfigModule(config, baseRspackConfig, "export"),
615
- resolve: getRspackConfigResolve(config, baseRspackConfig),
616
- plugins: getPlugins2(config, baseRspackConfig, userRspack),
617
- experiments: getExperiments2(baseRspackConfig)
618
- };
619
- }
620
- function getEntry2() {
621
- const devtoolsHook = resolveRspackClientPath("reactDevtoolsHook");
622
- const clientIndex = resolveRspackClientPath("index");
623
- return [devtoolsHook, clientIndex];
624
- }
625
- function getOutput2(config) {
626
- const { exportPath, publicUrl } = config;
627
- const { includeHashInOutputFilename } = createRspackCosmosConfig(config);
628
- return {
629
- path: path9.join(exportPath, publicUrl),
630
- filename: includeHashInOutputFilename ? "[name].[contenthash].js" : "[name].js",
631
- publicPath: publicUrl
632
- };
633
- }
634
- function getPlugins2(config, baseRspackConfig, userRspack) {
635
- const existingPlugins = ignoreEmptyRspackPlugins(baseRspackConfig.plugins);
636
- const globalsPlugin = getGlobalsPlugin(config, userRspack, false);
637
- const noEmitErrorsPlugin = new userRspack.NoEmitOnErrorsPlugin();
638
- return ensureHtmlPlugin([
639
- ...existingPlugins,
640
- globalsPlugin,
641
- noEmitErrorsPlugin
642
- ]);
643
- }
644
- function getExperiments2(baseWebpackConfig) {
645
- return ensureRspackConfigTopLevelAwait(baseWebpackConfig);
646
- }
647
-
648
- // src/server/rspackExportPlugin.ts
475
+ const baseRspackConfig = await getUserRspackConfig(config);
476
+ return {
477
+ ...baseRspackConfig,
478
+ entry: getEntry(),
479
+ output: getOutput(config),
480
+ module: getRspackConfigModule(config, baseRspackConfig, "export"),
481
+ resolve: getRspackConfigResolve(config, baseRspackConfig),
482
+ plugins: getPlugins(config, baseRspackConfig, userRspack),
483
+ experiments: getExperiments(baseRspackConfig)
484
+ };
485
+ }
486
+ function getEntry() {
487
+ return [resolveRspackClientPath("reactDevtoolsHook"), resolveRspackClientPath("index")];
488
+ }
489
+ function getOutput(config) {
490
+ const { exportPath, publicUrl } = config;
491
+ const { includeHashInOutputFilename } = createRspackCosmosConfig(config);
492
+ return {
493
+ path: path.join(exportPath, publicUrl),
494
+ filename: includeHashInOutputFilename ? "[name].[contenthash].js" : "[name].js",
495
+ publicPath: publicUrl
496
+ };
497
+ }
498
+ function getPlugins(config, baseRspackConfig, userRspack) {
499
+ const existingPlugins = ignoreEmptyRspackPlugins(baseRspackConfig.plugins);
500
+ const globalsPlugin = getGlobalsPlugin(config, userRspack, false);
501
+ const noEmitErrorsPlugin = new userRspack.NoEmitOnErrorsPlugin();
502
+ return ensureHtmlPlugin([
503
+ ...existingPlugins,
504
+ globalsPlugin,
505
+ noEmitErrorsPlugin
506
+ ]);
507
+ }
508
+ function getExperiments(baseWebpackConfig) {
509
+ return ensureRspackConfigTopLevelAwait(baseWebpackConfig);
510
+ }
511
+ //#endregion
512
+ //#region src/server/rspackExportPlugin.ts
649
513
  async function rspackExportPlugin({ config }) {
650
- const userRspack = getRspack(config.rootDir);
651
- if (!userRspack) {
652
- return;
653
- }
654
- const rspackConfig = await getExportRspackConfig(config, userRspack);
655
- try {
656
- await runRspackCompiler(userRspack, rspackConfig);
657
- } catch (err) {
658
- const rspackError = err;
659
- if (rspackError.rspackErrors) {
660
- rspackError.rspackErrors.forEach((error) => {
661
- console.error(`${error}
662
- `);
663
- });
664
- }
665
- throw rspackError;
666
- }
514
+ const userRspack = getRspack(config.rootDir);
515
+ if (!userRspack) return;
516
+ const rspackConfig = await getExportRspackConfig(config, userRspack);
517
+ try {
518
+ await runRspackCompiler(userRspack, rspackConfig);
519
+ } catch (err) {
520
+ const rspackError = err;
521
+ if (rspackError.rspackErrors) rspackError.rspackErrors.forEach((error) => {
522
+ console.error(`${error}\n`);
523
+ });
524
+ throw rspackError;
525
+ }
667
526
  }
668
527
  function runRspackCompiler(userRspack, rspackConfig) {
669
- return new Promise((resolve6, reject) => {
670
- const compiler = userRspack(rspackConfig);
671
- compiler.run((err, stats) => {
672
- if (err) {
673
- reject(err);
674
- } else if (stats?.hasErrors()) {
675
- const error = new RspackCompilationError();
676
- error.rspackErrors = stats.toJson().errors;
677
- reject(error);
678
- } else {
679
- resolve6(stats);
680
- }
681
- });
682
- });
528
+ return new Promise((resolve, reject) => {
529
+ userRspack(rspackConfig).run((err, stats) => {
530
+ if (err) reject(err);
531
+ else if (stats?.hasErrors()) {
532
+ const error = new RspackCompilationError();
533
+ error.rspackErrors = stats.toJson().errors;
534
+ reject(error);
535
+ } else resolve(stats);
536
+ });
537
+ });
683
538
  }
684
539
  var RspackCompilationError = class extends Error {
685
- rspackErrors;
686
- constructor() {
687
- super("Rspack errors occurred");
688
- }
689
- };
690
-
691
- // src/server/rspackServerPlugin.ts
692
- var rspackServerPlugin = {
693
- name: "rspack",
694
- config: rspackConfigPlugin,
695
- devServer: rspackDevServerPlugin,
696
- export: rspackExportPlugin
540
+ rspackErrors;
541
+ constructor() {
542
+ super("Rspack errors occurred");
543
+ }
697
544
  };
698
- var rspackServerPlugin_default = rspackServerPlugin;
699
- export {
700
- rspackServerPlugin_default as default
545
+ //#endregion
546
+ //#region src/server/rspackServerPlugin.ts
547
+ const rspackServerPlugin = {
548
+ name: "rspack",
549
+ config: rspackConfigPlugin,
550
+ devServer: rspackDevServerPlugin,
551
+ export: rspackExportPlugin
701
552
  };
553
+ //#endregion
554
+ export { rspackServerPlugin as default };