storybook-builder-rsbuild 0.1.0 → 0.1.1
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 +3 -7
- package/dist/index.js +39 -8
- package/dist/index.mjs +40 -8
- package/package.json +6 -9
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,
|
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
|
@@ -128,6 +127,7 @@ var import_express = __toESM(require("express"));
|
|
128
127
|
var import_fs_extra = __toESM(require("fs-extra"));
|
129
128
|
var import_pretty_hrtime = __toESM(require_pretty_hrtime());
|
130
129
|
var import_core_path = require("storybook/core-path");
|
130
|
+
var import_common3 = require("storybook/internal/common");
|
131
131
|
var import_server_errors = require("storybook/internal/server-errors");
|
132
132
|
|
133
133
|
// src/preview/iframe-rsbuild.config.ts
|
@@ -301,7 +301,7 @@ var storybookPaths = {
|
|
301
301
|
...routerPath ? { "@storybook/router": routerPath } : {},
|
302
302
|
...themingPath ? { "@storybook/theming": themingPath } : {}
|
303
303
|
};
|
304
|
-
var iframe_rsbuild_config_default = async (options) => {
|
304
|
+
var iframe_rsbuild_config_default = async (options, extraWebpackConfig) => {
|
305
305
|
const { rsbuildConfigPath, addonDocs } = await (0, import_common2.getBuilderOptions)(options);
|
306
306
|
const appliedDocsWebpack = await (0, import_preset.webpack)({}, { ...options, ...addonDocs });
|
307
307
|
const {
|
@@ -411,7 +411,7 @@ var iframe_rsbuild_config_default = async (options) => {
|
|
411
411
|
contentFromConfig.source ??= {};
|
412
412
|
contentFromConfig.source.entry = {};
|
413
413
|
const resourceFilename = isProd ? "static/media/[name].[contenthash:8][ext]" : "static/media/[path][name][ext]";
|
414
|
-
const
|
414
|
+
const rsbuildConfig = (0, import_core.mergeRsbuildConfig)(contentFromConfig, {
|
415
415
|
output: {
|
416
416
|
cleanDistPath: false,
|
417
417
|
assetPrefix: "/",
|
@@ -539,7 +539,7 @@ var iframe_rsbuild_config_default = async (options) => {
|
|
539
539
|
...config.experiments,
|
540
540
|
...lazyCompilationConfig
|
541
541
|
};
|
542
|
-
return mergeConfig(config, appliedDocsWebpack);
|
542
|
+
return mergeConfig(config, extraWebpackConfig, appliedDocsWebpack);
|
543
543
|
},
|
544
544
|
htmlPlugin: {
|
545
545
|
filename: "iframe.html",
|
@@ -571,7 +571,7 @@ var iframe_rsbuild_config_default = async (options) => {
|
|
571
571
|
}
|
572
572
|
}
|
573
573
|
});
|
574
|
-
return
|
574
|
+
return rsbuildConfig;
|
575
575
|
};
|
576
576
|
|
577
577
|
// src/react-shims.ts
|
@@ -619,9 +619,41 @@ var executor = {
|
|
619
619
|
return rsbuildInstance;
|
620
620
|
}
|
621
621
|
};
|
622
|
+
var isObject = (val) => val != null && typeof val === "object" && Array.isArray(val) === false;
|
623
|
+
function nonNullables(value) {
|
624
|
+
return value !== void 0;
|
625
|
+
}
|
622
626
|
var rsbuild = async (_, options) => {
|
623
627
|
const { presets } = options;
|
624
|
-
|
628
|
+
const webpackAddons = await presets.apply("webpackAddons");
|
629
|
+
const resolvedWebpackAddons = (webpackAddons ?? []).map((preset) => {
|
630
|
+
const options2 = isObject(preset) ? preset.options || void 0 : void 0;
|
631
|
+
const name = isObject(preset) ? preset.name : preset;
|
632
|
+
return (0, import_common3.resolveAddonName)(options2.configDir, name, options2);
|
633
|
+
}).filter(nonNullables);
|
634
|
+
const { apply } = await (0, import_common3.getPresets)(resolvedWebpackAddons, options);
|
635
|
+
const webpackAddonsConfig = await apply(
|
636
|
+
"webpackFinal",
|
637
|
+
// TODO: using empty webpack config as base for now. It's better to using the composed rspack
|
638
|
+
// config in `iframe-rsbuild.config.ts` as base config. But when `tools.rspack` is an async function,
|
639
|
+
// the following `tools.rspack` raise an ` Promises are not supported` error.
|
640
|
+
{
|
641
|
+
output: {},
|
642
|
+
module: {},
|
643
|
+
plugins: [],
|
644
|
+
resolve: {},
|
645
|
+
devServer: {},
|
646
|
+
optimization: {},
|
647
|
+
performance: {},
|
648
|
+
externals: {},
|
649
|
+
experiments: {},
|
650
|
+
node: {},
|
651
|
+
stats: {},
|
652
|
+
entry: {}
|
653
|
+
},
|
654
|
+
options
|
655
|
+
);
|
656
|
+
let defaultConfig = await iframe_rsbuild_config_default(options, webpackAddonsConfig);
|
625
657
|
const shimsConfig = await applyReactShims(defaultConfig, options);
|
626
658
|
defaultConfig = (0, import_core2.mergeRsbuildConfig)(
|
627
659
|
defaultConfig,
|
@@ -632,7 +664,7 @@ var rsbuild = async (_, options) => {
|
|
632
664
|
defaultConfig,
|
633
665
|
options
|
634
666
|
);
|
635
|
-
return
|
667
|
+
return finalDefaultConfig;
|
636
668
|
};
|
637
669
|
var getConfig = async (options) => {
|
638
670
|
const { presets } = options;
|
@@ -759,7 +791,6 @@ function getRandomPort(host) {
|
|
759
791
|
importPipeline,
|
760
792
|
previewMainTemplate,
|
761
793
|
printDuration,
|
762
|
-
rsbuild,
|
763
794
|
start,
|
764
795
|
toImportFn,
|
765
796
|
toImportFnPart
|
package/dist/index.mjs
CHANGED
@@ -6,12 +6,12 @@ import { mergeRsbuildConfig, loadConfig } from '@rsbuild/core';
|
|
6
6
|
import express from 'express';
|
7
7
|
import fs2 from 'fs-extra';
|
8
8
|
import { corePath } from 'storybook/core-path';
|
9
|
+
import { normalizeStories, loadPreviewOrConfigFile, getBuilderOptions, handlebars, 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';
|
@@ -244,7 +244,7 @@ var storybookPaths = {
|
|
244
244
|
...routerPath ? { "@storybook/router": routerPath } : {},
|
245
245
|
...themingPath ? { "@storybook/theming": themingPath } : {}
|
246
246
|
};
|
247
|
-
var iframe_rsbuild_config_default = async (options) => {
|
247
|
+
var iframe_rsbuild_config_default = async (options, extraWebpackConfig) => {
|
248
248
|
const { rsbuildConfigPath, addonDocs } = await getBuilderOptions(options);
|
249
249
|
const appliedDocsWebpack = await webpack({}, { ...options, ...addonDocs });
|
250
250
|
const {
|
@@ -354,7 +354,7 @@ var iframe_rsbuild_config_default = async (options) => {
|
|
354
354
|
contentFromConfig.source ??= {};
|
355
355
|
contentFromConfig.source.entry = {};
|
356
356
|
const resourceFilename = isProd ? "static/media/[name].[contenthash:8][ext]" : "static/media/[path][name][ext]";
|
357
|
-
const
|
357
|
+
const rsbuildConfig = mergeRsbuildConfig(contentFromConfig, {
|
358
358
|
output: {
|
359
359
|
cleanDistPath: false,
|
360
360
|
assetPrefix: "/",
|
@@ -484,7 +484,7 @@ var iframe_rsbuild_config_default = async (options) => {
|
|
484
484
|
...config.experiments,
|
485
485
|
...lazyCompilationConfig
|
486
486
|
};
|
487
|
-
return mergeConfig(config, appliedDocsWebpack);
|
487
|
+
return mergeConfig(config, extraWebpackConfig, appliedDocsWebpack);
|
488
488
|
},
|
489
489
|
htmlPlugin: {
|
490
490
|
filename: "iframe.html",
|
@@ -516,7 +516,7 @@ var iframe_rsbuild_config_default = async (options) => {
|
|
516
516
|
}
|
517
517
|
}
|
518
518
|
});
|
519
|
-
return
|
519
|
+
return rsbuildConfig;
|
520
520
|
};
|
521
521
|
var getIsReactVersion18or19 = async (options) => {
|
522
522
|
const { legacyRootApi } = await options.presets.apply(
|
@@ -560,9 +560,41 @@ var executor = {
|
|
560
560
|
return rsbuildInstance;
|
561
561
|
}
|
562
562
|
};
|
563
|
+
var isObject = (val) => val != null && typeof val === "object" && Array.isArray(val) === false;
|
564
|
+
function nonNullables(value) {
|
565
|
+
return value !== void 0;
|
566
|
+
}
|
563
567
|
var rsbuild = async (_, options) => {
|
564
568
|
const { presets } = options;
|
565
|
-
|
569
|
+
const webpackAddons = await presets.apply("webpackAddons");
|
570
|
+
const resolvedWebpackAddons = (webpackAddons ?? []).map((preset) => {
|
571
|
+
const options2 = isObject(preset) ? preset.options || void 0 : void 0;
|
572
|
+
const name = isObject(preset) ? preset.name : preset;
|
573
|
+
return resolveAddonName(options2.configDir, name, options2);
|
574
|
+
}).filter(nonNullables);
|
575
|
+
const { apply } = await getPresets(resolvedWebpackAddons, options);
|
576
|
+
const webpackAddonsConfig = await apply(
|
577
|
+
"webpackFinal",
|
578
|
+
// TODO: using empty webpack config as base for now. It's better to using the composed rspack
|
579
|
+
// config in `iframe-rsbuild.config.ts` as base config. But when `tools.rspack` is an async function,
|
580
|
+
// the following `tools.rspack` raise an ` Promises are not supported` error.
|
581
|
+
{
|
582
|
+
output: {},
|
583
|
+
module: {},
|
584
|
+
plugins: [],
|
585
|
+
resolve: {},
|
586
|
+
devServer: {},
|
587
|
+
optimization: {},
|
588
|
+
performance: {},
|
589
|
+
externals: {},
|
590
|
+
experiments: {},
|
591
|
+
node: {},
|
592
|
+
stats: {},
|
593
|
+
entry: {}
|
594
|
+
},
|
595
|
+
options
|
596
|
+
);
|
597
|
+
let defaultConfig = await iframe_rsbuild_config_default(options, webpackAddonsConfig);
|
566
598
|
const shimsConfig = await applyReactShims(defaultConfig, options);
|
567
599
|
defaultConfig = mergeRsbuildConfig(
|
568
600
|
defaultConfig,
|
@@ -573,7 +605,7 @@ var rsbuild = async (_, options) => {
|
|
573
605
|
defaultConfig,
|
574
606
|
options
|
575
607
|
);
|
576
|
-
return
|
608
|
+
return finalDefaultConfig;
|
577
609
|
};
|
578
610
|
var getConfig = async (options) => {
|
579
611
|
const { presets } = options;
|
@@ -690,4 +722,4 @@ function getRandomPort(host) {
|
|
690
722
|
});
|
691
723
|
}
|
692
724
|
|
693
|
-
export { bail, build, corePresets, executor, getConfig, getVirtualModules, importPipeline, previewMainTemplate, printDuration,
|
725
|
+
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.
|
3
|
+
"version": "0.1.1",
|
4
4
|
"description": "Rsbuild builder for Storybook",
|
5
5
|
"keywords": [
|
6
6
|
"storybook",
|
@@ -61,33 +61,30 @@
|
|
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.
|
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.
|
67
|
+
"express": "^4.21.0",
|
69
68
|
"fs-extra": "^11.2.0",
|
70
69
|
"magic-string": "^0.30.11",
|
71
70
|
"path-browserify": "^1.0.1",
|
72
71
|
"process": "^0.11.10",
|
73
72
|
"rsbuild-plugin-html-minifier-terser": "^1.1.1",
|
74
|
-
"style-loader": "^3.3.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.
|
79
|
+
"@rsbuild/core": "1.0.8",
|
82
80
|
"@types/express": "^4.17.21",
|
83
81
|
"@types/fs-extra": "^11.0.4",
|
84
82
|
"@types/node": "^18.0.0",
|
85
83
|
"@types/pretty-hrtime": "^1.0.3",
|
86
|
-
"add": "^2.0.6",
|
87
84
|
"pretty-hrtime": "^1.0.3",
|
88
85
|
"slash": "^5.1.0",
|
89
|
-
"storybook": "8.
|
90
|
-
"typescript": "^5.
|
86
|
+
"storybook": "8.4.0-alpha.0",
|
87
|
+
"typescript": "^5.6.2"
|
91
88
|
},
|
92
89
|
"peerDependencies": {
|
93
90
|
"@rsbuild/core": "^1.0.1",
|