storybook-builder-rsbuild 0.1.0 → 0.1.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.
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import * as rsbuildReal from '@rsbuild/core';
2
2
  import { RsbuildConfig } from '@rsbuild/core';
3
- import { TypescriptOptions as TypescriptOptions$1, Builder, Options, BuilderResult as BuilderResult$1, NormalizedStoriesSpecifier } from 'storybook/internal/types';
3
+ import { TypescriptOptions as TypescriptOptions$1, Builder, Options, StorybookConfigRaw, BuilderResult as BuilderResult$1, NormalizedStoriesSpecifier } from 'storybook/internal/types';
4
4
  import { PluginTypeCheckerOptions } from '@rsbuild/plugin-type-check';
5
5
 
6
6
  type RsbuildStats = {
@@ -19,6 +19,7 @@ type RsbuildBuilder = Builder<RsbuildConfig, RsbuildStats>;
19
19
  type RsbuildFinal = (config: RsbuildConfig, options: Options) => RsbuildConfig | Promise<RsbuildConfig>;
20
20
  type StorybookConfigRsbuild = {
21
21
  rsbuildFinal?: RsbuildFinal;
22
+ webpackAddons?: StorybookConfigRaw['addons'];
22
23
  };
23
24
  type BuilderOptions = {
24
25
  /**
@@ -42,10 +43,6 @@ interface BuilderResult extends BuilderResult$1 {
42
43
  stats?: Stats;
43
44
  }
44
45
 
45
- type RsbuildBuilderOptions = Options & {
46
- typescriptOptions: TypescriptOptions;
47
- };
48
-
49
46
  declare const getVirtualModules: (options: Options) => Promise<{
50
47
  virtualModules: Record<string, string>;
51
48
  entries: string[];
@@ -66,7 +63,6 @@ type BuilderStartOptions = Parameters<RsbuildBuilder['start']>['0'];
66
63
  declare const executor: {
67
64
  get: (options: Options) => Promise<typeof rsbuildReal>;
68
65
  };
69
- declare const rsbuild: (_: unknown, options: RsbuildBuilderOptions) => Promise<rsbuildReal.RsbuildConfig>;
70
66
  declare const getConfig: RsbuildBuilder['getConfig'];
71
67
  declare function bail(): Promise<void>;
72
68
  declare const start: RsbuildBuilder['start'];
@@ -74,4 +70,4 @@ declare const build: ({ options }: BuilderStartOptions) => Promise<Stats>;
74
70
  declare const corePresets: string[];
75
71
  declare const previewMainTemplate: () => string;
76
72
 
77
- export { BuilderOptions, BuilderResult, RsbuildBuilder, RsbuildFinal, Stats, StorybookConfigRsbuild, TypescriptOptions, bail, build, corePresets, executor, getConfig, getVirtualModules, importPipeline, previewMainTemplate, printDuration, rsbuild, start, toImportFn, toImportFnPart };
73
+ export { BuilderOptions, BuilderResult, RsbuildBuilder, RsbuildFinal, Stats, StorybookConfigRsbuild, TypescriptOptions, bail, build, corePresets, executor, getConfig, getVirtualModules, importPipeline, previewMainTemplate, printDuration, start, toImportFn, toImportFnPart };
package/dist/index.js CHANGED
@@ -114,7 +114,6 @@ __export(src_exports, {
114
114
  importPipeline: () => importPipeline,
115
115
  previewMainTemplate: () => previewMainTemplate,
116
116
  printDuration: () => printDuration,
117
- rsbuild: () => rsbuild,
118
117
  start: () => start,
119
118
  toImportFn: () => toImportFn,
120
119
  toImportFnPart: () => toImportFnPart
@@ -123,11 +122,11 @@ module.exports = __toCommonJS(src_exports);
123
122
  var import_node_net = require("net");
124
123
  var import_node_path5 = require("path");
125
124
  var rsbuildReal = __toESM(require("@rsbuild/core"));
126
- var import_core2 = require("@rsbuild/core");
127
- var import_express = __toESM(require("express"));
128
125
  var import_fs_extra = __toESM(require("fs-extra"));
129
126
  var import_pretty_hrtime = __toESM(require_pretty_hrtime());
127
+ var import_sirv = __toESM(require("sirv"));
130
128
  var import_core_path = require("storybook/core-path");
129
+ var import_common3 = require("storybook/internal/common");
131
130
  var import_server_errors = require("storybook/internal/server-errors");
132
131
 
133
132
  // src/preview/iframe-rsbuild.config.ts
@@ -162,7 +161,15 @@ var import_ts_dedent = require("ts-dedent");
162
161
  var getVirtualModules = async (options) => {
163
162
  const virtualModules = {};
164
163
  const cwd = process.cwd();
165
- const workingDir = options.cache?.basePath || process.cwd();
164
+ const workingDir = options.cache ? import_node_path.default.resolve(
165
+ process.cwd(),
166
+ // TODO: This is a hard code cache dir, as Rspack doesn't support virtual modules now.
167
+ // Remove this when Rspack supports virtual modules.
168
+ "./node_modules/.cache/storybook/storybook-rsbuild-builder"
169
+ ) : process.cwd();
170
+ if (!import_node_fs.default.existsSync(workingDir)) {
171
+ import_node_fs.default.mkdirSync(workingDir, { recursive: true });
172
+ }
166
173
  const isProd = options.configType === "PRODUCTION";
167
174
  const nonNormalizedStories = await options.presets.apply("stories", []);
168
175
  const entries = [];
@@ -192,15 +199,14 @@ var getVirtualModules = async (options) => {
192
199
  needPipelinedImport
193
200
  });
194
201
  const configEntryPath = (0, import_node_path2.resolve)((0, import_node_path2.join)(workingDir, "storybook-config-entry.js"));
195
- virtualModules[configEntryPath] = (0, import_common.handlebars)(
196
- await (0, import_common.readTemplate)(
197
- require.resolve("storybook-builder-rsbuild/templates/virtualModuleModernEntry.js.handlebars")
198
- ),
199
- {
200
- storiesFilename,
201
- previewAnnotations
202
- }
203
- // We need to double escape `\` for webpack. We may have some in windows paths
202
+ virtualModules[configEntryPath] = (await (0, import_common.readTemplate)(
203
+ require.resolve("storybook-builder-rsbuild/templates/virtualModuleModernEntry.js")
204
+ )).replaceAll(`'{{storiesFilename}}'`, `'./${storiesFilename}'`).replaceAll(
205
+ `'{{previewAnnotations}}'`,
206
+ previewAnnotations.filter(Boolean).map((entry) => `'${entry}'`).join(",")
207
+ ).replaceAll(
208
+ `'{{previewAnnotations_requires}}'`,
209
+ previewAnnotations.filter(Boolean).map((entry) => `require('${entry}')`).join(",")
204
210
  ).replace(/\\/g, "\\\\");
205
211
  entries.push(configEntryPath);
206
212
  for (const [key, value] of Object.entries(virtualModules)) {
@@ -301,7 +307,7 @@ var storybookPaths = {
301
307
  ...routerPath ? { "@storybook/router": routerPath } : {},
302
308
  ...themingPath ? { "@storybook/theming": themingPath } : {}
303
309
  };
304
- var iframe_rsbuild_config_default = async (options) => {
310
+ var iframe_rsbuild_config_default = async (options, extraWebpackConfig) => {
305
311
  const { rsbuildConfigPath, addonDocs } = await (0, import_common2.getBuilderOptions)(options);
306
312
  const appliedDocsWebpack = await (0, import_preset.webpack)({}, { ...options, ...addonDocs });
307
313
  const {
@@ -327,7 +333,7 @@ var iframe_rsbuild_config_default = async (options) => {
327
333
  docsOptions,
328
334
  entries,
329
335
  nonNormalizedStories,
330
- // modulesCount = 1000,
336
+ _modulesCount,
331
337
  build2,
332
338
  tagsOptions
333
339
  ] = await Promise.all([
@@ -341,8 +347,7 @@ var iframe_rsbuild_config_default = async (options) => {
341
347
  presets.apply("docs"),
342
348
  presets.apply("entries", []),
343
349
  presets.apply("stories", []),
344
- options.cache?.get("modulesCount").catch(() => {
345
- }),
350
+ options.cache?.get("modulesCount", 1e3),
346
351
  options.presets.apply("build"),
347
352
  presets.apply("tags", {})
348
353
  ]);
@@ -411,7 +416,7 @@ var iframe_rsbuild_config_default = async (options) => {
411
416
  contentFromConfig.source ??= {};
412
417
  contentFromConfig.source.entry = {};
413
418
  const resourceFilename = isProd ? "static/media/[name].[contenthash:8][ext]" : "static/media/[path][name][ext]";
414
- const merged = (0, import_core.mergeRsbuildConfig)(contentFromConfig, {
419
+ const rsbuildConfig = (0, import_core.mergeRsbuildConfig)(contentFromConfig, {
415
420
  output: {
416
421
  cleanDistPath: false,
417
422
  assetPrefix: "/",
@@ -539,7 +544,7 @@ var iframe_rsbuild_config_default = async (options) => {
539
544
  ...config.experiments,
540
545
  ...lazyCompilationConfig
541
546
  };
542
- return mergeConfig(config, appliedDocsWebpack);
547
+ return mergeConfig(config, extraWebpackConfig, appliedDocsWebpack);
543
548
  },
544
549
  htmlPlugin: {
545
550
  filename: "iframe.html",
@@ -571,7 +576,7 @@ var iframe_rsbuild_config_default = async (options) => {
571
576
  }
572
577
  }
573
578
  });
574
- return merged;
579
+ return rsbuildConfig;
575
580
  };
576
581
 
577
582
  // src/react-shims.ts
@@ -619,11 +624,43 @@ var executor = {
619
624
  return rsbuildInstance;
620
625
  }
621
626
  };
627
+ var isObject = (val) => val != null && typeof val === "object" && Array.isArray(val) === false;
628
+ function nonNullables(value) {
629
+ return value !== void 0;
630
+ }
622
631
  var rsbuild = async (_, options) => {
623
632
  const { presets } = options;
624
- let defaultConfig = await iframe_rsbuild_config_default(options);
633
+ const webpackAddons = await presets.apply("webpackAddons");
634
+ const resolvedWebpackAddons = (webpackAddons ?? []).map((preset) => {
635
+ const options2 = isObject(preset) ? preset.options || void 0 : void 0;
636
+ const name = isObject(preset) ? preset.name : preset;
637
+ return (0, import_common3.resolveAddonName)(options2.configDir, name, options2);
638
+ }).filter(nonNullables);
639
+ const { apply } = await (0, import_common3.getPresets)(resolvedWebpackAddons, options);
640
+ const webpackAddonsConfig = await apply(
641
+ "webpackFinal",
642
+ // TODO: using empty webpack config as base for now. It's better to using the composed rspack
643
+ // config in `iframe-rsbuild.config.ts` as base config. But when `tools.rspack` is an async function,
644
+ // the following `tools.rspack` raise an ` Promises are not supported` error.
645
+ {
646
+ output: {},
647
+ module: {},
648
+ plugins: [],
649
+ resolve: {},
650
+ devServer: {},
651
+ optimization: {},
652
+ performance: {},
653
+ externals: {},
654
+ experiments: {},
655
+ node: {},
656
+ stats: {},
657
+ entry: {}
658
+ },
659
+ options
660
+ );
661
+ let defaultConfig = await iframe_rsbuild_config_default(options, webpackAddonsConfig);
625
662
  const shimsConfig = await applyReactShims(defaultConfig, options);
626
- defaultConfig = (0, import_core2.mergeRsbuildConfig)(
663
+ defaultConfig = rsbuildReal.mergeRsbuildConfig(
627
664
  defaultConfig,
628
665
  shimsConfig
629
666
  );
@@ -632,7 +669,7 @@ var rsbuild = async (_, options) => {
632
669
  defaultConfig,
633
670
  options
634
671
  );
635
- return (0, import_core2.mergeRsbuildConfig)(finalDefaultConfig);
672
+ return finalDefaultConfig;
636
673
  };
637
674
  var getConfig = async (options) => {
638
675
  const { presets } = options;
@@ -693,7 +730,7 @@ var start = async ({
693
730
  const previewDirOrigin = previewResolvedDir;
694
731
  router.use(
695
732
  "/sb-preview",
696
- import_express.default.static(previewDirOrigin, { immutable: true, maxAge: "5m" })
733
+ (0, import_sirv.default)(previewDirOrigin, { maxAge: 3e5, dev: true, immutable: true })
697
734
  );
698
735
  router.use(rsbuildServer.middlewares);
699
736
  rsbuildServer.connectWebSocket({ server: storybookServer });
@@ -759,7 +796,6 @@ function getRandomPort(host) {
759
796
  importPipeline,
760
797
  previewMainTemplate,
761
798
  printDuration,
762
- rsbuild,
763
799
  start,
764
800
  toImportFn,
765
801
  toImportFnPart
package/dist/index.mjs CHANGED
@@ -2,16 +2,16 @@ import { __commonJS, __toESM, __require } from './chunk-TTFRSOOU.mjs';
2
2
  import { createServer } from 'net';
3
3
  import path, { join, resolve, parse, dirname, isAbsolute } from 'path';
4
4
  import * as rsbuildReal from '@rsbuild/core';
5
- import { mergeRsbuildConfig, loadConfig } from '@rsbuild/core';
6
- import express from 'express';
5
+ import { loadConfig, mergeRsbuildConfig } from '@rsbuild/core';
7
6
  import fs2 from 'fs-extra';
7
+ import sirv from 'sirv';
8
8
  import { corePath } from 'storybook/core-path';
9
+ import { normalizeStories, loadPreviewOrConfigFile, getBuilderOptions, readTemplate, resolveAddonName, getPresets, stringifyProcessEnvs, isPreservingSymlinks } from 'storybook/internal/common';
9
10
  import { WebpackInvocationError } from 'storybook/internal/server-errors';
10
11
  import { pluginTypeCheck } from '@rsbuild/plugin-type-check';
11
12
  import { webpack } from '@storybook/addon-docs/dist/preset';
12
13
  import CaseSensitivePathsPlugin from 'case-sensitive-paths-webpack-plugin';
13
14
  import { pluginHtmlMinifierTerser } from 'rsbuild-plugin-html-minifier-terser';
14
- import { normalizeStories, loadPreviewOrConfigFile, getBuilderOptions, handlebars, readTemplate, stringifyProcessEnvs, isPreservingSymlinks } from 'storybook/internal/common';
15
15
  import { globalsNameReferenceMap } from 'storybook/internal/preview/globals';
16
16
  import { dedent } from 'ts-dedent';
17
17
  import fs from 'fs';
@@ -103,7 +103,15 @@ function slash(path2) {
103
103
  var getVirtualModules = async (options) => {
104
104
  const virtualModules = {};
105
105
  const cwd = process.cwd();
106
- const workingDir = options.cache?.basePath || process.cwd();
106
+ const workingDir = options.cache ? path.resolve(
107
+ process.cwd(),
108
+ // TODO: This is a hard code cache dir, as Rspack doesn't support virtual modules now.
109
+ // Remove this when Rspack supports virtual modules.
110
+ "./node_modules/.cache/storybook/storybook-rsbuild-builder"
111
+ ) : process.cwd();
112
+ if (!fs.existsSync(workingDir)) {
113
+ fs.mkdirSync(workingDir, { recursive: true });
114
+ }
107
115
  const isProd = options.configType === "PRODUCTION";
108
116
  const nonNormalizedStories = await options.presets.apply("stories", []);
109
117
  const entries = [];
@@ -133,17 +141,16 @@ var getVirtualModules = async (options) => {
133
141
  needPipelinedImport
134
142
  });
135
143
  const configEntryPath = resolve(join(workingDir, "storybook-config-entry.js"));
136
- virtualModules[configEntryPath] = handlebars(
137
- await readTemplate(
138
- __require.resolve(
139
- "storybook-builder-rsbuild/templates/virtualModuleModernEntry.js.handlebars"
140
- )
141
- ),
142
- {
143
- storiesFilename,
144
- previewAnnotations
145
- }
146
- // We need to double escape `\` for webpack. We may have some in windows paths
144
+ virtualModules[configEntryPath] = (await readTemplate(
145
+ __require.resolve(
146
+ "storybook-builder-rsbuild/templates/virtualModuleModernEntry.js"
147
+ )
148
+ )).replaceAll(`'{{storiesFilename}}'`, `'./${storiesFilename}'`).replaceAll(
149
+ `'{{previewAnnotations}}'`,
150
+ previewAnnotations.filter(Boolean).map((entry) => `'${entry}'`).join(",")
151
+ ).replaceAll(
152
+ `'{{previewAnnotations_requires}}'`,
153
+ previewAnnotations.filter(Boolean).map((entry) => `require('${entry}')`).join(",")
147
154
  ).replace(/\\/g, "\\\\");
148
155
  entries.push(configEntryPath);
149
156
  for (const [key, value] of Object.entries(virtualModules)) {
@@ -244,7 +251,7 @@ var storybookPaths = {
244
251
  ...routerPath ? { "@storybook/router": routerPath } : {},
245
252
  ...themingPath ? { "@storybook/theming": themingPath } : {}
246
253
  };
247
- var iframe_rsbuild_config_default = async (options) => {
254
+ var iframe_rsbuild_config_default = async (options, extraWebpackConfig) => {
248
255
  const { rsbuildConfigPath, addonDocs } = await getBuilderOptions(options);
249
256
  const appliedDocsWebpack = await webpack({}, { ...options, ...addonDocs });
250
257
  const {
@@ -270,7 +277,7 @@ var iframe_rsbuild_config_default = async (options) => {
270
277
  docsOptions,
271
278
  entries,
272
279
  nonNormalizedStories,
273
- // modulesCount = 1000,
280
+ _modulesCount,
274
281
  build2,
275
282
  tagsOptions
276
283
  ] = await Promise.all([
@@ -284,8 +291,7 @@ var iframe_rsbuild_config_default = async (options) => {
284
291
  presets.apply("docs"),
285
292
  presets.apply("entries", []),
286
293
  presets.apply("stories", []),
287
- options.cache?.get("modulesCount").catch(() => {
288
- }),
294
+ options.cache?.get("modulesCount", 1e3),
289
295
  options.presets.apply("build"),
290
296
  presets.apply("tags", {})
291
297
  ]);
@@ -354,7 +360,7 @@ var iframe_rsbuild_config_default = async (options) => {
354
360
  contentFromConfig.source ??= {};
355
361
  contentFromConfig.source.entry = {};
356
362
  const resourceFilename = isProd ? "static/media/[name].[contenthash:8][ext]" : "static/media/[path][name][ext]";
357
- const merged = mergeRsbuildConfig(contentFromConfig, {
363
+ const rsbuildConfig = mergeRsbuildConfig(contentFromConfig, {
358
364
  output: {
359
365
  cleanDistPath: false,
360
366
  assetPrefix: "/",
@@ -484,7 +490,7 @@ var iframe_rsbuild_config_default = async (options) => {
484
490
  ...config.experiments,
485
491
  ...lazyCompilationConfig
486
492
  };
487
- return mergeConfig(config, appliedDocsWebpack);
493
+ return mergeConfig(config, extraWebpackConfig, appliedDocsWebpack);
488
494
  },
489
495
  htmlPlugin: {
490
496
  filename: "iframe.html",
@@ -516,7 +522,7 @@ var iframe_rsbuild_config_default = async (options) => {
516
522
  }
517
523
  }
518
524
  });
519
- return merged;
525
+ return rsbuildConfig;
520
526
  };
521
527
  var getIsReactVersion18or19 = async (options) => {
522
528
  const { legacyRootApi } = await options.presets.apply(
@@ -560,11 +566,43 @@ var executor = {
560
566
  return rsbuildInstance;
561
567
  }
562
568
  };
569
+ var isObject = (val) => val != null && typeof val === "object" && Array.isArray(val) === false;
570
+ function nonNullables(value) {
571
+ return value !== void 0;
572
+ }
563
573
  var rsbuild = async (_, options) => {
564
574
  const { presets } = options;
565
- let defaultConfig = await iframe_rsbuild_config_default(options);
575
+ const webpackAddons = await presets.apply("webpackAddons");
576
+ const resolvedWebpackAddons = (webpackAddons ?? []).map((preset) => {
577
+ const options2 = isObject(preset) ? preset.options || void 0 : void 0;
578
+ const name = isObject(preset) ? preset.name : preset;
579
+ return resolveAddonName(options2.configDir, name, options2);
580
+ }).filter(nonNullables);
581
+ const { apply } = await getPresets(resolvedWebpackAddons, options);
582
+ const webpackAddonsConfig = await apply(
583
+ "webpackFinal",
584
+ // TODO: using empty webpack config as base for now. It's better to using the composed rspack
585
+ // config in `iframe-rsbuild.config.ts` as base config. But when `tools.rspack` is an async function,
586
+ // the following `tools.rspack` raise an ` Promises are not supported` error.
587
+ {
588
+ output: {},
589
+ module: {},
590
+ plugins: [],
591
+ resolve: {},
592
+ devServer: {},
593
+ optimization: {},
594
+ performance: {},
595
+ externals: {},
596
+ experiments: {},
597
+ node: {},
598
+ stats: {},
599
+ entry: {}
600
+ },
601
+ options
602
+ );
603
+ let defaultConfig = await iframe_rsbuild_config_default(options, webpackAddonsConfig);
566
604
  const shimsConfig = await applyReactShims(defaultConfig, options);
567
- defaultConfig = mergeRsbuildConfig(
605
+ defaultConfig = rsbuildReal.mergeRsbuildConfig(
568
606
  defaultConfig,
569
607
  shimsConfig
570
608
  );
@@ -573,7 +611,7 @@ var rsbuild = async (_, options) => {
573
611
  defaultConfig,
574
612
  options
575
613
  );
576
- return mergeRsbuildConfig(finalDefaultConfig);
614
+ return finalDefaultConfig;
577
615
  };
578
616
  var getConfig = async (options) => {
579
617
  const { presets } = options;
@@ -634,7 +672,7 @@ var start = async ({
634
672
  const previewDirOrigin = previewResolvedDir;
635
673
  router.use(
636
674
  "/sb-preview",
637
- express.static(previewDirOrigin, { immutable: true, maxAge: "5m" })
675
+ sirv(previewDirOrigin, { maxAge: 3e5, dev: true, immutable: true })
638
676
  );
639
677
  router.use(rsbuildServer.middlewares);
640
678
  rsbuildServer.connectWebSocket({ server: storybookServer });
@@ -690,4 +728,4 @@ function getRandomPort(host) {
690
728
  });
691
729
  }
692
730
 
693
- export { bail, build, corePresets, executor, getConfig, getVirtualModules, importPipeline, previewMainTemplate, printDuration, rsbuild, start, toImportFn, toImportFnPart };
731
+ export { bail, build, corePresets, executor, getConfig, getVirtualModules, importPipeline, previewMainTemplate, printDuration, start, toImportFn, toImportFnPart };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "storybook-builder-rsbuild",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "Rsbuild builder for Storybook",
5
5
  "keywords": [
6
6
  "storybook",
@@ -38,7 +38,7 @@
38
38
  "node": "./dist/loaders/export-order-loader.js",
39
39
  "require": "./dist/loaders/export-order-loader.js"
40
40
  },
41
- "./templates/virtualModuleModernEntry.js.handlebars": "./templates/virtualModuleModernEntry.js.handlebars",
41
+ "./templates/virtualModuleModernEntry.js": "./templates/virtualModuleModernEntry.js",
42
42
  "./templates/preview.ejs": "./templates/preview.ejs",
43
43
  "./templates/virtualModuleEntry.template.js": "./templates/virtualModuleEntry.template.js",
44
44
  "./templates/virtualModuleStory.template.js": "./templates/virtualModuleStory.template.js",
@@ -61,33 +61,29 @@
61
61
  "@storybook/core-webpack": "^8.2.1",
62
62
  "browser-assert": "^1.2.1",
63
63
  "case-sensitive-paths-webpack-plugin": "^2.4.0",
64
- "cjs-module-lexer": "^1.2.3",
64
+ "cjs-module-lexer": "^1.4.1",
65
65
  "constants-browserify": "^1.0.0",
66
- "css-loader": "^6.11.0",
67
66
  "es-module-lexer": "^1.5.4",
68
- "express": "^4.19.2",
69
67
  "fs-extra": "^11.2.0",
70
- "magic-string": "^0.30.11",
68
+ "magic-string": "^0.30.12",
71
69
  "path-browserify": "^1.0.1",
72
70
  "process": "^0.11.10",
73
71
  "rsbuild-plugin-html-minifier-terser": "^1.1.1",
74
- "style-loader": "^3.3.4",
72
+ "sirv": "^2.0.4",
75
73
  "ts-dedent": "^2.2.0",
76
74
  "url": "^0.11.4",
77
75
  "util": "^0.12.5",
78
76
  "util-deprecate": "^1.0.2"
79
77
  },
80
78
  "devDependencies": {
81
- "@rsbuild/core": "1.0.1",
82
- "@types/express": "^4.17.21",
79
+ "@rsbuild/core": "1.0.17",
83
80
  "@types/fs-extra": "^11.0.4",
84
81
  "@types/node": "^18.0.0",
85
82
  "@types/pretty-hrtime": "^1.0.3",
86
- "add": "^2.0.6",
87
83
  "pretty-hrtime": "^1.0.3",
88
84
  "slash": "^5.1.0",
89
- "storybook": "8.3.0-beta.3",
90
- "typescript": "^5.3.2"
85
+ "storybook": "8.4.0-alpha.7",
86
+ "typescript": "^5.6.3"
91
87
  },
92
88
  "peerDependencies": {
93
89
  "@rsbuild/core": "^1.0.1",
@@ -0,0 +1,38 @@
1
+ import { createBrowserChannel } from 'storybook/internal/channels'
2
+ import {
3
+ PreviewWeb,
4
+ addons,
5
+ composeConfigs,
6
+ } from 'storybook/internal/preview-api'
7
+
8
+ import { global } from '@storybook/global'
9
+
10
+ import { importFn } from '{{storiesFilename}}'
11
+
12
+ const getProjectAnnotations = () =>
13
+ composeConfigs(['{{previewAnnotations_requires}}'])
14
+
15
+ const channel = createBrowserChannel({ page: 'preview' })
16
+ addons.setChannel(channel)
17
+
18
+ if (global.CONFIG_TYPE === 'DEVELOPMENT') {
19
+ window.__STORYBOOK_SERVER_CHANNEL__ = channel
20
+ }
21
+
22
+ const preview = new PreviewWeb(importFn, getProjectAnnotations)
23
+
24
+ window.__STORYBOOK_PREVIEW__ = preview
25
+ window.__STORYBOOK_STORY_STORE__ = preview.storyStore
26
+ window.__STORYBOOK_ADDONS_CHANNEL__ = channel
27
+
28
+ if (import.meta.webpackHot) {
29
+ import.meta.webpackHot.accept('{{storiesFilename}}', () => {
30
+ // importFn has changed so we need to patch the new one in
31
+ preview.onStoriesChanged({ importFn })
32
+ })
33
+
34
+ import.meta.webpackHot.accept(['{{previewAnnotations}}'], () => {
35
+ // getProjectAnnotations has changed so we need to patch the new one in
36
+ preview.onGetProjectAnnotationsChanged({ getProjectAnnotations })
37
+ })
38
+ }
@@ -1,34 +0,0 @@
1
- import { global } from '@storybook/global';
2
-
3
- import { ClientApi, PreviewWeb, addons, composeConfigs } from 'storybook/internal/preview-api';
4
- import { createBrowserChannel } from 'storybook/internal/channels';
5
-
6
- import { importFn } from './{{storiesFilename}}';
7
-
8
- const getProjectAnnotations = () =>
9
- composeConfigs([{{#each previewAnnotations}}require('{{this}}'),{{/each}}]);
10
-
11
- const channel = createBrowserChannel({ page: 'preview' });
12
- addons.setChannel(channel);
13
-
14
- if (global.CONFIG_TYPE === 'DEVELOPMENT'){
15
- window.__STORYBOOK_SERVER_CHANNEL__ = channel;
16
- }
17
-
18
- const preview = new PreviewWeb(importFn, getProjectAnnotations);
19
-
20
- window.__STORYBOOK_PREVIEW__ = preview;
21
- window.__STORYBOOK_STORY_STORE__ = preview.storyStore;
22
- window.__STORYBOOK_ADDONS_CHANNEL__ = channel;
23
-
24
- if (import.meta.webpackHot) {
25
- import.meta.webpackHot.accept('./{{storiesFilename}}', () => {
26
- // importFn has changed so we need to patch the new one in
27
- preview.onStoriesChanged({ importFn });
28
- });
29
-
30
- import.meta.webpackHot.accept([{{#each previewAnnotations}}'{{this}}',{{/each}}], () => {
31
- // getProjectAnnotations has changed so we need to patch the new one in
32
- preview.onGetProjectAnnotationsChanged({ getProjectAnnotations });
33
- });
34
- }