storybook-builder-rsbuild 3.4.0 → 3.4.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/_node-chunks/{chunk-NXNFA2RX.js → chunk-QCILEEJ4.js} +6 -6
- package/dist/index.d.ts +10 -2
- package/dist/index.js +74 -27
- package/dist/loaders/export-order-loader.js +7 -7
- package/dist/loaders/rsbuild-automock-loader.js +7 -7
- package/dist/loaders/storybook-mock-transform-loader.js +7 -7
- package/dist/preview-preset.js +13 -14
- package/package.json +2 -2
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
1
|
+
import CJS_COMPAT_NODE_URL_b90b3490f755cd30 from 'node:url';
|
|
2
|
+
import CJS_COMPAT_NODE_PATH_b90b3490f755cd30 from 'node:path';
|
|
3
|
+
import CJS_COMPAT_NODE_MODULE_b90b3490f755cd30 from "node:module";
|
|
4
4
|
|
|
5
|
-
var __filename =
|
|
6
|
-
var __dirname =
|
|
7
|
-
var require =
|
|
5
|
+
var __filename = CJS_COMPAT_NODE_URL_b90b3490f755cd30.fileURLToPath(import.meta.url);
|
|
6
|
+
var __dirname = CJS_COMPAT_NODE_PATH_b90b3490f755cd30.dirname(__filename);
|
|
7
|
+
var require = CJS_COMPAT_NODE_MODULE_b90b3490f755cd30.createRequire(import.meta.url);
|
|
8
8
|
|
|
9
9
|
// ------------------------------------------------------------
|
|
10
10
|
// end of CJS compatibility banner, injected by Storybook's esbuild configuration
|
package/dist/index.d.ts
CHANGED
|
@@ -48,6 +48,14 @@ interface BuilderResult extends BuilderResult$1 {
|
|
|
48
48
|
stats?: Stats;
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
+
/**
|
|
52
|
+
* Strips fields that are unsafe to inherit into the Storybook preview build.
|
|
53
|
+
*
|
|
54
|
+
* @internal For use by official Storybook Rsbuild packages only. This API is subject to change at
|
|
55
|
+
* any time and should not be used in user configuration.
|
|
56
|
+
*/
|
|
57
|
+
declare const stripInheritedConfig: (config: RsbuildConfig, source: string) => string[];
|
|
58
|
+
|
|
51
59
|
/**
|
|
52
60
|
* Re-assert Storybook core's intent to keep `node_modules` out of the stories
|
|
53
61
|
* context. Core's `(?!.*node_modules)` guard relies on webpack's context
|
|
@@ -61,7 +69,7 @@ interface BuilderResult extends BuilderResult$1 {
|
|
|
61
69
|
* — https://github.com/web-infra-dev/rspack/pull/14576.
|
|
62
70
|
*/
|
|
63
71
|
declare const excludeNodeModulesFromStoryContext: (importFnSource: string, stories: NormalizedStoriesSpecifier[]) => string;
|
|
64
|
-
declare const getVirtualModules: (options: Options) => Promise<{
|
|
72
|
+
declare const getVirtualModules: (options: Options, isLazyCompilationActive: boolean) => Promise<{
|
|
65
73
|
virtualModules: Record<string, string>;
|
|
66
74
|
entries: string[];
|
|
67
75
|
}>;
|
|
@@ -90,5 +98,5 @@ declare const build: ({ options }: BuilderStartOptions) => Promise<Stats>;
|
|
|
90
98
|
declare const corePresets: string[];
|
|
91
99
|
declare const previewMainTemplate: () => string;
|
|
92
100
|
|
|
93
|
-
export { bail, build, changeDetectionAdapter, corePresets, excludeNodeModulesFromStoryContext, executor, getConfig, getVirtualModules, previewMainTemplate, printDuration, start };
|
|
101
|
+
export { bail, build, changeDetectionAdapter, corePresets, excludeNodeModulesFromStoryContext, executor, getConfig, getVirtualModules, previewMainTemplate, printDuration, start, stripInheritedConfig };
|
|
94
102
|
export type { BuilderOptions, BuilderResult, RsbuildBuilder, RsbuildFinal, Stats, StorybookConfigRsbuild, TypescriptOptions };
|
package/dist/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
1
|
+
import CJS_COMPAT_NODE_URL_b90b3490f755cd30 from 'node:url';
|
|
2
|
+
import CJS_COMPAT_NODE_PATH_b90b3490f755cd30 from 'node:path';
|
|
3
|
+
import CJS_COMPAT_NODE_MODULE_b90b3490f755cd30 from "node:module";
|
|
4
4
|
|
|
5
|
-
var __filename =
|
|
6
|
-
var __dirname =
|
|
7
|
-
var require =
|
|
5
|
+
var __filename = CJS_COMPAT_NODE_URL_b90b3490f755cd30.fileURLToPath(import.meta.url);
|
|
6
|
+
var __dirname = CJS_COMPAT_NODE_PATH_b90b3490f755cd30.dirname(__filename);
|
|
7
|
+
var require = CJS_COMPAT_NODE_MODULE_b90b3490f755cd30.createRequire(import.meta.url);
|
|
8
8
|
|
|
9
9
|
// ------------------------------------------------------------
|
|
10
10
|
// end of CJS compatibility banner, injected by Storybook's esbuild configuration
|
|
@@ -13,7 +13,7 @@ import {
|
|
|
13
13
|
__commonJS,
|
|
14
14
|
__require,
|
|
15
15
|
__toESM
|
|
16
|
-
} from "./_node-chunks/chunk-
|
|
16
|
+
} from "./_node-chunks/chunk-QCILEEJ4.js";
|
|
17
17
|
|
|
18
18
|
// ../../node_modules/.pnpm/pretty-hrtime@1.0.3/node_modules/pretty-hrtime/index.js
|
|
19
19
|
var require_pretty_hrtime = __commonJS({
|
|
@@ -222,15 +222,52 @@ import { pluginTypeCheck } from "@rsbuild/plugin-type-check";
|
|
|
222
222
|
import CaseSensitivePathsPlugin from "case-sensitive-paths-webpack-plugin";
|
|
223
223
|
import { pluginHtmlMinifierTerser } from "rsbuild-plugin-html-minifier-terser";
|
|
224
224
|
import {
|
|
225
|
-
getBuilderOptions
|
|
225
|
+
getBuilderOptions,
|
|
226
226
|
isPreservingSymlinks,
|
|
227
227
|
normalizeStories as normalizeStories2,
|
|
228
228
|
stringifyProcessEnvs
|
|
229
229
|
} from "storybook/internal/common";
|
|
230
|
-
import { logger as
|
|
230
|
+
import { logger as logger5 } from "storybook/internal/node-logger";
|
|
231
231
|
import { globalsNameReferenceMap } from "storybook/internal/preview/globals";
|
|
232
232
|
import { dedent as dedent2 } from "ts-dedent";
|
|
233
233
|
|
|
234
|
+
// src/inherited-config.ts
|
|
235
|
+
import { logger as logger3 } from "storybook/internal/node-logger";
|
|
236
|
+
var inheritedConfigFieldPaths = [
|
|
237
|
+
"source.entry",
|
|
238
|
+
"output.distPath",
|
|
239
|
+
"output.filename",
|
|
240
|
+
"output.cleanDistPath",
|
|
241
|
+
"output.externals",
|
|
242
|
+
"output.assetPrefix",
|
|
243
|
+
"server.publicDir",
|
|
244
|
+
"dev.progressBar",
|
|
245
|
+
"dev.assetPrefix",
|
|
246
|
+
"dev.writeToDisk",
|
|
247
|
+
"tools.htmlPlugin",
|
|
248
|
+
"tools.rspack.output.library",
|
|
249
|
+
"tools.rspack.output.globalObject",
|
|
250
|
+
"tools.rspack.output.umdNamedDefine"
|
|
251
|
+
], stripConfigField = (value, segments, segmentIndex = 0) => {
|
|
252
|
+
if (Array.isArray(value)) {
|
|
253
|
+
let stripped = !1;
|
|
254
|
+
for (let item of value)
|
|
255
|
+
stripped = stripConfigField(item, segments, segmentIndex) || stripped;
|
|
256
|
+
return stripped;
|
|
257
|
+
}
|
|
258
|
+
if (!value || typeof value != "object")
|
|
259
|
+
return !1;
|
|
260
|
+
let target = value, field = segments[segmentIndex];
|
|
261
|
+
return field ? segmentIndex === segments.length - 1 ? target[field] === void 0 ? !1 : (delete target[field], !0) : stripConfigField(target[field], segments, segmentIndex + 1) : !1;
|
|
262
|
+
}, stripInheritedConfig = (config, source) => {
|
|
263
|
+
let strippedFields = inheritedConfigFieldPaths.filter(
|
|
264
|
+
(path) => stripConfigField(config, path.split("."))
|
|
265
|
+
);
|
|
266
|
+
return strippedFields.length > 0 && logger3.warn(
|
|
267
|
+
`Stripped incompatible fields from ${source} (${strippedFields.join(", ")}) because they can break the Storybook preview build.`
|
|
268
|
+
), strippedFields;
|
|
269
|
+
};
|
|
270
|
+
|
|
234
271
|
// src/preview/detect-msw.ts
|
|
235
272
|
import { existsSync } from "node:fs";
|
|
236
273
|
import { isAbsolute as isAbsolute2, resolve } from "node:path";
|
|
@@ -255,7 +292,6 @@ function slash(path) {
|
|
|
255
292
|
|
|
256
293
|
// src/preview/virtual-module-mapping.ts
|
|
257
294
|
import {
|
|
258
|
-
getBuilderOptions,
|
|
259
295
|
loadPreviewOrConfigFile,
|
|
260
296
|
normalizeStories,
|
|
261
297
|
readTemplate
|
|
@@ -504,8 +540,8 @@ var NODE_MODULES_GLOB_TOKEN = /(?:^|[\\/(|,{])node_modules(?:$|[\\/)|,}])/, toWe
|
|
|
504
540
|
];
|
|
505
541
|
}).join(`
|
|
506
542
|
`);
|
|
507
|
-
}, getVirtualModules = async (options) => {
|
|
508
|
-
let virtualModules = {},
|
|
543
|
+
}, getVirtualModules = async (options, isLazyCompilationActive) => {
|
|
544
|
+
let virtualModules = {}, workingDir = process.cwd(), nonNormalizedStories = await options.presets.apply("stories", []), entries = [], stories = normalizeStories(nonNormalizedStories, {
|
|
509
545
|
configDir: options.configDir,
|
|
510
546
|
workingDir
|
|
511
547
|
}), previewAnnotations = [
|
|
@@ -515,10 +551,10 @@ var NODE_MODULES_GLOB_TOKEN = /(?:^|[\\/(|,{])node_modules(?:$|[\\/)|,}])/, toWe
|
|
|
515
551
|
options
|
|
516
552
|
)).map((entry) => typeof entry == "object" ? entry.absolute : slash(entry)),
|
|
517
553
|
loadPreviewOrConfigFile(options)
|
|
518
|
-
].filter(Boolean), storiesFilename = "storybook-stories.js", storiesPath = resolve2(join(workingDir, storiesFilename))
|
|
554
|
+
].filter(Boolean), storiesFilename = "storybook-stories.js", storiesPath = resolve2(join(workingDir, storiesFilename));
|
|
519
555
|
virtualModules[storiesPath] = excludeNodeModulesFromStoryContext(
|
|
520
556
|
__webpack_exports__toImportFn(stories, {
|
|
521
|
-
needPipelinedImport
|
|
557
|
+
needPipelinedImport: isLazyCompilationActive
|
|
522
558
|
}),
|
|
523
559
|
stories
|
|
524
560
|
);
|
|
@@ -571,8 +607,21 @@ var require2 = createRequire(import.meta.url), getAbsolutePath = (input) => {
|
|
|
571
607
|
}, rspackMajorVersion = getRspackMajorVersion(rspack.rspackVersion), RAW_QUERY_REGEX = /[?&]raw(?:&|=|$)/, globalPath = maybeGetAbsolutePath("@storybook/global"), storybookPaths = {
|
|
572
608
|
// biome-ignore lint/complexity/useLiteralKeys: dynamic key required for conditional spread
|
|
573
609
|
...globalPath ? { "@storybook/global": globalPath } : {}
|
|
610
|
+
}, resolveLazyCompilation = async (options, builderOptions, isProd, shouldDisableDevFeatures) => {
|
|
611
|
+
let lazyCompilationConfig;
|
|
612
|
+
return isProd || (shouldDisableDevFeatures ? lazyCompilationConfig = !1 : builderOptions.lazyCompilation !== void 0 ? lazyCompilationConfig = builderOptions.lazyCompilation : await isMswActive(options) ? (lazyCompilationConfig = !1, logger5.warn(dedent2`
|
|
613
|
+
Detected mockServiceWorker.js in staticDirs. Lazy compilation has been disabled
|
|
614
|
+
automatically to avoid a Service Worker race that can leave the preview iframe
|
|
615
|
+
blank on cold story loads. Set \`lazyCompilation\` explicitly in your builder
|
|
616
|
+
options to override.
|
|
617
|
+
`)) : lazyCompilationConfig = {
|
|
618
|
+
entries: !1
|
|
619
|
+
}), {
|
|
620
|
+
lazyCompilationConfig,
|
|
621
|
+
isLazyCompilationActive: lazyCompilationConfig !== void 0 && lazyCompilationConfig !== !1
|
|
622
|
+
};
|
|
574
623
|
}, iframe_rsbuild_config_default = async (options, extraWebpackConfig) => {
|
|
575
|
-
let { rsbuildConfigPath, addonDocs } = await
|
|
624
|
+
let { rsbuildConfigPath, addonDocs } = await getBuilderOptions(options), webpackConfigFromPresets = await options.presets.apply("webpack", {}, options);
|
|
576
625
|
addonDocs && console.warn(
|
|
577
626
|
"`addonDocs` option is deprecated and will be removed in future versions. Please use `@storybook/addon-docs` option instead."
|
|
578
627
|
);
|
|
@@ -618,16 +667,12 @@ var require2 = createRequire(import.meta.url), getAbsolutePath = (input) => {
|
|
|
618
667
|
]), stories = normalizeStories2(nonNormalizedStories, {
|
|
619
668
|
configDir: options.configDir,
|
|
620
669
|
workingDir
|
|
621
|
-
}), shouldCheckTs = typescriptOptions.check && !typescriptOptions.skipCompiler, tsCheckOptions = typescriptOptions.checkOptions || {}, builderOptions = await
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
`)) : lazyCompilationConfig = {
|
|
628
|
-
entries: !1
|
|
629
|
-
});
|
|
630
|
-
let shouldDisableHmr = shouldDisableDevFeatures;
|
|
670
|
+
}), shouldCheckTs = typescriptOptions.check && !typescriptOptions.skipCompiler, tsCheckOptions = typescriptOptions.checkOptions || {}, builderOptions = await getBuilderOptions(options), cacheConfig = builderOptions.fsCache ? !0 : void 0, shouldDisableDevFeatures = process.env.SB_RSBUILD_TEST_MINIMAL_DEV === "true", { lazyCompilationConfig, isLazyCompilationActive } = await resolveLazyCompilation(
|
|
671
|
+
options,
|
|
672
|
+
builderOptions,
|
|
673
|
+
isProd,
|
|
674
|
+
shouldDisableDevFeatures
|
|
675
|
+
), shouldDisableHmr = shouldDisableDevFeatures;
|
|
631
676
|
if (!template)
|
|
632
677
|
throw new Error(dedent2`
|
|
633
678
|
Storybook's Webpack5 builder requires a template to be specified.
|
|
@@ -637,7 +682,7 @@ var require2 = createRequire(import.meta.url), getAbsolutePath = (input) => {
|
|
|
637
682
|
`);
|
|
638
683
|
let externals = globalsNameReferenceMap;
|
|
639
684
|
build2?.test?.disableBlocks && (externals["@storybook/addon-docs/blocks"] = "__STORYBOOK_BLOCKS_EMPTY_MODULE__");
|
|
640
|
-
let { virtualModules: virtualModuleMapping, entries: dynamicEntries } = await getVirtualModules(options), contentFromConfig = {}, { content } = await loadConfig({
|
|
685
|
+
let { virtualModules: virtualModuleMapping, entries: dynamicEntries } = await getVirtualModules(options, isLazyCompilationActive), contentFromConfig = {}, { content } = await loadConfig({
|
|
641
686
|
cwd: workingDir,
|
|
642
687
|
path: rsbuildConfigPath
|
|
643
688
|
}), { environments, ...withoutEnv } = content;
|
|
@@ -668,6 +713,7 @@ var require2 = createRequire(import.meta.url), getAbsolutePath = (input) => {
|
|
|
668
713
|
}
|
|
669
714
|
} else
|
|
670
715
|
contentFromConfig = content;
|
|
716
|
+
stripInheritedConfig(contentFromConfig, "the loaded Rsbuild config");
|
|
671
717
|
let resourceFilename = isProd ? "static/media/[name].[contenthash:8][ext]" : "static/media/[path][name][ext]", rsbuildConfig = mergeRsbuildConfig(contentFromConfig, {
|
|
672
718
|
output: {
|
|
673
719
|
cleanDistPath: !1,
|
|
@@ -1036,5 +1082,6 @@ export {
|
|
|
1036
1082
|
getVirtualModules,
|
|
1037
1083
|
previewMainTemplate,
|
|
1038
1084
|
printDuration,
|
|
1039
|
-
start
|
|
1085
|
+
start,
|
|
1086
|
+
stripInheritedConfig
|
|
1040
1087
|
};
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
1
|
+
import CJS_COMPAT_NODE_URL_b90b3490f755cd30 from 'node:url';
|
|
2
|
+
import CJS_COMPAT_NODE_PATH_b90b3490f755cd30 from 'node:path';
|
|
3
|
+
import CJS_COMPAT_NODE_MODULE_b90b3490f755cd30 from "node:module";
|
|
4
4
|
|
|
5
|
-
var __filename =
|
|
6
|
-
var __dirname =
|
|
7
|
-
var require =
|
|
5
|
+
var __filename = CJS_COMPAT_NODE_URL_b90b3490f755cd30.fileURLToPath(import.meta.url);
|
|
6
|
+
var __dirname = CJS_COMPAT_NODE_PATH_b90b3490f755cd30.dirname(__filename);
|
|
7
|
+
var require = CJS_COMPAT_NODE_MODULE_b90b3490f755cd30.createRequire(import.meta.url);
|
|
8
8
|
|
|
9
9
|
// ------------------------------------------------------------
|
|
10
10
|
// end of CJS compatibility banner, injected by Storybook's esbuild configuration
|
|
11
11
|
// ------------------------------------------------------------
|
|
12
|
-
import "../_node-chunks/chunk-
|
|
12
|
+
import "../_node-chunks/chunk-QCILEEJ4.js";
|
|
13
13
|
|
|
14
14
|
// src/loaders/export-order-loader.ts
|
|
15
15
|
import assert from "node:assert";
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
1
|
+
import CJS_COMPAT_NODE_URL_b90b3490f755cd30 from 'node:url';
|
|
2
|
+
import CJS_COMPAT_NODE_PATH_b90b3490f755cd30 from 'node:path';
|
|
3
|
+
import CJS_COMPAT_NODE_MODULE_b90b3490f755cd30 from "node:module";
|
|
4
4
|
|
|
5
|
-
var __filename =
|
|
6
|
-
var __dirname =
|
|
7
|
-
var require =
|
|
5
|
+
var __filename = CJS_COMPAT_NODE_URL_b90b3490f755cd30.fileURLToPath(import.meta.url);
|
|
6
|
+
var __dirname = CJS_COMPAT_NODE_PATH_b90b3490f755cd30.dirname(__filename);
|
|
7
|
+
var require = CJS_COMPAT_NODE_MODULE_b90b3490f755cd30.createRequire(import.meta.url);
|
|
8
8
|
|
|
9
9
|
// ------------------------------------------------------------
|
|
10
10
|
// end of CJS compatibility banner, injected by Storybook's esbuild configuration
|
|
11
11
|
// ------------------------------------------------------------
|
|
12
|
-
import "../_node-chunks/chunk-
|
|
12
|
+
import "../_node-chunks/chunk-QCILEEJ4.js";
|
|
13
13
|
|
|
14
14
|
// src/loaders/rsbuild-automock-loader.ts
|
|
15
15
|
import { babelParser, getAutomockCode } from "storybook/internal/mocking-utils";
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
1
|
+
import CJS_COMPAT_NODE_URL_b90b3490f755cd30 from 'node:url';
|
|
2
|
+
import CJS_COMPAT_NODE_PATH_b90b3490f755cd30 from 'node:path';
|
|
3
|
+
import CJS_COMPAT_NODE_MODULE_b90b3490f755cd30 from "node:module";
|
|
4
4
|
|
|
5
|
-
var __filename =
|
|
6
|
-
var __dirname =
|
|
7
|
-
var require =
|
|
5
|
+
var __filename = CJS_COMPAT_NODE_URL_b90b3490f755cd30.fileURLToPath(import.meta.url);
|
|
6
|
+
var __dirname = CJS_COMPAT_NODE_PATH_b90b3490f755cd30.dirname(__filename);
|
|
7
|
+
var require = CJS_COMPAT_NODE_MODULE_b90b3490f755cd30.createRequire(import.meta.url);
|
|
8
8
|
|
|
9
9
|
// ------------------------------------------------------------
|
|
10
10
|
// end of CJS compatibility banner, injected by Storybook's esbuild configuration
|
|
11
11
|
// ------------------------------------------------------------
|
|
12
|
-
import "../_node-chunks/chunk-
|
|
12
|
+
import "../_node-chunks/chunk-QCILEEJ4.js";
|
|
13
13
|
|
|
14
14
|
// src/loaders/storybook-mock-transform-loader.ts
|
|
15
15
|
import { rewriteSbMockImportCalls } from "storybook/internal/mocking-utils";
|
package/dist/preview-preset.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
1
|
+
import CJS_COMPAT_NODE_URL_b90b3490f755cd30 from 'node:url';
|
|
2
|
+
import CJS_COMPAT_NODE_PATH_b90b3490f755cd30 from 'node:path';
|
|
3
|
+
import CJS_COMPAT_NODE_MODULE_b90b3490f755cd30 from "node:module";
|
|
4
4
|
|
|
5
|
-
var __filename =
|
|
6
|
-
var __dirname =
|
|
7
|
-
var require =
|
|
5
|
+
var __filename = CJS_COMPAT_NODE_URL_b90b3490f755cd30.fileURLToPath(import.meta.url);
|
|
6
|
+
var __dirname = CJS_COMPAT_NODE_PATH_b90b3490f755cd30.dirname(__filename);
|
|
7
|
+
var require = CJS_COMPAT_NODE_MODULE_b90b3490f755cd30.createRequire(import.meta.url);
|
|
8
8
|
|
|
9
9
|
// ------------------------------------------------------------
|
|
10
10
|
// end of CJS compatibility banner, injected by Storybook's esbuild configuration
|
|
11
11
|
// ------------------------------------------------------------
|
|
12
|
-
import "./_node-chunks/chunk-
|
|
12
|
+
import "./_node-chunks/chunk-QCILEEJ4.js";
|
|
13
13
|
|
|
14
14
|
// src/preview-preset.ts
|
|
15
15
|
import { createRequire } from "node:module";
|
|
@@ -35,13 +35,13 @@ var PLUGIN_NAME = "RspackInjectMockerRuntimePlugin", RspackInjectMockerRuntimePl
|
|
|
35
35
|
}
|
|
36
36
|
}
|
|
37
37
|
apply(compiler) {
|
|
38
|
-
let HtmlPlugin = this.getHtmlPlugin(compiler);
|
|
39
|
-
if (
|
|
38
|
+
let HtmlPlugin = this.getHtmlPlugin(compiler), getHtmlHooks = HtmlPlugin?.getCompilationHooks ?? HtmlPlugin?.getHooks;
|
|
39
|
+
if (typeof getHtmlHooks != "function") {
|
|
40
40
|
compiler.getInfrastructureLogger(PLUGIN_NAME).warn("HTML plugin is not available. Cannot inject mocker runtime.");
|
|
41
41
|
return;
|
|
42
42
|
}
|
|
43
43
|
compiler.hooks.compilation.tap(PLUGIN_NAME, (compilation) => {
|
|
44
|
-
|
|
44
|
+
getHtmlHooks(compilation).beforeAssetTagGeneration.tapAsync(
|
|
45
45
|
PLUGIN_NAME,
|
|
46
46
|
(data, cb) => {
|
|
47
47
|
try {
|
|
@@ -50,10 +50,10 @@ var PLUGIN_NAME = "RspackInjectMockerRuntimePlugin", RspackInjectMockerRuntimePl
|
|
|
50
50
|
throw new Error(
|
|
51
51
|
"rspack sources is not available on compiler.webpack"
|
|
52
52
|
);
|
|
53
|
-
compilation.getAsset(runtimeAssetName) ||
|
|
53
|
+
compilation.getAsset(runtimeAssetName) || compilation.emitAsset(
|
|
54
54
|
runtimeAssetName,
|
|
55
55
|
new Sources.RawSource(runtimeScriptContent)
|
|
56
|
-
), data.assets.js.unshift(runtimeAssetName)
|
|
56
|
+
), data.assets.js.unshift(runtimeAssetName), cb(null, data);
|
|
57
57
|
} catch (error) {
|
|
58
58
|
cb(error);
|
|
59
59
|
}
|
|
@@ -66,7 +66,6 @@ var PLUGIN_NAME = "RspackInjectMockerRuntimePlugin", RspackInjectMockerRuntimePl
|
|
|
66
66
|
// src/plugins/rspack-mock-plugin.ts
|
|
67
67
|
import { dirname, isAbsolute } from "node:path";
|
|
68
68
|
import { fileURLToPath } from "node:url";
|
|
69
|
-
import { rspack } from "@rsbuild/core";
|
|
70
69
|
import { findMockRedirect } from "@vitest/mocker/redirect";
|
|
71
70
|
import {
|
|
72
71
|
babelParser,
|
|
@@ -100,7 +99,7 @@ var RspackMockPlugin = class {
|
|
|
100
99
|
])
|
|
101
100
|
), this.candidateSpecifiers = new Set(resolved.map((mock) => mock.path)), this.lastPreviewMtime = mTimePreviewConfig, resolved.length > 0 && logger.info(`Mock map updated with ${resolved.length} mocks.`);
|
|
102
101
|
};
|
|
103
|
-
compiler.hooks.beforeRun.tap(PLUGIN_NAME2, updateMocks), compiler.hooks.watchRun.tap(PLUGIN_NAME2, updateMocks), new
|
|
102
|
+
compiler.hooks.beforeRun.tap(PLUGIN_NAME2, updateMocks), compiler.hooks.watchRun.tap(PLUGIN_NAME2, updateMocks), new compiler.webpack.NormalModuleReplacementPlugin(/.*/, (resource) => {
|
|
104
103
|
try {
|
|
105
104
|
if (this.mockMap.size === 0)
|
|
106
105
|
return;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "storybook-builder-rsbuild",
|
|
3
|
-
"version": "3.4.
|
|
3
|
+
"version": "3.4.2",
|
|
4
4
|
"description": "Rsbuild builder for Storybook",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"storybook",
|
|
@@ -64,7 +64,7 @@
|
|
|
64
64
|
"util-deprecate": "^1.0.2"
|
|
65
65
|
},
|
|
66
66
|
"devDependencies": {
|
|
67
|
-
"@rsbuild/core": "^2.1.
|
|
67
|
+
"@rsbuild/core": "^2.1.10",
|
|
68
68
|
"@storybook/core-webpack": "10.5.5",
|
|
69
69
|
"@types/fs-extra": "^11.0.4",
|
|
70
70
|
"@types/node": "^22.0.0",
|