storybook-builder-rsbuild 0.0.7 → 0.0.8

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.d.ts CHANGED
@@ -25,6 +25,10 @@ type BuilderOptions = {
25
25
  * Path to rsbuild.config file, relative to CWD.
26
26
  */
27
27
  rsbuildConfigPath?: string;
28
+ /**
29
+ * Enable Rspack's lazy compilation (experimental).
30
+ */
31
+ lazyCompilation?: boolean;
28
32
  };
29
33
  interface BuilderResult extends BuilderResult$1 {
30
34
  stats?: Stats;
@@ -58,7 +62,7 @@ declare const rsbuild: (_: unknown, options: RsbuildBuilderOptions) => Promise<r
58
62
  declare const getConfig: RsbuildBuilder['getConfig'];
59
63
  declare function bail(): Promise<void>;
60
64
  declare const start: RsbuildBuilder['start'];
61
- declare const build: ({ options, }: BuilderStartOptions) => Promise<Stats>;
65
+ declare const build: ({ options }: BuilderStartOptions) => Promise<Stats>;
62
66
  declare const corePresets: string[];
63
67
  declare const previewMainTemplate: () => string;
64
68
 
package/dist/index.js CHANGED
@@ -120,24 +120,32 @@ __export(src_exports, {
120
120
  toImportFnPart: () => toImportFnPart
121
121
  });
122
122
  module.exports = __toCommonJS(src_exports);
123
+ var import_node_net = require("net");
124
+ var import_node_path5 = require("path");
123
125
  var rsbuildReal = __toESM(require("@rsbuild/core"));
124
- var import_path5 = require("path");
126
+ var import_core2 = require("@rsbuild/core");
125
127
  var import_express = __toESM(require("express"));
126
128
  var import_fs_extra = __toESM(require("fs-extra"));
129
+ var import_pretty_hrtime = __toESM(require_pretty_hrtime());
130
+ var import_core_path = require("storybook/core-path");
127
131
  var import_server_errors = require("storybook/internal/server-errors");
128
132
 
129
133
  // src/preview/iframe-rsbuild.config.ts
130
- var import_path3 = require("path");
134
+ var import_node_path3 = require("path");
135
+ var import_core = require("@rsbuild/core");
136
+ var import_plugin_type_check = require("@rsbuild/plugin-type-check");
137
+ var import_preset = require("@storybook/addon-docs/dist/preset");
131
138
  var import_case_sensitive_paths_webpack_plugin = __toESM(require("case-sensitive-paths-webpack-plugin"));
132
- var import_globals = require("storybook/internal/preview/globals");
139
+ var import_rsbuild_plugin_html_minifier_terser = require("rsbuild-plugin-html-minifier-terser");
133
140
  var import_common2 = require("storybook/internal/common");
141
+ var import_globals = require("storybook/internal/preview/globals");
134
142
  var import_ts_dedent2 = require("ts-dedent");
135
143
 
136
144
  // src/preview/virtual-module-mapping.ts
137
- var import_path = __toESM(require("path"));
138
- var import_fs = __toESM(require("fs"));
139
- var import_path2 = require("path");
140
- var import_common = require("storybook/internal/common");
145
+ var import_node_fs = __toESM(require("fs"));
146
+ var import_node_path = __toESM(require("path"));
147
+ var import_node_path2 = require("path");
148
+ var import_core_webpack = require("@storybook/core-webpack");
141
149
 
142
150
  // ../../node_modules/.pnpm/slash@5.1.0/node_modules/slash/index.js
143
151
  function slash(path2) {
@@ -149,7 +157,7 @@ function slash(path2) {
149
157
  }
150
158
 
151
159
  // src/preview/virtual-module-mapping.ts
152
- var import_core_webpack = require("@storybook/core-webpack");
160
+ var import_common = require("storybook/internal/common");
153
161
  var import_ts_dedent = require("ts-dedent");
154
162
  var getVirtualModules = async (options) => {
155
163
  const virtualModules = {};
@@ -162,7 +170,7 @@ var getVirtualModules = async (options) => {
162
170
  configDir: options.configDir,
163
171
  workingDir
164
172
  });
165
- const realPathRelativeToCwd = import_path.default.relative(workingDir, cwd).split(import_path.default.sep).join(import_path.default.posix.sep);
173
+ const realPathRelativeToCwd = import_node_path.default.relative(workingDir, cwd).split(import_node_path.default.sep).join(import_node_path.default.posix.sep);
166
174
  const previewAnnotations = [
167
175
  ...(await options.presets.apply(
168
176
  "previewAnnotations",
@@ -177,12 +185,13 @@ var getVirtualModules = async (options) => {
177
185
  (0, import_common.loadPreviewOrConfigFile)(options)
178
186
  ].filter(Boolean);
179
187
  const storiesFilename = "storybook-stories.js";
180
- const storiesPath = (0, import_path2.resolve)((0, import_path2.join)(workingDir, storiesFilename));
181
- const needPipelinedImport = !isProd;
188
+ const storiesPath = (0, import_node_path2.resolve)((0, import_node_path2.join)(workingDir, storiesFilename));
189
+ const builderOptions = await (0, import_common.getBuilderOptions)(options);
190
+ const needPipelinedImport = !!builderOptions.lazyCompilation && !isProd;
182
191
  virtualModules[storiesPath] = toImportFn(stories, realPathRelativeToCwd, {
183
192
  needPipelinedImport
184
193
  });
185
- const configEntryPath = (0, import_path2.resolve)((0, import_path2.join)(workingDir, "storybook-config-entry.js"));
194
+ const configEntryPath = (0, import_node_path2.resolve)((0, import_node_path2.join)(workingDir, "storybook-config-entry.js"));
186
195
  virtualModules[configEntryPath] = (0, import_common.handlebars)(
187
196
  await (0, import_common.readTemplate)(
188
197
  require.resolve("storybook-builder-rsbuild/templates/virtualModuleModernEntry.js.handlebars")
@@ -194,9 +203,9 @@ var getVirtualModules = async (options) => {
194
203
  // We need to double escape `\` for webpack. We may have some in windows paths
195
204
  ).replace(/\\/g, "\\\\");
196
205
  entries.push(configEntryPath);
197
- Object.entries(virtualModules).forEach(([key, value]) => {
198
- import_fs.default.writeFileSync(key, value);
199
- });
206
+ for (const [key, value] of Object.entries(virtualModules)) {
207
+ import_node_fs.default.writeFileSync(key, value);
208
+ }
200
209
  return {
201
210
  virtualModules,
202
211
  entries
@@ -221,7 +230,7 @@ function toImportFnPart(specifier) {
221
230
  `;
222
231
  }
223
232
  function toImportFn(stories, relativeOffset, { needPipelinedImport } = {}) {
224
- let pipelinedImport = `const pipeline = (x) => x();`;
233
+ let pipelinedImport = "const pipeline = (x) => x();";
225
234
  if (needPipelinedImport) {
226
235
  pipelinedImport = `
227
236
  const importPipeline = ${importPipeline};
@@ -270,11 +279,7 @@ function importPipeline() {
270
279
  }
271
280
 
272
281
  // src/preview/iframe-rsbuild.config.ts
273
- var import_core = require("@rsbuild/core");
274
- var import_preset = require("@storybook/addon-docs/dist/preset");
275
- var import_plugin_type_check = require("@rsbuild/plugin-type-check");
276
- var import_rsbuild_plugin_html_minifier_terser = require("rsbuild-plugin-html-minifier-terser");
277
- var getAbsolutePath = (input) => (0, import_path3.dirname)(require.resolve((0, import_path3.join)(input, "package.json")));
282
+ var getAbsolutePath = (input) => (0, import_node_path3.dirname)(require.resolve((0, import_node_path3.join)(input, "package.json")));
278
283
  var maybeGetAbsolutePath = (input) => {
279
284
  try {
280
285
  return getAbsolutePath(input);
@@ -282,24 +287,24 @@ var maybeGetAbsolutePath = (input) => {
282
287
  return false;
283
288
  }
284
289
  };
285
- var managerAPIPath = maybeGetAbsolutePath(`@storybook/manager-api`);
286
- var componentsPath = maybeGetAbsolutePath(`@storybook/components`);
287
- var globalPath = maybeGetAbsolutePath(`@storybook/global`);
288
- var routerPath = maybeGetAbsolutePath(`@storybook/router`);
289
- var themingPath = maybeGetAbsolutePath(`@storybook/theming`);
290
+ var managerAPIPath = maybeGetAbsolutePath("@storybook/manager-api");
291
+ var componentsPath = maybeGetAbsolutePath("@storybook/components");
292
+ var globalPath = maybeGetAbsolutePath("@storybook/global");
293
+ var routerPath = maybeGetAbsolutePath("@storybook/router");
294
+ var themingPath = maybeGetAbsolutePath("@storybook/theming");
290
295
  var storybookPaths = {
291
296
  ...managerAPIPath ? {
292
- [`@storybook/manager-api`]: managerAPIPath
297
+ "@storybook/manager-api": managerAPIPath
293
298
  } : {},
294
- ...componentsPath ? { [`@storybook/components`]: componentsPath } : {},
295
- ...globalPath ? { [`@storybook/global`]: globalPath } : {},
296
- ...routerPath ? { [`@storybook/router`]: routerPath } : {},
297
- ...themingPath ? { [`@storybook/theming`]: themingPath } : {}
299
+ ...componentsPath ? { "@storybook/components": componentsPath } : {},
300
+ ...globalPath ? { "@storybook/global": globalPath } : {},
301
+ ...routerPath ? { "@storybook/router": routerPath } : {},
302
+ ...themingPath ? { "@storybook/theming": themingPath } : {}
298
303
  };
299
304
  var iframe_rsbuild_config_default = async (options) => {
300
305
  const appliedDocsWebpack = await (0, import_preset.webpack)({}, options);
301
306
  const {
302
- outputDir = (0, import_path3.join)(".", "public"),
307
+ outputDir = (0, import_node_path3.join)(".", "public"),
303
308
  quiet,
304
309
  packageJson,
305
310
  configType,
@@ -347,6 +352,10 @@ var iframe_rsbuild_config_default = async (options) => {
347
352
  });
348
353
  const shouldCheckTs = typescriptOptions.check && !typescriptOptions.skipCompiler;
349
354
  const tsCheckOptions = typescriptOptions.checkOptions || {};
355
+ const builderOptions = await (0, import_common2.getBuilderOptions)(options);
356
+ const lazyCompilationConfig = builderOptions.lazyCompilation && !isProd ? {
357
+ lazyCompilation: { entries: false }
358
+ } : {};
350
359
  if (!template) {
351
360
  throw new Error(import_ts_dedent2.dedent`
352
361
  Storybook's Webpack5 builder requires a template to be specified.
@@ -376,10 +385,10 @@ var iframe_rsbuild_config_default = async (options) => {
376
385
  },
377
386
  sourceMap: {
378
387
  js: options.build?.test?.disableSourcemaps ? false : "cheap-module-source-map",
379
- css: options.build?.test?.disableSourcemaps ? false : true
388
+ css: !options.build?.test?.disableSourcemaps
380
389
  },
381
390
  distPath: {
382
- root: (0, import_path3.resolve)(process.cwd(), outputDir)
391
+ root: (0, import_node_path3.resolve)(process.cwd(), outputDir)
383
392
  },
384
393
  filename: {
385
394
  js: isProd ? "[name].[contenthash:8].iframe.bundle.js" : "[name].iframe.bundle.js",
@@ -479,10 +488,15 @@ var iframe_rsbuild_config_default = async (options) => {
479
488
  new import_case_sensitive_paths_webpack_plugin.default()
480
489
  ].filter(Boolean)
481
490
  );
491
+ config.experiments ??= {};
492
+ config.experiments = {
493
+ ...config.experiments,
494
+ ...lazyCompilationConfig
495
+ };
482
496
  return mergeConfig(config, appliedDocsWebpack);
483
497
  },
484
498
  htmlPlugin: {
485
- filename: `iframe.html`,
499
+ filename: "iframe.html",
486
500
  // FIXME: `none` isn't a known option
487
501
  chunksSortMode: "none",
488
502
  alwaysWriteToDisk: true,
@@ -514,12 +528,9 @@ var iframe_rsbuild_config_default = async (options) => {
514
528
  return merged;
515
529
  };
516
530
 
517
- // src/index.ts
518
- var import_core_path = require("storybook/core-path");
519
-
520
531
  // src/react-shims.ts
521
- var import_path4 = require("path");
522
532
  var import_promises = require("fs/promises");
533
+ var import_node_path4 = require("path");
523
534
  var getIsReactVersion18or19 = async (options) => {
524
535
  const { legacyRootApi } = await options.presets.apply(
525
536
  "frameworkOptions"
@@ -531,12 +542,12 @@ var getIsReactVersion18or19 = async (options) => {
531
542
  "resolvedReact",
532
543
  {}
533
544
  );
534
- const reactDom = resolvedReact.reactDom || (0, import_path4.dirname)(require.resolve("react-dom/package.json"));
535
- if (!(0, import_path4.isAbsolute)(reactDom)) {
545
+ const reactDom = resolvedReact.reactDom || (0, import_node_path4.dirname)(require.resolve("react-dom/package.json"));
546
+ if (!(0, import_node_path4.isAbsolute)(reactDom)) {
536
547
  return false;
537
548
  }
538
549
  const { version } = JSON.parse(
539
- await (0, import_promises.readFile)((0, import_path4.join)(reactDom, "package.json"), "utf-8")
550
+ await (0, import_promises.readFile)((0, import_node_path4.join)(reactDom, "package.json"), "utf-8")
540
551
  );
541
552
  return version.startsWith("18") || version.startsWith("19") || version.startsWith("0.0.0");
542
553
  };
@@ -555,8 +566,6 @@ var applyReactShims = async (config, options) => {
555
566
  };
556
567
 
557
568
  // src/index.ts
558
- var import_pretty_hrtime = __toESM(require_pretty_hrtime());
559
- var import_core2 = require("@rsbuild/core");
560
569
  var printDuration = (startTime) => (0, import_pretty_hrtime.default)(process.hrtime(startTime)).replace(" ms", " milliseconds").replace(" s", " seconds").replace(" m", " minutes");
561
570
  var executor = {
562
571
  get: async (options) => {
@@ -608,10 +617,9 @@ var start = async ({
608
617
  ...config,
609
618
  server: {
610
619
  ...config.server,
611
- port: options.port,
612
- host: "localhost",
620
+ port: await getRandomPort(options.host),
621
+ host: options.host,
613
622
  htmlFallback: false,
614
- strictPort: true,
615
623
  printUrls: false
616
624
  },
617
625
  dev: {
@@ -632,13 +640,13 @@ var start = async ({
632
640
  if (!rsbuildBuild) {
633
641
  throw new import_server_errors.WebpackInvocationError({
634
642
  // eslint-disable-next-line local-rules/no-uncategorized-errors
635
- error: new Error(`Missing Rsbuild build instance at runtime!`)
643
+ error: new Error("Missing Rsbuild build instance at runtime!")
636
644
  });
637
645
  }
638
- const previewResolvedDir = (0, import_path5.join)(import_core_path.corePath, "dist/preview");
646
+ const previewResolvedDir = (0, import_node_path5.join)(import_core_path.corePath, "dist/preview");
639
647
  const previewDirOrigin = previewResolvedDir;
640
648
  router.use(
641
- `/sb-preview`,
649
+ "/sb-preview",
642
650
  import_express.default.static(previewDirOrigin, { immutable: true, maxAge: "5m" })
643
651
  );
644
652
  router.use(rsbuildServer.middlewares);
@@ -657,16 +665,16 @@ var build = async ({ options }) => {
657
665
  cwd: process.cwd(),
658
666
  rsbuildConfig: config
659
667
  });
660
- const previewResolvedDir = (0, import_path5.join)(import_core_path.corePath, "dist/preview");
668
+ const previewResolvedDir = (0, import_node_path5.join)(import_core_path.corePath, "dist/preview");
661
669
  const previewDirOrigin = previewResolvedDir;
662
- const previewDirTarget = (0, import_path5.join)(options.outputDir || "", `sb-preview`);
670
+ const previewDirTarget = (0, import_node_path5.join)(options.outputDir || "", "sb-preview");
663
671
  let stats;
664
672
  rsbuildBuild.onAfterBuild((params) => {
665
673
  stats = params.stats;
666
674
  });
667
675
  const previewFiles = import_fs_extra.default.copy(previewDirOrigin, previewDirTarget, {
668
676
  filter: (src) => {
669
- const { ext } = (0, import_path5.parse)(src);
677
+ const { ext } = (0, import_node_path5.parse)(src);
670
678
  if (ext) {
671
679
  return ext === ".js";
672
680
  }
@@ -679,8 +687,21 @@ var build = async ({ options }) => {
679
687
  await Promise.all([rsbuildBuild.build(), previewFiles]);
680
688
  return stats;
681
689
  };
682
- var corePresets = [(0, import_path5.join)(__dirname, "./preview-preset.js")];
690
+ var corePresets = [(0, import_node_path5.join)(__dirname, "./preview-preset.js")];
683
691
  var previewMainTemplate = () => require.resolve("storybook-builder-rsbuild/templates/preview.ejs");
692
+ function getRandomPort(host) {
693
+ return new Promise((resolve3, reject) => {
694
+ const server2 = (0, import_node_net.createServer)();
695
+ server2.unref();
696
+ server2.on("error", reject);
697
+ server2.listen({ port: 0, host }, () => {
698
+ const { port } = server2.address();
699
+ server2.close(() => {
700
+ resolve3(port);
701
+ });
702
+ });
703
+ });
704
+ }
684
705
  // Annotate the CommonJS export names for ESM import in node:
685
706
  0 && (module.exports = {
686
707
  bail,
package/dist/index.mjs CHANGED
@@ -1,20 +1,21 @@
1
1
  import { __commonJS, __toESM, __require } from './chunk-TTFRSOOU.mjs';
2
+ import { createServer } from 'net';
3
+ import path, { join, resolve, parse, dirname, isAbsolute } from 'path';
2
4
  import * as rsbuildReal from '@rsbuild/core';
3
5
  import { mergeRsbuildConfig, loadConfig } from '@rsbuild/core';
4
- import path, { join, resolve, parse, dirname, isAbsolute } from 'path';
5
6
  import express from 'express';
6
7
  import fs2 from 'fs-extra';
8
+ import { corePath } from 'storybook/core-path';
7
9
  import { WebpackInvocationError } from 'storybook/internal/server-errors';
10
+ import { pluginTypeCheck } from '@rsbuild/plugin-type-check';
11
+ import { webpack } from '@storybook/addon-docs/dist/preset';
8
12
  import CaseSensitivePathsPlugin from 'case-sensitive-paths-webpack-plugin';
13
+ import { pluginHtmlMinifierTerser } from 'rsbuild-plugin-html-minifier-terser';
14
+ import { normalizeStories, loadPreviewOrConfigFile, getBuilderOptions, handlebars, readTemplate, stringifyProcessEnvs, isPreservingSymlinks } from 'storybook/internal/common';
9
15
  import { globalsNameReferenceMap } from 'storybook/internal/preview/globals';
10
- import { normalizeStories, loadPreviewOrConfigFile, handlebars, readTemplate, getBuilderOptions, stringifyProcessEnvs, isPreservingSymlinks } from 'storybook/internal/common';
11
16
  import { dedent } from 'ts-dedent';
12
17
  import fs from 'fs';
13
18
  import { webpackIncludeRegexp } from '@storybook/core-webpack';
14
- import { webpack } from '@storybook/addon-docs/dist/preset';
15
- import { pluginTypeCheck } from '@rsbuild/plugin-type-check';
16
- import { pluginHtmlMinifierTerser } from 'rsbuild-plugin-html-minifier-terser';
17
- import { corePath } from 'storybook/core-path';
18
19
  import { readFile } from 'fs/promises';
19
20
 
20
21
  // ../../node_modules/.pnpm/pretty-hrtime@1.0.3/node_modules/pretty-hrtime/index.js
@@ -88,6 +89,9 @@ var require_pretty_hrtime = __commonJS({
88
89
  }
89
90
  });
90
91
 
92
+ // src/index.ts
93
+ var import_pretty_hrtime = __toESM(require_pretty_hrtime());
94
+
91
95
  // ../../node_modules/.pnpm/slash@5.1.0/node_modules/slash/index.js
92
96
  function slash(path2) {
93
97
  const isExtendedLengthPath = path2.startsWith("\\\\?\\");
@@ -123,7 +127,8 @@ var getVirtualModules = async (options) => {
123
127
  ].filter(Boolean);
124
128
  const storiesFilename = "storybook-stories.js";
125
129
  const storiesPath = resolve(join(workingDir, storiesFilename));
126
- const needPipelinedImport = !isProd;
130
+ const builderOptions = await getBuilderOptions(options);
131
+ const needPipelinedImport = !!builderOptions.lazyCompilation && !isProd;
127
132
  virtualModules[storiesPath] = toImportFn(stories, realPathRelativeToCwd, {
128
133
  needPipelinedImport
129
134
  });
@@ -141,9 +146,9 @@ var getVirtualModules = async (options) => {
141
146
  // We need to double escape `\` for webpack. We may have some in windows paths
142
147
  ).replace(/\\/g, "\\\\");
143
148
  entries.push(configEntryPath);
144
- Object.entries(virtualModules).forEach(([key, value]) => {
149
+ for (const [key, value] of Object.entries(virtualModules)) {
145
150
  fs.writeFileSync(key, value);
146
- });
151
+ }
147
152
  return {
148
153
  virtualModules,
149
154
  entries
@@ -168,7 +173,7 @@ function toImportFnPart(specifier) {
168
173
  `;
169
174
  }
170
175
  function toImportFn(stories, relativeOffset, { needPipelinedImport } = {}) {
171
- let pipelinedImport = `const pipeline = (x) => x();`;
176
+ let pipelinedImport = "const pipeline = (x) => x();";
172
177
  if (needPipelinedImport) {
173
178
  pipelinedImport = `
174
179
  const importPipeline = ${importPipeline};
@@ -215,6 +220,8 @@ function importPipeline() {
215
220
  return moduleExportsPromise;
216
221
  };
217
222
  }
223
+
224
+ // src/preview/iframe-rsbuild.config.ts
218
225
  var getAbsolutePath = (input) => dirname(__require.resolve(join(input, "package.json")));
219
226
  var maybeGetAbsolutePath = (input) => {
220
227
  try {
@@ -223,19 +230,19 @@ var maybeGetAbsolutePath = (input) => {
223
230
  return false;
224
231
  }
225
232
  };
226
- var managerAPIPath = maybeGetAbsolutePath(`@storybook/manager-api`);
227
- var componentsPath = maybeGetAbsolutePath(`@storybook/components`);
228
- var globalPath = maybeGetAbsolutePath(`@storybook/global`);
229
- var routerPath = maybeGetAbsolutePath(`@storybook/router`);
230
- var themingPath = maybeGetAbsolutePath(`@storybook/theming`);
233
+ var managerAPIPath = maybeGetAbsolutePath("@storybook/manager-api");
234
+ var componentsPath = maybeGetAbsolutePath("@storybook/components");
235
+ var globalPath = maybeGetAbsolutePath("@storybook/global");
236
+ var routerPath = maybeGetAbsolutePath("@storybook/router");
237
+ var themingPath = maybeGetAbsolutePath("@storybook/theming");
231
238
  var storybookPaths = {
232
239
  ...managerAPIPath ? {
233
- [`@storybook/manager-api`]: managerAPIPath
240
+ "@storybook/manager-api": managerAPIPath
234
241
  } : {},
235
- ...componentsPath ? { [`@storybook/components`]: componentsPath } : {},
236
- ...globalPath ? { [`@storybook/global`]: globalPath } : {},
237
- ...routerPath ? { [`@storybook/router`]: routerPath } : {},
238
- ...themingPath ? { [`@storybook/theming`]: themingPath } : {}
242
+ ...componentsPath ? { "@storybook/components": componentsPath } : {},
243
+ ...globalPath ? { "@storybook/global": globalPath } : {},
244
+ ...routerPath ? { "@storybook/router": routerPath } : {},
245
+ ...themingPath ? { "@storybook/theming": themingPath } : {}
239
246
  };
240
247
  var iframe_rsbuild_config_default = async (options) => {
241
248
  const appliedDocsWebpack = await webpack({}, options);
@@ -288,6 +295,10 @@ var iframe_rsbuild_config_default = async (options) => {
288
295
  });
289
296
  const shouldCheckTs = typescriptOptions.check && !typescriptOptions.skipCompiler;
290
297
  const tsCheckOptions = typescriptOptions.checkOptions || {};
298
+ const builderOptions = await getBuilderOptions(options);
299
+ const lazyCompilationConfig = builderOptions.lazyCompilation && !isProd ? {
300
+ lazyCompilation: { entries: false }
301
+ } : {};
291
302
  if (!template) {
292
303
  throw new Error(dedent`
293
304
  Storybook's Webpack5 builder requires a template to be specified.
@@ -317,7 +328,7 @@ var iframe_rsbuild_config_default = async (options) => {
317
328
  },
318
329
  sourceMap: {
319
330
  js: options.build?.test?.disableSourcemaps ? false : "cheap-module-source-map",
320
- css: options.build?.test?.disableSourcemaps ? false : true
331
+ css: !options.build?.test?.disableSourcemaps
321
332
  },
322
333
  distPath: {
323
334
  root: resolve(process.cwd(), outputDir)
@@ -422,10 +433,15 @@ var iframe_rsbuild_config_default = async (options) => {
422
433
  new CaseSensitivePathsPlugin()
423
434
  ].filter(Boolean)
424
435
  );
436
+ config.experiments ??= {};
437
+ config.experiments = {
438
+ ...config.experiments,
439
+ ...lazyCompilationConfig
440
+ };
425
441
  return mergeConfig(config, appliedDocsWebpack);
426
442
  },
427
443
  htmlPlugin: {
428
- filename: `iframe.html`,
444
+ filename: "iframe.html",
429
445
  // FIXME: `none` isn't a known option
430
446
  chunksSortMode: "none",
431
447
  alwaysWriteToDisk: true,
@@ -491,7 +507,6 @@ var applyReactShims = async (config, options) => {
491
507
  };
492
508
 
493
509
  // src/index.ts
494
- var import_pretty_hrtime = __toESM(require_pretty_hrtime());
495
510
  var printDuration = (startTime) => (0, import_pretty_hrtime.default)(process.hrtime(startTime)).replace(" ms", " milliseconds").replace(" s", " seconds").replace(" m", " minutes");
496
511
  var executor = {
497
512
  get: async (options) => {
@@ -543,10 +558,9 @@ var start = async ({
543
558
  ...config,
544
559
  server: {
545
560
  ...config.server,
546
- port: options.port,
547
- host: "localhost",
561
+ port: await getRandomPort(options.host),
562
+ host: options.host,
548
563
  htmlFallback: false,
549
- strictPort: true,
550
564
  printUrls: false
551
565
  },
552
566
  dev: {
@@ -567,13 +581,13 @@ var start = async ({
567
581
  if (!rsbuildBuild) {
568
582
  throw new WebpackInvocationError({
569
583
  // eslint-disable-next-line local-rules/no-uncategorized-errors
570
- error: new Error(`Missing Rsbuild build instance at runtime!`)
584
+ error: new Error("Missing Rsbuild build instance at runtime!")
571
585
  });
572
586
  }
573
587
  const previewResolvedDir = join(corePath, "dist/preview");
574
588
  const previewDirOrigin = previewResolvedDir;
575
589
  router.use(
576
- `/sb-preview`,
590
+ "/sb-preview",
577
591
  express.static(previewDirOrigin, { immutable: true, maxAge: "5m" })
578
592
  );
579
593
  router.use(rsbuildServer.middlewares);
@@ -594,7 +608,7 @@ var build = async ({ options }) => {
594
608
  });
595
609
  const previewResolvedDir = join(corePath, "dist/preview");
596
610
  const previewDirOrigin = previewResolvedDir;
597
- const previewDirTarget = join(options.outputDir || "", `sb-preview`);
611
+ const previewDirTarget = join(options.outputDir || "", "sb-preview");
598
612
  let stats;
599
613
  rsbuildBuild.onAfterBuild((params) => {
600
614
  stats = params.stats;
@@ -616,5 +630,18 @@ var build = async ({ options }) => {
616
630
  };
617
631
  var corePresets = [join(__dirname, "./preview-preset.js")];
618
632
  var previewMainTemplate = () => __require.resolve("storybook-builder-rsbuild/templates/preview.ejs");
633
+ function getRandomPort(host) {
634
+ return new Promise((resolve3, reject) => {
635
+ const server2 = createServer();
636
+ server2.unref();
637
+ server2.on("error", reject);
638
+ server2.listen({ port: 0, host }, () => {
639
+ const { port } = server2.address();
640
+ server2.close(() => {
641
+ resolve3(port);
642
+ });
643
+ });
644
+ });
645
+ }
619
646
 
620
647
  export { bail, build, corePresets, executor, getConfig, getVirtualModules, importPipeline, previewMainTemplate, printDuration, rsbuild, start, toImportFn, toImportFnPart };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "storybook-builder-rsbuild",
3
- "version": "0.0.7",
3
+ "version": "0.0.8",
4
4
  "description": "Rsbuild builder for Storybook",
5
5
  "keywords": [
6
6
  "storybook",
@@ -56,7 +56,7 @@
56
56
  "!src/**/*"
57
57
  ],
58
58
  "dependencies": {
59
- "@rsbuild/plugin-type-check": "1.0.0-alpha.9",
59
+ "@rsbuild/plugin-type-check": "1.0.1-beta.0",
60
60
  "@storybook/addon-docs": "^8.2.1",
61
61
  "@storybook/core-webpack": "^8.2.1",
62
62
  "browser-assert": "^1.2.1",
@@ -78,7 +78,7 @@
78
78
  "util-deprecate": "^1.0.2"
79
79
  },
80
80
  "devDependencies": {
81
- "@rsbuild/core": "1.0.0-alpha.9",
81
+ "@rsbuild/core": "1.0.1-beta.0",
82
82
  "@types/express": "^4.17.21",
83
83
  "@types/fs-extra": "^11.0.4",
84
84
  "@types/node": "^18.0.0",
@@ -110,6 +110,7 @@
110
110
  "platform": "node"
111
111
  },
112
112
  "scripts": {
113
+ "build": "pnpm run prep --optimized",
113
114
  "check": "node --loader ../../scripts/node_modules/esbuild-register/loader.js -r ../../scripts/node_modules/esbuild-register/register.js ../../scripts/prepare/check.ts",
114
115
  "prep": "node --loader ../../scripts/node_modules/esbuild-register/loader.js -r ../../scripts/node_modules/esbuild-register/register.js ../../scripts/prepare/bundle.ts"
115
116
  }