storybook-builder-rsbuild 2.1.5 → 3.0.0-beta.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/compiled/@storybook/core-webpack/index.d.ts +56 -0
- package/compiled/@storybook/core-webpack/index.js +360 -0
- package/compiled/@storybook/core-webpack/package.json +1 -0
- package/dist/_node-chunks/chunk-MIMCYZFR.js +45 -0
- package/dist/index.d.ts +3 -72
- package/dist/index.js +459 -406
- package/dist/loaders/export-order-loader.js +31 -52
- package/dist/preview-preset.js +17 -39
- package/package.json +18 -30
- package/dist/chunk-TTFRSOOU.mjs +0 -34
- package/dist/index.mjs +0 -667
- package/dist/loaders/export-order-loader.d.ts +0 -5
- package/dist/loaders/export-order-loader.mjs +0 -49
- package/dist/preview-preset.d.ts +0 -3
package/dist/index.mjs
DELETED
|
@@ -1,667 +0,0 @@
|
|
|
1
|
-
import { __commonJS, __toESM, __require } from './chunk-TTFRSOOU.mjs';
|
|
2
|
-
import { createServer } from 'net';
|
|
3
|
-
import { dirname, join, resolve, parse, isAbsolute } from 'path';
|
|
4
|
-
import * as rsbuildReal from '@rsbuild/core';
|
|
5
|
-
import { loadConfig, mergeRsbuildConfig } from '@rsbuild/core';
|
|
6
|
-
import fs from 'fs-extra';
|
|
7
|
-
import sirv from 'sirv';
|
|
8
|
-
import { getBuilderOptions, normalizeStories, loadPreviewOrConfigFile, readTemplate, resolveAddonName, getPresets, stringifyProcessEnvs, isPreservingSymlinks } from 'storybook/internal/common';
|
|
9
|
-
import { WebpackInvocationError } from 'storybook/internal/server-errors';
|
|
10
|
-
import { pluginTypeCheck } from '@rsbuild/plugin-type-check';
|
|
11
|
-
import { webpack } from '@storybook/addon-docs/preset';
|
|
12
|
-
import CaseSensitivePathsPlugin from 'case-sensitive-paths-webpack-plugin';
|
|
13
|
-
import { pluginHtmlMinifierTerser } from 'rsbuild-plugin-html-minifier-terser';
|
|
14
|
-
import { globalsNameReferenceMap } from 'storybook/internal/preview/globals';
|
|
15
|
-
import { dedent } from 'ts-dedent';
|
|
16
|
-
import { toImportFn } from '@storybook/core-webpack';
|
|
17
|
-
import { readFile } from 'fs/promises';
|
|
18
|
-
|
|
19
|
-
// ../../node_modules/.pnpm/pretty-hrtime@1.0.3/node_modules/pretty-hrtime/index.js
|
|
20
|
-
var require_pretty_hrtime = __commonJS({
|
|
21
|
-
"../../node_modules/.pnpm/pretty-hrtime@1.0.3/node_modules/pretty-hrtime/index.js"(exports, module) {
|
|
22
|
-
var minimalDesc = ["h", "min", "s", "ms", "\u03BCs", "ns"];
|
|
23
|
-
var verboseDesc = ["hour", "minute", "second", "millisecond", "microsecond", "nanosecond"];
|
|
24
|
-
var convert = [60 * 60, 60, 1, 1e6, 1e3, 1];
|
|
25
|
-
module.exports = function(source, opts) {
|
|
26
|
-
var verbose, precise, i, spot, sourceAtStep, valAtStep, decimals, strAtStep, results, totalSeconds;
|
|
27
|
-
verbose = false;
|
|
28
|
-
precise = false;
|
|
29
|
-
if (opts) {
|
|
30
|
-
verbose = opts.verbose || false;
|
|
31
|
-
precise = opts.precise || false;
|
|
32
|
-
}
|
|
33
|
-
if (!Array.isArray(source) || source.length !== 2) {
|
|
34
|
-
return "";
|
|
35
|
-
}
|
|
36
|
-
if (typeof source[0] !== "number" || typeof source[1] !== "number") {
|
|
37
|
-
return "";
|
|
38
|
-
}
|
|
39
|
-
if (source[1] < 0) {
|
|
40
|
-
totalSeconds = source[0] + source[1] / 1e9;
|
|
41
|
-
source[0] = parseInt(totalSeconds);
|
|
42
|
-
source[1] = parseFloat((totalSeconds % 1).toPrecision(9)) * 1e9;
|
|
43
|
-
}
|
|
44
|
-
results = "";
|
|
45
|
-
for (i = 0; i < 6; i++) {
|
|
46
|
-
spot = i < 3 ? 0 : 1;
|
|
47
|
-
sourceAtStep = source[spot];
|
|
48
|
-
if (i !== 3 && i !== 0) {
|
|
49
|
-
sourceAtStep = sourceAtStep % convert[i - 1];
|
|
50
|
-
}
|
|
51
|
-
if (i === 2) {
|
|
52
|
-
sourceAtStep += source[1] / 1e9;
|
|
53
|
-
}
|
|
54
|
-
valAtStep = sourceAtStep / convert[i];
|
|
55
|
-
if (valAtStep >= 1) {
|
|
56
|
-
if (verbose) {
|
|
57
|
-
valAtStep = Math.floor(valAtStep);
|
|
58
|
-
}
|
|
59
|
-
if (!precise) {
|
|
60
|
-
decimals = valAtStep >= 10 ? 0 : 2;
|
|
61
|
-
strAtStep = valAtStep.toFixed(decimals);
|
|
62
|
-
} else {
|
|
63
|
-
strAtStep = valAtStep.toString();
|
|
64
|
-
}
|
|
65
|
-
if (strAtStep.indexOf(".") > -1 && strAtStep[strAtStep.length - 1] === "0") {
|
|
66
|
-
strAtStep = strAtStep.replace(/\.?0+$/, "");
|
|
67
|
-
}
|
|
68
|
-
if (results) {
|
|
69
|
-
results += " ";
|
|
70
|
-
}
|
|
71
|
-
results += strAtStep;
|
|
72
|
-
if (verbose) {
|
|
73
|
-
results += " " + verboseDesc[i];
|
|
74
|
-
if (strAtStep !== "1") {
|
|
75
|
-
results += "s";
|
|
76
|
-
}
|
|
77
|
-
} else {
|
|
78
|
-
results += " " + minimalDesc[i];
|
|
79
|
-
}
|
|
80
|
-
if (!verbose) {
|
|
81
|
-
break;
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
return results;
|
|
86
|
-
};
|
|
87
|
-
}
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
// src/index.ts
|
|
91
|
-
var import_pretty_hrtime = __toESM(require_pretty_hrtime());
|
|
92
|
-
|
|
93
|
-
// ../../node_modules/.pnpm/slash@5.1.0/node_modules/slash/index.js
|
|
94
|
-
function slash(path) {
|
|
95
|
-
const isExtendedLengthPath = path.startsWith("\\\\?\\");
|
|
96
|
-
if (isExtendedLengthPath) {
|
|
97
|
-
return path;
|
|
98
|
-
}
|
|
99
|
-
return path.replace(/\\/g, "/");
|
|
100
|
-
}
|
|
101
|
-
var getVirtualModules = async (options) => {
|
|
102
|
-
const virtualModules = {};
|
|
103
|
-
const builderOptions = await getBuilderOptions(options);
|
|
104
|
-
const workingDir = process.cwd();
|
|
105
|
-
const isProd = options.configType === "PRODUCTION";
|
|
106
|
-
const nonNormalizedStories = await options.presets.apply("stories", []);
|
|
107
|
-
const entries = [];
|
|
108
|
-
const stories = normalizeStories(nonNormalizedStories, {
|
|
109
|
-
configDir: options.configDir,
|
|
110
|
-
workingDir
|
|
111
|
-
});
|
|
112
|
-
const previewAnnotations = [
|
|
113
|
-
...(await options.presets.apply(
|
|
114
|
-
"previewAnnotations",
|
|
115
|
-
[],
|
|
116
|
-
options
|
|
117
|
-
)).map((entry) => {
|
|
118
|
-
if (typeof entry === "object") {
|
|
119
|
-
return entry.absolute;
|
|
120
|
-
}
|
|
121
|
-
return slash(entry);
|
|
122
|
-
}),
|
|
123
|
-
loadPreviewOrConfigFile(options)
|
|
124
|
-
].filter(Boolean);
|
|
125
|
-
const storiesFilename = "storybook-stories.js";
|
|
126
|
-
const storiesPath = resolve(join(workingDir, storiesFilename));
|
|
127
|
-
const needPipelinedImport = !!builderOptions.lazyCompilation && !isProd;
|
|
128
|
-
virtualModules[storiesPath] = toImportFn(stories, {
|
|
129
|
-
needPipelinedImport
|
|
130
|
-
});
|
|
131
|
-
const configEntryPath = resolve(join(workingDir, "storybook-config-entry.js"));
|
|
132
|
-
virtualModules[configEntryPath] = (await readTemplate(
|
|
133
|
-
__require.resolve(
|
|
134
|
-
"storybook-builder-rsbuild/templates/virtualModuleModernEntry.js"
|
|
135
|
-
)
|
|
136
|
-
)).replaceAll(`'{{storiesFilename}}'`, `'./${storiesFilename}'`).replaceAll(
|
|
137
|
-
`'{{previewAnnotations}}'`,
|
|
138
|
-
previewAnnotations.filter(Boolean).map((entry) => `'${entry}'`).join(",")
|
|
139
|
-
).replaceAll(
|
|
140
|
-
`'{{previewAnnotations_requires}}'`,
|
|
141
|
-
previewAnnotations.filter(Boolean).map((entry) => `require('${entry}')`).join(",")
|
|
142
|
-
).replace(/\\/g, "\\\\");
|
|
143
|
-
entries.push(configEntryPath);
|
|
144
|
-
return {
|
|
145
|
-
virtualModules,
|
|
146
|
-
entries
|
|
147
|
-
};
|
|
148
|
-
};
|
|
149
|
-
|
|
150
|
-
// src/preview/iframe-rsbuild.config.ts
|
|
151
|
-
var getAbsolutePath = (input) => dirname(__require.resolve(join(input, "package.json")));
|
|
152
|
-
var maybeGetAbsolutePath = (input) => {
|
|
153
|
-
try {
|
|
154
|
-
return getAbsolutePath(input);
|
|
155
|
-
} catch (e) {
|
|
156
|
-
return false;
|
|
157
|
-
}
|
|
158
|
-
};
|
|
159
|
-
var builtInResolveExtensions = [
|
|
160
|
-
".mjs",
|
|
161
|
-
".js",
|
|
162
|
-
".jsx",
|
|
163
|
-
".ts",
|
|
164
|
-
".tsx",
|
|
165
|
-
".json",
|
|
166
|
-
".cjs"
|
|
167
|
-
];
|
|
168
|
-
var globalPath = maybeGetAbsolutePath("@storybook/global");
|
|
169
|
-
var storybookPaths = {
|
|
170
|
-
// biome-ignore lint/complexity/useLiteralKeys: <explanation>
|
|
171
|
-
...globalPath ? { ["@storybook/global"]: globalPath } : {}
|
|
172
|
-
};
|
|
173
|
-
var iframe_rsbuild_config_default = async (options, extraWebpackConfig) => {
|
|
174
|
-
const { rsbuildConfigPath, addonDocs } = await getBuilderOptions(options);
|
|
175
|
-
const appliedDocsWebpack = await webpack({}, { ...options, ...addonDocs });
|
|
176
|
-
const {
|
|
177
|
-
outputDir = join(".", "public"),
|
|
178
|
-
quiet,
|
|
179
|
-
packageJson,
|
|
180
|
-
configType,
|
|
181
|
-
presets,
|
|
182
|
-
previewUrl,
|
|
183
|
-
typescriptOptions,
|
|
184
|
-
features
|
|
185
|
-
} = options;
|
|
186
|
-
const isProd = configType === "PRODUCTION";
|
|
187
|
-
const workingDir = process.cwd();
|
|
188
|
-
const [
|
|
189
|
-
coreOptions,
|
|
190
|
-
frameworkOptions,
|
|
191
|
-
envs,
|
|
192
|
-
logLevel,
|
|
193
|
-
headHtmlSnippet,
|
|
194
|
-
bodyHtmlSnippet,
|
|
195
|
-
template,
|
|
196
|
-
docsOptions,
|
|
197
|
-
entries,
|
|
198
|
-
nonNormalizedStories,
|
|
199
|
-
_modulesCount,
|
|
200
|
-
build2,
|
|
201
|
-
tagsOptions
|
|
202
|
-
] = await Promise.all([
|
|
203
|
-
presets.apply("core"),
|
|
204
|
-
presets.apply("frameworkOptions"),
|
|
205
|
-
presets.apply("env"),
|
|
206
|
-
presets.apply("logLevel", void 0),
|
|
207
|
-
presets.apply("previewHead"),
|
|
208
|
-
presets.apply("previewBody"),
|
|
209
|
-
presets.apply("previewMainTemplate"),
|
|
210
|
-
presets.apply("docs"),
|
|
211
|
-
presets.apply("entries", []),
|
|
212
|
-
presets.apply("stories", []),
|
|
213
|
-
options.cache?.get("modulesCount", 1e3),
|
|
214
|
-
options.presets.apply("build"),
|
|
215
|
-
presets.apply("tags", {})
|
|
216
|
-
]);
|
|
217
|
-
const stories = normalizeStories(nonNormalizedStories, {
|
|
218
|
-
configDir: options.configDir,
|
|
219
|
-
workingDir
|
|
220
|
-
});
|
|
221
|
-
const shouldCheckTs = typescriptOptions.check && !typescriptOptions.skipCompiler;
|
|
222
|
-
const tsCheckOptions = typescriptOptions.checkOptions || {};
|
|
223
|
-
const builderOptions = await getBuilderOptions(options);
|
|
224
|
-
const cacheConfig = builderOptions.fsCache ? true : void 0;
|
|
225
|
-
const lazyCompilationConfig = builderOptions.lazyCompilation && !isProd ? {
|
|
226
|
-
lazyCompilation: { entries: false }
|
|
227
|
-
} : {};
|
|
228
|
-
if (!template) {
|
|
229
|
-
throw new Error(dedent`
|
|
230
|
-
Storybook's Webpack5 builder requires a template to be specified.
|
|
231
|
-
Somehow you've ended up with a falsy value for the template option.
|
|
232
|
-
|
|
233
|
-
Please file an issue at https://github.com/storybookjs/storybook with a reproduction.
|
|
234
|
-
`);
|
|
235
|
-
}
|
|
236
|
-
const externals = globalsNameReferenceMap;
|
|
237
|
-
if (build2?.test?.disableBlocks) {
|
|
238
|
-
externals["@storybook/blocks"] = "__STORYBOOK_BLOCKS_EMPTY_MODULE__";
|
|
239
|
-
}
|
|
240
|
-
const { virtualModules: virtualModuleMapping, entries: dynamicEntries } = await getVirtualModules(options);
|
|
241
|
-
if (!options.cache) {
|
|
242
|
-
throw new Error("Cache is required");
|
|
243
|
-
}
|
|
244
|
-
let contentFromConfig = {};
|
|
245
|
-
const { content } = await loadConfig({
|
|
246
|
-
cwd: workingDir,
|
|
247
|
-
path: rsbuildConfigPath
|
|
248
|
-
});
|
|
249
|
-
const { environments, ...withoutEnv } = content;
|
|
250
|
-
if (content.environments) {
|
|
251
|
-
const envCount = Object.keys(content.environments).length;
|
|
252
|
-
if (envCount === 0) {
|
|
253
|
-
contentFromConfig = withoutEnv;
|
|
254
|
-
} else if (envCount === 1) {
|
|
255
|
-
contentFromConfig = mergeRsbuildConfig(
|
|
256
|
-
withoutEnv,
|
|
257
|
-
content.environments[0]
|
|
258
|
-
);
|
|
259
|
-
} else {
|
|
260
|
-
const userEnv = builderOptions.environment;
|
|
261
|
-
if (typeof userEnv !== "string") {
|
|
262
|
-
throw new Error(
|
|
263
|
-
"You must specify an environment when there are multiple environments in the Rsbuild config."
|
|
264
|
-
);
|
|
265
|
-
}
|
|
266
|
-
if (Object.keys(content.environments).includes(userEnv)) {
|
|
267
|
-
contentFromConfig = mergeRsbuildConfig(
|
|
268
|
-
withoutEnv,
|
|
269
|
-
content.environments[userEnv]
|
|
270
|
-
);
|
|
271
|
-
} else {
|
|
272
|
-
throw new Error(
|
|
273
|
-
`The specified environment "${userEnv}" is not found in the Rsbuild config.`
|
|
274
|
-
);
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
|
-
} else {
|
|
278
|
-
contentFromConfig = content;
|
|
279
|
-
}
|
|
280
|
-
const resourceFilename = isProd ? "static/media/[name].[contenthash:8][ext]" : "static/media/[path][name][ext]";
|
|
281
|
-
const rsbuildConfig = mergeRsbuildConfig(contentFromConfig, {
|
|
282
|
-
output: {
|
|
283
|
-
cleanDistPath: false,
|
|
284
|
-
assetPrefix: "/",
|
|
285
|
-
dataUriLimit: {
|
|
286
|
-
media: 1e4
|
|
287
|
-
},
|
|
288
|
-
sourceMap: {
|
|
289
|
-
js: options.build?.test?.disableSourcemaps ? false : "cheap-module-source-map",
|
|
290
|
-
css: !options.build?.test?.disableSourcemaps
|
|
291
|
-
},
|
|
292
|
-
distPath: {
|
|
293
|
-
root: resolve(process.cwd(), outputDir)
|
|
294
|
-
},
|
|
295
|
-
filename: {
|
|
296
|
-
js: isProd ? "[name].[contenthash:8].iframe.bundle.js" : "[name].iframe.bundle.js",
|
|
297
|
-
image: resourceFilename,
|
|
298
|
-
font: resourceFilename,
|
|
299
|
-
media: resourceFilename
|
|
300
|
-
},
|
|
301
|
-
externals
|
|
302
|
-
},
|
|
303
|
-
server: {
|
|
304
|
-
// Storybook will handle public directory itself, disable Rsbuild's public dir
|
|
305
|
-
// feature to prevent overwriting Storybook's public directory.
|
|
306
|
-
publicDir: false
|
|
307
|
-
},
|
|
308
|
-
dev: {
|
|
309
|
-
assetPrefix: "/",
|
|
310
|
-
progressBar: !quiet
|
|
311
|
-
},
|
|
312
|
-
resolve: {
|
|
313
|
-
alias: {
|
|
314
|
-
...storybookPaths
|
|
315
|
-
}
|
|
316
|
-
},
|
|
317
|
-
source: {
|
|
318
|
-
define: {
|
|
319
|
-
...stringifyProcessEnvs(envs),
|
|
320
|
-
NODE_ENV: JSON.stringify(process.env.NODE_ENV)
|
|
321
|
-
}
|
|
322
|
-
},
|
|
323
|
-
performance: {
|
|
324
|
-
chunkSplit: {
|
|
325
|
-
strategy: "custom",
|
|
326
|
-
splitChunks: {
|
|
327
|
-
chunks: "all"
|
|
328
|
-
}
|
|
329
|
-
},
|
|
330
|
-
buildCache: cacheConfig
|
|
331
|
-
},
|
|
332
|
-
plugins: [
|
|
333
|
-
shouldCheckTs ? pluginTypeCheck(tsCheckOptions) : null,
|
|
334
|
-
pluginHtmlMinifierTerser(() => ({
|
|
335
|
-
collapseWhitespace: true,
|
|
336
|
-
removeComments: true,
|
|
337
|
-
removeRedundantAttributes: true,
|
|
338
|
-
removeScriptTypeAttributes: false,
|
|
339
|
-
removeStyleLinkTypeAttributes: true,
|
|
340
|
-
useShortDoctype: true
|
|
341
|
-
}))
|
|
342
|
-
].filter(Boolean),
|
|
343
|
-
tools: {
|
|
344
|
-
rspack: (config, { addRules, rspack: rspack2, mergeConfig }) => {
|
|
345
|
-
addRules({
|
|
346
|
-
test: /\.stories\.([tj])sx?$|(stories|story)\.mdx$/,
|
|
347
|
-
exclude: /node_modules/,
|
|
348
|
-
enforce: "post",
|
|
349
|
-
use: [
|
|
350
|
-
{
|
|
351
|
-
loader: __require.resolve(
|
|
352
|
-
"storybook-builder-rsbuild/loaders/export-order-loader"
|
|
353
|
-
)
|
|
354
|
-
}
|
|
355
|
-
]
|
|
356
|
-
});
|
|
357
|
-
config.module ??= {};
|
|
358
|
-
config.module.parser ??= {};
|
|
359
|
-
config.module.parser.javascript ??= {};
|
|
360
|
-
config.module.parser.javascript.unknownContextCritical = false;
|
|
361
|
-
config.resolve ??= {};
|
|
362
|
-
config.resolve.symlinks = !isPreservingSymlinks();
|
|
363
|
-
config.resolve.extensions = Array.from(
|
|
364
|
-
/* @__PURE__ */ new Set([
|
|
365
|
-
...config.resolve.extensions ?? [],
|
|
366
|
-
...builtInResolveExtensions
|
|
367
|
-
])
|
|
368
|
-
);
|
|
369
|
-
config.watchOptions = {
|
|
370
|
-
ignored: /node_modules/
|
|
371
|
-
};
|
|
372
|
-
config.ignoreWarnings = [
|
|
373
|
-
...config.ignoreWarnings || [],
|
|
374
|
-
/export '\S+' was not found in 'global'/,
|
|
375
|
-
/export '\S+' was not found in '@storybook\/global'/
|
|
376
|
-
];
|
|
377
|
-
config.resolve ??= {};
|
|
378
|
-
config.resolve.fallback ??= {
|
|
379
|
-
stream: false,
|
|
380
|
-
path: __require.resolve("path-browserify"),
|
|
381
|
-
assert: __require.resolve("browser-assert"),
|
|
382
|
-
util: __require.resolve("util"),
|
|
383
|
-
url: __require.resolve("url"),
|
|
384
|
-
fs: false,
|
|
385
|
-
constants: __require.resolve("constants-browserify")
|
|
386
|
-
};
|
|
387
|
-
config.optimization ??= {};
|
|
388
|
-
config.optimization.runtimeChunk = true;
|
|
389
|
-
config.optimization.usedExports = options.build?.test?.disableTreeShaking ? false : isProd;
|
|
390
|
-
config.optimization.moduleIds = "named";
|
|
391
|
-
config.module ??= {};
|
|
392
|
-
config.module.parser ??= {};
|
|
393
|
-
config.module.parser.javascript ??= {};
|
|
394
|
-
config.module.parser.javascript.exportsPresence = false;
|
|
395
|
-
if (!rspack2.experiments?.VirtualModulesPlugin) {
|
|
396
|
-
throw new Error(
|
|
397
|
-
"rspack.experiments.VirtualModulesPlugin requires at least 1.5.0 version of @rsbuild/core, please upgrade or downgrade storybook-rsbuild-builder to lower version."
|
|
398
|
-
);
|
|
399
|
-
}
|
|
400
|
-
config.plugins ??= [];
|
|
401
|
-
config.plugins.push(
|
|
402
|
-
...[
|
|
403
|
-
Object.keys(virtualModuleMapping).length > 0 ? new rspack2.experiments.VirtualModulesPlugin(
|
|
404
|
-
virtualModuleMapping
|
|
405
|
-
) : null,
|
|
406
|
-
new rspack2.ProvidePlugin({
|
|
407
|
-
process: __require.resolve("process/browser.js")
|
|
408
|
-
}),
|
|
409
|
-
new CaseSensitivePathsPlugin()
|
|
410
|
-
].filter(Boolean)
|
|
411
|
-
);
|
|
412
|
-
config.experiments ??= {};
|
|
413
|
-
config.experiments.outputModule = false;
|
|
414
|
-
config.externalsType = "var";
|
|
415
|
-
config.output ??= {};
|
|
416
|
-
config.output.module = false;
|
|
417
|
-
config.output.chunkFormat = "array-push";
|
|
418
|
-
config.output.chunkLoading = "jsonp";
|
|
419
|
-
config.experiments = {
|
|
420
|
-
...config.experiments,
|
|
421
|
-
...lazyCompilationConfig
|
|
422
|
-
};
|
|
423
|
-
return mergeConfig(config, extraWebpackConfig || {}, appliedDocsWebpack);
|
|
424
|
-
},
|
|
425
|
-
htmlPlugin: {
|
|
426
|
-
filename: "iframe.html",
|
|
427
|
-
// FIXME: `none` isn't a known option
|
|
428
|
-
chunksSortMode: "none",
|
|
429
|
-
alwaysWriteToDisk: true,
|
|
430
|
-
inject: false,
|
|
431
|
-
template,
|
|
432
|
-
templateParameters: {
|
|
433
|
-
version: packageJson?.version ?? "0.0.0-storybook-rsbuild-unknown-version",
|
|
434
|
-
globals: {
|
|
435
|
-
CONFIG_TYPE: configType,
|
|
436
|
-
LOGLEVEL: logLevel,
|
|
437
|
-
FRAMEWORK_OPTIONS: frameworkOptions,
|
|
438
|
-
CHANNEL_OPTIONS: coreOptions.channelOptions,
|
|
439
|
-
FEATURES: features,
|
|
440
|
-
PREVIEW_URL: previewUrl,
|
|
441
|
-
STORIES: stories.map((specifier) => ({
|
|
442
|
-
...specifier,
|
|
443
|
-
importPathMatcher: specifier.importPathMatcher.source
|
|
444
|
-
})),
|
|
445
|
-
DOCS_OPTIONS: docsOptions,
|
|
446
|
-
TAGS_OPTIONS: tagsOptions,
|
|
447
|
-
...build2?.test?.disableBlocks ? { __STORYBOOK_BLOCKS_EMPTY_MODULE__: {} } : {}
|
|
448
|
-
},
|
|
449
|
-
headHtmlSnippet,
|
|
450
|
-
bodyHtmlSnippet
|
|
451
|
-
}
|
|
452
|
-
}
|
|
453
|
-
}
|
|
454
|
-
});
|
|
455
|
-
rsbuildConfig.source ??= {};
|
|
456
|
-
rsbuildConfig.source.entry = {
|
|
457
|
-
main: [...entries ?? [], ...dynamicEntries]
|
|
458
|
-
};
|
|
459
|
-
return rsbuildConfig;
|
|
460
|
-
};
|
|
461
|
-
var getIsReactVersion18or19 = async (options) => {
|
|
462
|
-
const { legacyRootApi } = await options.presets.apply(
|
|
463
|
-
"frameworkOptions"
|
|
464
|
-
) || {};
|
|
465
|
-
if (legacyRootApi) {
|
|
466
|
-
return false;
|
|
467
|
-
}
|
|
468
|
-
const resolvedReact = await options.presets.apply(
|
|
469
|
-
"resolvedReact",
|
|
470
|
-
{}
|
|
471
|
-
);
|
|
472
|
-
let reactDom = "";
|
|
473
|
-
reactDom = resolvedReact.reactDom || dirname(__require.resolve("react-dom/package.json"));
|
|
474
|
-
if (!isAbsolute(reactDom)) {
|
|
475
|
-
return false;
|
|
476
|
-
}
|
|
477
|
-
const { version } = JSON.parse(
|
|
478
|
-
await readFile(join(reactDom, "package.json"), "utf-8")
|
|
479
|
-
);
|
|
480
|
-
return version.startsWith("18") || version.startsWith("19") || version.startsWith("0.0.0");
|
|
481
|
-
};
|
|
482
|
-
var applyReactShims = async (config, options) => {
|
|
483
|
-
const isReactVersion18 = await getIsReactVersion18or19(options);
|
|
484
|
-
if (isReactVersion18) {
|
|
485
|
-
return {};
|
|
486
|
-
}
|
|
487
|
-
return {
|
|
488
|
-
resolve: {
|
|
489
|
-
alias: {
|
|
490
|
-
"@storybook/react-dom-shim": "@storybook/react-dom-shim/dist/react-16"
|
|
491
|
-
}
|
|
492
|
-
}
|
|
493
|
-
};
|
|
494
|
-
};
|
|
495
|
-
|
|
496
|
-
// src/index.ts
|
|
497
|
-
var corePath = dirname(__require.resolve("storybook/package.json"));
|
|
498
|
-
var printDuration = (startTime) => (0, import_pretty_hrtime.default)(process.hrtime(startTime)).replace(" ms", " milliseconds").replace(" s", " seconds").replace(" m", " minutes");
|
|
499
|
-
var executor = {
|
|
500
|
-
get: async (options) => {
|
|
501
|
-
const rsbuildInstance = await options.presets.apply("rsbuildInstance") || rsbuildReal;
|
|
502
|
-
return rsbuildInstance;
|
|
503
|
-
}
|
|
504
|
-
};
|
|
505
|
-
var isObject = (val) => val != null && typeof val === "object" && Array.isArray(val) === false;
|
|
506
|
-
function nonNullables(value) {
|
|
507
|
-
return value !== void 0;
|
|
508
|
-
}
|
|
509
|
-
var rsbuild = async (_, options) => {
|
|
510
|
-
const { presets } = options;
|
|
511
|
-
const webpackAddons = await presets.apply("webpackAddons");
|
|
512
|
-
const resolvedWebpackAddons = (webpackAddons ?? []).map((preset) => {
|
|
513
|
-
const addonOptions = isObject(preset) ? preset.options || void 0 : void 0;
|
|
514
|
-
const name = isObject(preset) ? preset.name : preset;
|
|
515
|
-
return resolveAddonName(options.configDir, name, addonOptions);
|
|
516
|
-
}).filter(nonNullables);
|
|
517
|
-
const { apply } = await getPresets(resolvedWebpackAddons, options);
|
|
518
|
-
const webpackAddonsConfig = await apply(
|
|
519
|
-
"webpackFinal",
|
|
520
|
-
// TODO: using empty webpack config as base for now. It's better to using the composed rspack
|
|
521
|
-
// config in `iframe-rsbuild.config.ts` as base config. But when `tools.rspack` is an async function,
|
|
522
|
-
// the following `tools.rspack` raise an `Promises are not supported` error.
|
|
523
|
-
{
|
|
524
|
-
output: {},
|
|
525
|
-
module: {},
|
|
526
|
-
plugins: [],
|
|
527
|
-
resolve: {},
|
|
528
|
-
// https://github.com/web-infra-dev/rsbuild/blob/8dc35dc1d1500d2f119875d46b6a07e27986d532/packages/core/src/provider/rspackConfig.ts#L167
|
|
529
|
-
devServer: void 0,
|
|
530
|
-
optimization: {},
|
|
531
|
-
performance: {},
|
|
532
|
-
externals: {},
|
|
533
|
-
experiments: {},
|
|
534
|
-
node: {},
|
|
535
|
-
stats: {},
|
|
536
|
-
entry: {}
|
|
537
|
-
},
|
|
538
|
-
options
|
|
539
|
-
);
|
|
540
|
-
let intrinsicRsbuildConfig = await iframe_rsbuild_config_default(options, webpackAddonsConfig);
|
|
541
|
-
const shimsConfig = await applyReactShims(intrinsicRsbuildConfig, options);
|
|
542
|
-
intrinsicRsbuildConfig = rsbuildReal.mergeRsbuildConfig(
|
|
543
|
-
intrinsicRsbuildConfig,
|
|
544
|
-
shimsConfig
|
|
545
|
-
);
|
|
546
|
-
const finalConfig = await presets.apply(
|
|
547
|
-
"rsbuildFinal",
|
|
548
|
-
intrinsicRsbuildConfig,
|
|
549
|
-
options
|
|
550
|
-
);
|
|
551
|
-
return finalConfig;
|
|
552
|
-
};
|
|
553
|
-
var getConfig = async (options) => {
|
|
554
|
-
const { presets } = options;
|
|
555
|
-
const typescriptOptions = await presets.apply("typescript", {}, options);
|
|
556
|
-
const frameworkOptions = await presets.apply("frameworkOptions");
|
|
557
|
-
return rsbuild({}, {
|
|
558
|
-
...options,
|
|
559
|
-
typescriptOptions,
|
|
560
|
-
frameworkOptions
|
|
561
|
-
});
|
|
562
|
-
};
|
|
563
|
-
var server;
|
|
564
|
-
async function bail() {
|
|
565
|
-
return server?.close();
|
|
566
|
-
}
|
|
567
|
-
var start = async ({
|
|
568
|
-
startTime,
|
|
569
|
-
options,
|
|
570
|
-
router,
|
|
571
|
-
server: storybookServer,
|
|
572
|
-
channel
|
|
573
|
-
}) => {
|
|
574
|
-
const { createRsbuild } = await executor.get(options);
|
|
575
|
-
const config = await getConfig(options);
|
|
576
|
-
const rsbuildBuild = await createRsbuild({
|
|
577
|
-
cwd: process.cwd(),
|
|
578
|
-
rsbuildConfig: {
|
|
579
|
-
...config,
|
|
580
|
-
server: {
|
|
581
|
-
...config.server,
|
|
582
|
-
port: await getRandomPort(options.host),
|
|
583
|
-
host: options.host,
|
|
584
|
-
htmlFallback: false,
|
|
585
|
-
printUrls: false
|
|
586
|
-
}
|
|
587
|
-
}
|
|
588
|
-
});
|
|
589
|
-
const rsbuildServer = await rsbuildBuild.createDevServer();
|
|
590
|
-
const waitFirstCompileDone = new Promise((resolve3) => {
|
|
591
|
-
rsbuildBuild.onDevCompileDone(({ stats: stats2, isFirstCompile }) => {
|
|
592
|
-
if (!isFirstCompile) {
|
|
593
|
-
return;
|
|
594
|
-
}
|
|
595
|
-
resolve3(stats2);
|
|
596
|
-
});
|
|
597
|
-
});
|
|
598
|
-
server = rsbuildServer;
|
|
599
|
-
if (!rsbuildBuild) {
|
|
600
|
-
throw new WebpackInvocationError({
|
|
601
|
-
// eslint-disable-next-line local-rules/no-uncategorized-errors
|
|
602
|
-
error: new Error("Missing Rsbuild build instance at runtime!")
|
|
603
|
-
});
|
|
604
|
-
}
|
|
605
|
-
const previewResolvedDir = join(corePath, "dist/preview");
|
|
606
|
-
const previewDirOrigin = previewResolvedDir;
|
|
607
|
-
router.use(
|
|
608
|
-
"/sb-preview",
|
|
609
|
-
sirv(previewDirOrigin, { maxAge: 3e5, dev: true, immutable: true })
|
|
610
|
-
);
|
|
611
|
-
router.use(rsbuildServer.middlewares);
|
|
612
|
-
rsbuildServer.connectWebSocket({ server: storybookServer });
|
|
613
|
-
const stats = await waitFirstCompileDone;
|
|
614
|
-
await server.afterListen();
|
|
615
|
-
return {
|
|
616
|
-
bail,
|
|
617
|
-
stats,
|
|
618
|
-
totalTime: process.hrtime(startTime)
|
|
619
|
-
};
|
|
620
|
-
};
|
|
621
|
-
var build = async ({ options }) => {
|
|
622
|
-
const { createRsbuild } = await executor.get(options);
|
|
623
|
-
const config = await getConfig(options);
|
|
624
|
-
const rsbuildBuild = await createRsbuild({
|
|
625
|
-
cwd: process.cwd(),
|
|
626
|
-
rsbuildConfig: config
|
|
627
|
-
});
|
|
628
|
-
const previewResolvedDir = join(corePath, "dist/preview");
|
|
629
|
-
const previewDirOrigin = previewResolvedDir;
|
|
630
|
-
const previewDirTarget = join(options.outputDir || "", "sb-preview");
|
|
631
|
-
let stats;
|
|
632
|
-
rsbuildBuild.onAfterBuild((params) => {
|
|
633
|
-
stats = params.stats;
|
|
634
|
-
});
|
|
635
|
-
const previewFiles = fs.copy(previewDirOrigin, previewDirTarget, {
|
|
636
|
-
filter: (src) => {
|
|
637
|
-
const { ext } = parse(src);
|
|
638
|
-
if (ext) {
|
|
639
|
-
return ext === ".js";
|
|
640
|
-
}
|
|
641
|
-
return true;
|
|
642
|
-
}
|
|
643
|
-
});
|
|
644
|
-
rsbuildBuild.onAfterBuild((params) => {
|
|
645
|
-
stats = params.stats;
|
|
646
|
-
});
|
|
647
|
-
const [{ close }] = await Promise.all([rsbuildBuild.build(), previewFiles]);
|
|
648
|
-
await close();
|
|
649
|
-
return stats;
|
|
650
|
-
};
|
|
651
|
-
var corePresets = [join(__dirname, "./preview-preset.js")];
|
|
652
|
-
var previewMainTemplate = () => __require.resolve("storybook-builder-rsbuild/templates/preview.ejs");
|
|
653
|
-
function getRandomPort(host) {
|
|
654
|
-
return new Promise((resolve3, reject) => {
|
|
655
|
-
const server2 = createServer();
|
|
656
|
-
server2.unref();
|
|
657
|
-
server2.on("error", reject);
|
|
658
|
-
server2.listen({ port: 0, host }, () => {
|
|
659
|
-
const { port } = server2.address();
|
|
660
|
-
server2.close(() => {
|
|
661
|
-
resolve3(port);
|
|
662
|
-
});
|
|
663
|
-
});
|
|
664
|
-
});
|
|
665
|
-
}
|
|
666
|
-
|
|
667
|
-
export { bail, build, corePresets, executor, getConfig, getVirtualModules, previewMainTemplate, printDuration, start };
|