storybook-builder-rsbuild 0.0.1-beta.0
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/LICENSE +21 -0
- package/README.md +11 -0
- package/dist/chunk-TTFRSOOU.mjs +34 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +627 -0
- package/dist/index.mjs +554 -0
- package/dist/loaders/export-order-loader.d.ts +2 -0
- package/dist/loaders/export-order-loader.js +72 -0
- package/dist/loaders/export-order-loader.mjs +41 -0
- package/dist/presets/custom-rsbuild-preset.d.ts +2 -0
- package/dist/presets/custom-rsbuild-preset.js +56 -0
- package/dist/presets/preview-preset.d.ts +2 -0
- package/dist/presets/preview-preset.js +427 -0
- package/dist/preview-preset.d.ts +2 -0
- package/dist/preview-preset.js +42 -0
- package/package.json +112 -0
- package/templates/preview.ejs +54 -0
- package/templates/virtualModuleModernEntry.js.handlebars +34 -0
- package/typings.d.ts +2 -0
package/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2024 fi3ework
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
# Builder-Webpack5
|
2
|
+
|
3
|
+
Builder implemented with `webpack5` and `webpack5`-compatible loaders/plugins/config, used by `@storybook/core-server` to build the preview iframe.
|
4
|
+
|
5
|
+
```js
|
6
|
+
export default {
|
7
|
+
core: {
|
8
|
+
builder: '@storybook/builder-webpack5',
|
9
|
+
},
|
10
|
+
};
|
11
|
+
```
|
@@ -0,0 +1,34 @@
|
|
1
|
+
var __create = Object.create;
|
2
|
+
var __defProp = Object.defineProperty;
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
7
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
8
|
+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
9
|
+
}) : x)(function(x) {
|
10
|
+
if (typeof require !== "undefined")
|
11
|
+
return require.apply(this, arguments);
|
12
|
+
throw new Error('Dynamic require of "' + x + '" is not supported');
|
13
|
+
});
|
14
|
+
var __commonJS = (cb, mod) => function __require2() {
|
15
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
16
|
+
};
|
17
|
+
var __copyProps = (to, from, except, desc) => {
|
18
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
19
|
+
for (let key of __getOwnPropNames(from))
|
20
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
21
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
22
|
+
}
|
23
|
+
return to;
|
24
|
+
};
|
25
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
26
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
27
|
+
// file that has been converted to a CommonJS file using a Babel-
|
28
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
29
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
30
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
31
|
+
mod
|
32
|
+
));
|
33
|
+
|
34
|
+
export { __commonJS, __require, __toESM };
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
@@ -0,0 +1,627 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __create = Object.create;
|
3
|
+
var __defProp = Object.defineProperty;
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
8
|
+
var __commonJS = (cb, mod) => function __require() {
|
9
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
10
|
+
};
|
11
|
+
var __export = (target, all) => {
|
12
|
+
for (var name in all)
|
13
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
14
|
+
};
|
15
|
+
var __copyProps = (to, from, except, desc) => {
|
16
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
17
|
+
for (let key of __getOwnPropNames(from))
|
18
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
19
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
20
|
+
}
|
21
|
+
return to;
|
22
|
+
};
|
23
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
24
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
25
|
+
// file that has been converted to a CommonJS file using a Babel-
|
26
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
27
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
28
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
29
|
+
mod
|
30
|
+
));
|
31
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
32
|
+
|
33
|
+
// ../../node_modules/.pnpm/pretty-hrtime@1.0.3/node_modules/pretty-hrtime/index.js
|
34
|
+
var require_pretty_hrtime = __commonJS({
|
35
|
+
"../../node_modules/.pnpm/pretty-hrtime@1.0.3/node_modules/pretty-hrtime/index.js"(exports, module2) {
|
36
|
+
"use strict";
|
37
|
+
var minimalDesc = ["h", "min", "s", "ms", "\u03BCs", "ns"];
|
38
|
+
var verboseDesc = ["hour", "minute", "second", "millisecond", "microsecond", "nanosecond"];
|
39
|
+
var convert = [60 * 60, 60, 1, 1e6, 1e3, 1];
|
40
|
+
module2.exports = function(source, opts) {
|
41
|
+
var verbose, precise, i, spot, sourceAtStep, valAtStep, decimals, strAtStep, results, totalSeconds;
|
42
|
+
verbose = false;
|
43
|
+
precise = false;
|
44
|
+
if (opts) {
|
45
|
+
verbose = opts.verbose || false;
|
46
|
+
precise = opts.precise || false;
|
47
|
+
}
|
48
|
+
if (!Array.isArray(source) || source.length !== 2) {
|
49
|
+
return "";
|
50
|
+
}
|
51
|
+
if (typeof source[0] !== "number" || typeof source[1] !== "number") {
|
52
|
+
return "";
|
53
|
+
}
|
54
|
+
if (source[1] < 0) {
|
55
|
+
totalSeconds = source[0] + source[1] / 1e9;
|
56
|
+
source[0] = parseInt(totalSeconds);
|
57
|
+
source[1] = parseFloat((totalSeconds % 1).toPrecision(9)) * 1e9;
|
58
|
+
}
|
59
|
+
results = "";
|
60
|
+
for (i = 0; i < 6; i++) {
|
61
|
+
spot = i < 3 ? 0 : 1;
|
62
|
+
sourceAtStep = source[spot];
|
63
|
+
if (i !== 3 && i !== 0) {
|
64
|
+
sourceAtStep = sourceAtStep % convert[i - 1];
|
65
|
+
}
|
66
|
+
if (i === 2) {
|
67
|
+
sourceAtStep += source[1] / 1e9;
|
68
|
+
}
|
69
|
+
valAtStep = sourceAtStep / convert[i];
|
70
|
+
if (valAtStep >= 1) {
|
71
|
+
if (verbose) {
|
72
|
+
valAtStep = Math.floor(valAtStep);
|
73
|
+
}
|
74
|
+
if (!precise) {
|
75
|
+
decimals = valAtStep >= 10 ? 0 : 2;
|
76
|
+
strAtStep = valAtStep.toFixed(decimals);
|
77
|
+
} else {
|
78
|
+
strAtStep = valAtStep.toString();
|
79
|
+
}
|
80
|
+
if (strAtStep.indexOf(".") > -1 && strAtStep[strAtStep.length - 1] === "0") {
|
81
|
+
strAtStep = strAtStep.replace(/\.?0+$/, "");
|
82
|
+
}
|
83
|
+
if (results) {
|
84
|
+
results += " ";
|
85
|
+
}
|
86
|
+
results += strAtStep;
|
87
|
+
if (verbose) {
|
88
|
+
results += " " + verboseDesc[i];
|
89
|
+
if (strAtStep !== "1") {
|
90
|
+
results += "s";
|
91
|
+
}
|
92
|
+
} else {
|
93
|
+
results += " " + minimalDesc[i];
|
94
|
+
}
|
95
|
+
if (!verbose) {
|
96
|
+
break;
|
97
|
+
}
|
98
|
+
}
|
99
|
+
}
|
100
|
+
return results;
|
101
|
+
};
|
102
|
+
}
|
103
|
+
});
|
104
|
+
|
105
|
+
// src/index.ts
|
106
|
+
var src_exports = {};
|
107
|
+
__export(src_exports, {
|
108
|
+
bail: () => bail,
|
109
|
+
build: () => build,
|
110
|
+
corePresets: () => corePresets,
|
111
|
+
executor: () => executor,
|
112
|
+
getConfig: () => getConfig,
|
113
|
+
getVirtualModules: () => getVirtualModules,
|
114
|
+
importPipeline: () => importPipeline,
|
115
|
+
previewMainTemplate: () => previewMainTemplate,
|
116
|
+
printDuration: () => printDuration,
|
117
|
+
rsbuild: () => rsbuild,
|
118
|
+
start: () => start,
|
119
|
+
toImportFn: () => toImportFn,
|
120
|
+
toImportFnPart: () => toImportFnPart
|
121
|
+
});
|
122
|
+
module.exports = __toCommonJS(src_exports);
|
123
|
+
var rsbuildReal = __toESM(require("@rsbuild/core"));
|
124
|
+
var import_path4 = require("path");
|
125
|
+
var import_express = __toESM(require("express"));
|
126
|
+
var import_fs_extra = __toESM(require("fs-extra"));
|
127
|
+
var import_server_errors = require("@storybook/core-events/server-errors");
|
128
|
+
|
129
|
+
// src/preview/iframe-rsbuild.config.ts
|
130
|
+
var import_path3 = require("path");
|
131
|
+
var import_case_sensitive_paths_webpack_plugin = __toESM(require("case-sensitive-paths-webpack-plugin"));
|
132
|
+
var import_globals = require("@storybook/preview/globals");
|
133
|
+
var import_core_common2 = require("@storybook/core-common");
|
134
|
+
var import_ts_dedent2 = require("ts-dedent");
|
135
|
+
|
136
|
+
// 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_core_common = require("@storybook/core-common");
|
141
|
+
|
142
|
+
// ../../node_modules/.pnpm/slash@5.1.0/node_modules/slash/index.js
|
143
|
+
function slash(path2) {
|
144
|
+
const isExtendedLengthPath = path2.startsWith("\\\\?\\");
|
145
|
+
if (isExtendedLengthPath) {
|
146
|
+
return path2;
|
147
|
+
}
|
148
|
+
return path2.replace(/\\/g, "/");
|
149
|
+
}
|
150
|
+
|
151
|
+
// src/preview/virtual-module-mapping.ts
|
152
|
+
var import_core_webpack = require("@storybook/core-webpack");
|
153
|
+
var import_ts_dedent = require("ts-dedent");
|
154
|
+
var getVirtualModules = async (options) => {
|
155
|
+
const virtualModules = {};
|
156
|
+
const cwd = process.cwd();
|
157
|
+
const workingDir = options.cache?.basePath || process.cwd();
|
158
|
+
const isProd = options.configType === "PRODUCTION";
|
159
|
+
const nonNormalizedStories = await options.presets.apply("stories", []);
|
160
|
+
const entries = [];
|
161
|
+
const stories = (0, import_core_common.normalizeStories)(nonNormalizedStories, {
|
162
|
+
configDir: options.configDir,
|
163
|
+
workingDir
|
164
|
+
});
|
165
|
+
const realPathRelativeToCwd = import_path.default.relative(workingDir, cwd);
|
166
|
+
const previewAnnotations = [
|
167
|
+
...(await options.presets.apply(
|
168
|
+
"previewAnnotations",
|
169
|
+
[],
|
170
|
+
options
|
171
|
+
)).map((entry) => {
|
172
|
+
if (typeof entry === "object") {
|
173
|
+
return entry.absolute;
|
174
|
+
}
|
175
|
+
return slash(entry);
|
176
|
+
}),
|
177
|
+
(0, import_core_common.loadPreviewOrConfigFile)(options)
|
178
|
+
].filter(Boolean);
|
179
|
+
const storiesFilename = "storybook-stories.js";
|
180
|
+
const storiesPath = (0, import_path2.resolve)((0, import_path2.join)(workingDir, storiesFilename));
|
181
|
+
const needPipelinedImport = !isProd;
|
182
|
+
virtualModules[storiesPath] = toImportFn(stories, realPathRelativeToCwd, {
|
183
|
+
needPipelinedImport
|
184
|
+
});
|
185
|
+
const configEntryPath = (0, import_path2.resolve)((0, import_path2.join)(workingDir, "storybook-config-entry.js"));
|
186
|
+
virtualModules[configEntryPath] = (0, import_core_common.handlebars)(
|
187
|
+
await (0, import_core_common.readTemplate)(
|
188
|
+
require.resolve("storybook-builder-rsbuild/templates/virtualModuleModernEntry.js.handlebars")
|
189
|
+
),
|
190
|
+
{
|
191
|
+
storiesFilename,
|
192
|
+
previewAnnotations
|
193
|
+
}
|
194
|
+
// We need to double escape `\` for webpack. We may have some in windows paths
|
195
|
+
).replace(/\\/g, "\\\\");
|
196
|
+
entries.push(configEntryPath);
|
197
|
+
Object.entries(virtualModules).forEach(([key, value]) => {
|
198
|
+
import_fs.default.writeFileSync(key, value);
|
199
|
+
});
|
200
|
+
return {
|
201
|
+
virtualModules,
|
202
|
+
entries
|
203
|
+
};
|
204
|
+
};
|
205
|
+
function toImportFnPart(specifier) {
|
206
|
+
const { directory, importPathMatcher } = specifier;
|
207
|
+
return import_ts_dedent.dedent`
|
208
|
+
async (path) => {
|
209
|
+
if (!${importPathMatcher}.exec(path)) {
|
210
|
+
return;
|
211
|
+
}
|
212
|
+
|
213
|
+
const pathRemainder = path.substring(${directory.length + 1});
|
214
|
+
return import(
|
215
|
+
/* webpackChunkName: "[request]" */
|
216
|
+
/* webpackInclude: ${(0, import_core_webpack.webpackIncludeRegexp)(specifier)} */
|
217
|
+
'${directory}/' + pathRemainder
|
218
|
+
);
|
219
|
+
}
|
220
|
+
|
221
|
+
`;
|
222
|
+
}
|
223
|
+
function toImportFn(stories, relativeOffset, { needPipelinedImport } = {}) {
|
224
|
+
let pipelinedImport = `const pipeline = (x) => x();`;
|
225
|
+
if (needPipelinedImport) {
|
226
|
+
pipelinedImport = `
|
227
|
+
const importPipeline = ${importPipeline};
|
228
|
+
const pipeline = importPipeline();
|
229
|
+
`;
|
230
|
+
}
|
231
|
+
return import_ts_dedent.dedent`
|
232
|
+
${pipelinedImport}
|
233
|
+
|
234
|
+
const importers = [
|
235
|
+
${stories.map(toImportFnPart).join(",\n")}
|
236
|
+
];
|
237
|
+
|
238
|
+
export async function importFn(path) {
|
239
|
+
const offset = '${relativeOffset}';
|
240
|
+
|
241
|
+
for (let i = 0; i < importers.length; i++) {
|
242
|
+
const pathWithOffset = buildPath(offset, path)
|
243
|
+
|
244
|
+
const moduleExports = await pipeline(() => importers[i](pathWithOffset));
|
245
|
+
if (moduleExports) {
|
246
|
+
return moduleExports;
|
247
|
+
}
|
248
|
+
}
|
249
|
+
}
|
250
|
+
|
251
|
+
function buildPath(offset, path) {
|
252
|
+
if(path.startsWith('./')) {
|
253
|
+
return offset + '/' + path.substring(2);
|
254
|
+
} else {
|
255
|
+
return offset + '/' + path;
|
256
|
+
}
|
257
|
+
}
|
258
|
+
`;
|
259
|
+
}
|
260
|
+
function importPipeline() {
|
261
|
+
let importGate = Promise.resolve();
|
262
|
+
return async (importFn) => {
|
263
|
+
await importGate;
|
264
|
+
const moduleExportsPromise = importFn();
|
265
|
+
importGate = importGate.then(async () => {
|
266
|
+
await moduleExportsPromise;
|
267
|
+
});
|
268
|
+
return moduleExportsPromise;
|
269
|
+
};
|
270
|
+
}
|
271
|
+
|
272
|
+
// 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 getAbsolutePath = (input) => (0, import_path3.dirname)(require.resolve((0, import_path3.join)(input, "package.json")));
|
276
|
+
var maybeGetAbsolutePath = (input) => {
|
277
|
+
try {
|
278
|
+
return getAbsolutePath(input);
|
279
|
+
} catch (e) {
|
280
|
+
return false;
|
281
|
+
}
|
282
|
+
};
|
283
|
+
var managerAPIPath = maybeGetAbsolutePath(`@storybook/manager-api`);
|
284
|
+
var componentsPath = maybeGetAbsolutePath(`@storybook/components`);
|
285
|
+
var globalPath = maybeGetAbsolutePath(`@storybook/global`);
|
286
|
+
var routerPath = maybeGetAbsolutePath(`@storybook/router`);
|
287
|
+
var themingPath = maybeGetAbsolutePath(`@storybook/theming`);
|
288
|
+
var storybookPaths = {
|
289
|
+
...managerAPIPath ? {
|
290
|
+
[`@storybook/manager-api`]: managerAPIPath
|
291
|
+
} : {},
|
292
|
+
...componentsPath ? { [`@storybook/components`]: componentsPath } : {},
|
293
|
+
...globalPath ? { [`@storybook/global`]: globalPath } : {},
|
294
|
+
...routerPath ? { [`@storybook/router`]: routerPath } : {},
|
295
|
+
...themingPath ? { [`@storybook/theming`]: themingPath } : {}
|
296
|
+
};
|
297
|
+
var iframe_rsbuild_config_default = async (options) => {
|
298
|
+
const appliedDocsWebpack = await (0, import_preset.webpack)({}, options);
|
299
|
+
const {
|
300
|
+
outputDir = (0, import_path3.join)(".", "public"),
|
301
|
+
quiet,
|
302
|
+
packageJson,
|
303
|
+
configType,
|
304
|
+
presets,
|
305
|
+
previewUrl,
|
306
|
+
// typescriptOptions,
|
307
|
+
features
|
308
|
+
} = options;
|
309
|
+
const isProd = configType === "PRODUCTION";
|
310
|
+
const workingDir = process.cwd();
|
311
|
+
const [
|
312
|
+
coreOptions,
|
313
|
+
frameworkOptions,
|
314
|
+
envs,
|
315
|
+
logLevel,
|
316
|
+
headHtmlSnippet,
|
317
|
+
bodyHtmlSnippet,
|
318
|
+
template,
|
319
|
+
docsOptions,
|
320
|
+
entries,
|
321
|
+
nonNormalizedStories,
|
322
|
+
// modulesCount = 1000,
|
323
|
+
build2,
|
324
|
+
tagsOptions
|
325
|
+
] = await Promise.all([
|
326
|
+
presets.apply("core"),
|
327
|
+
presets.apply("frameworkOptions"),
|
328
|
+
presets.apply("env"),
|
329
|
+
presets.apply("logLevel", void 0),
|
330
|
+
presets.apply("previewHead"),
|
331
|
+
presets.apply("previewBody"),
|
332
|
+
presets.apply("previewMainTemplate"),
|
333
|
+
presets.apply("docs"),
|
334
|
+
presets.apply("entries", []),
|
335
|
+
presets.apply("stories", []),
|
336
|
+
options.cache?.get("modulesCount").catch(() => {
|
337
|
+
}),
|
338
|
+
options.presets.apply("build"),
|
339
|
+
presets.apply("tags", {})
|
340
|
+
]);
|
341
|
+
const { rsbuildConfigPath } = await (0, import_core_common2.getBuilderOptions)(options);
|
342
|
+
const stories = (0, import_core_common2.normalizeStories)(nonNormalizedStories, {
|
343
|
+
configDir: options.configDir,
|
344
|
+
workingDir
|
345
|
+
});
|
346
|
+
if (!template) {
|
347
|
+
throw new Error(import_ts_dedent2.dedent`
|
348
|
+
Storybook's Webpack5 builder requires a template to be specified.
|
349
|
+
Somehow you've ended up with a falsy value for the template option.
|
350
|
+
|
351
|
+
Please file an issue at https://github.com/storybookjs/storybook with a reproduction.
|
352
|
+
`);
|
353
|
+
}
|
354
|
+
const externals = import_globals.globalsNameReferenceMap;
|
355
|
+
if (build2?.test?.disableBlocks) {
|
356
|
+
externals["@storybook/blocks"] = "__STORYBOOK_BLOCKS_EMPTY_MODULE__";
|
357
|
+
}
|
358
|
+
const { virtualModules: _virtualModules, entries: dynamicEntries } = await getVirtualModules(options);
|
359
|
+
if (!options.cache) {
|
360
|
+
throw new Error("Cache is required");
|
361
|
+
}
|
362
|
+
const { content } = await (0, import_core.loadConfig)({
|
363
|
+
cwd: workingDir,
|
364
|
+
path: rsbuildConfigPath
|
365
|
+
});
|
366
|
+
const resourceFilename = isProd ? "static/media/[name].[contenthash:8][ext]" : "static/media/[path][name][ext]";
|
367
|
+
const merged = (0, import_core.mergeRsbuildConfig)(content, {
|
368
|
+
output: {
|
369
|
+
cleanDistPath: false,
|
370
|
+
dataUriLimit: {
|
371
|
+
media: 1e4
|
372
|
+
},
|
373
|
+
sourceMap: {
|
374
|
+
js: options.build?.test?.disableSourcemaps ? false : "cheap-module-source-map",
|
375
|
+
css: options.build?.test?.disableSourcemaps ? false : true
|
376
|
+
},
|
377
|
+
distPath: {
|
378
|
+
root: (0, import_path3.resolve)(process.cwd(), outputDir)
|
379
|
+
},
|
380
|
+
filename: {
|
381
|
+
js: isProd ? "[name].[contenthash:8].iframe.bundle.js" : "[name].iframe.bundle.js",
|
382
|
+
image: resourceFilename,
|
383
|
+
font: resourceFilename,
|
384
|
+
media: resourceFilename
|
385
|
+
},
|
386
|
+
assetPrefix: "/",
|
387
|
+
externals
|
388
|
+
},
|
389
|
+
dev: {
|
390
|
+
assetPrefix: "",
|
391
|
+
progressBar: !quiet
|
392
|
+
},
|
393
|
+
source: {
|
394
|
+
alias: {
|
395
|
+
...storybookPaths
|
396
|
+
},
|
397
|
+
entry: {
|
398
|
+
// to avoid `It's not allowed to load an initial chunk on demand. The chunk name "main" is already used by an entrypoint` of
|
399
|
+
main: [...entries ?? [], ...dynamicEntries]
|
400
|
+
},
|
401
|
+
define: {
|
402
|
+
...(0, import_core_common2.stringifyProcessEnvs)(envs),
|
403
|
+
NODE_ENV: JSON.stringify(process.env.NODE_ENV)
|
404
|
+
}
|
405
|
+
},
|
406
|
+
performance: {
|
407
|
+
chunkSplit: {
|
408
|
+
strategy: "custom",
|
409
|
+
splitChunks: {
|
410
|
+
chunks: "all"
|
411
|
+
}
|
412
|
+
}
|
413
|
+
},
|
414
|
+
tools: {
|
415
|
+
rspack: (config, { addRules, appendPlugins, rspack, mergeConfig }) => {
|
416
|
+
addRules({
|
417
|
+
test: /\.stories\.([tj])sx?$|(stories|story)\.mdx$/,
|
418
|
+
exclude: /node_modules/,
|
419
|
+
enforce: "post",
|
420
|
+
use: [
|
421
|
+
{
|
422
|
+
loader: require.resolve("storybook-builder-rsbuild/loaders/export-order-loader")
|
423
|
+
}
|
424
|
+
]
|
425
|
+
});
|
426
|
+
config.resolve ??= {};
|
427
|
+
config.resolve.symlinks = !(0, import_core_common2.isPreservingSymlinks)();
|
428
|
+
config.watchOptions = {
|
429
|
+
ignored: /node_modules/
|
430
|
+
};
|
431
|
+
config.output = config.output || {};
|
432
|
+
config.output.publicPath = "";
|
433
|
+
config.ignoreWarnings = [
|
434
|
+
...config.ignoreWarnings || [],
|
435
|
+
/export '\S+' was not found in 'global'/,
|
436
|
+
/export '\S+' was not found in '@storybook\/global'/
|
437
|
+
];
|
438
|
+
config.resolve ??= {};
|
439
|
+
config.resolve.fallback ??= {
|
440
|
+
stream: false,
|
441
|
+
path: require.resolve("path-browserify"),
|
442
|
+
assert: require.resolve("browser-assert"),
|
443
|
+
util: require.resolve("util"),
|
444
|
+
url: require.resolve("url"),
|
445
|
+
fs: false,
|
446
|
+
constants: require.resolve("constants-browserify")
|
447
|
+
};
|
448
|
+
config.optimization ??= {};
|
449
|
+
config.optimization.runtimeChunk = true;
|
450
|
+
config.optimization.usedExports = options.build?.test?.disableTreeShaking ? false : isProd;
|
451
|
+
config.optimization.moduleIds = "named";
|
452
|
+
appendPlugins(
|
453
|
+
[
|
454
|
+
new rspack.ProvidePlugin({
|
455
|
+
process: require.resolve("process/browser.js")
|
456
|
+
}),
|
457
|
+
new import_case_sensitive_paths_webpack_plugin.default()
|
458
|
+
].filter(Boolean)
|
459
|
+
);
|
460
|
+
return mergeConfig(config, appliedDocsWebpack);
|
461
|
+
},
|
462
|
+
htmlPlugin: {
|
463
|
+
filename: `iframe.html`,
|
464
|
+
// FIXME: `none` isn't a known option
|
465
|
+
chunksSortMode: "none",
|
466
|
+
alwaysWriteToDisk: true,
|
467
|
+
inject: false,
|
468
|
+
template,
|
469
|
+
templateParameters: {
|
470
|
+
version: packageJson.version,
|
471
|
+
globals: {
|
472
|
+
CONFIG_TYPE: configType,
|
473
|
+
LOGLEVEL: logLevel,
|
474
|
+
FRAMEWORK_OPTIONS: frameworkOptions,
|
475
|
+
CHANNEL_OPTIONS: coreOptions.channelOptions,
|
476
|
+
FEATURES: features,
|
477
|
+
PREVIEW_URL: previewUrl,
|
478
|
+
STORIES: stories.map((specifier) => ({
|
479
|
+
...specifier,
|
480
|
+
importPathMatcher: specifier.importPathMatcher.source
|
481
|
+
})),
|
482
|
+
DOCS_OPTIONS: docsOptions,
|
483
|
+
TAGS_OPTIONS: tagsOptions,
|
484
|
+
...build2?.test?.disableBlocks ? { __STORYBOOK_BLOCKS_EMPTY_MODULE__: {} } : {}
|
485
|
+
},
|
486
|
+
headHtmlSnippet,
|
487
|
+
bodyHtmlSnippet
|
488
|
+
},
|
489
|
+
minify: {
|
490
|
+
collapseWhitespace: true,
|
491
|
+
removeComments: true,
|
492
|
+
removeRedundantAttributes: true,
|
493
|
+
removeScriptTypeAttributes: false,
|
494
|
+
removeStyleLinkTypeAttributes: true,
|
495
|
+
useShortDoctype: true
|
496
|
+
}
|
497
|
+
}
|
498
|
+
}
|
499
|
+
});
|
500
|
+
return merged;
|
501
|
+
};
|
502
|
+
|
503
|
+
// src/index.ts
|
504
|
+
var import_pretty_hrtime = __toESM(require_pretty_hrtime());
|
505
|
+
var printDuration = (startTime) => (0, import_pretty_hrtime.default)(process.hrtime(startTime)).replace(" ms", " milliseconds").replace(" s", " seconds").replace(" m", " minutes");
|
506
|
+
var getAbsolutePath2 = (input) => (0, import_path4.dirname)(require.resolve((0, import_path4.join)(input, "package.json")));
|
507
|
+
var executor = {
|
508
|
+
get: async (options) => {
|
509
|
+
const rsbuildInstance = await options.presets.apply("rsbuildInstance") || rsbuildReal;
|
510
|
+
return rsbuildInstance;
|
511
|
+
}
|
512
|
+
};
|
513
|
+
var rsbuild = async (_, options) => {
|
514
|
+
const defaultConfig = await iframe_rsbuild_config_default(options);
|
515
|
+
const { presets } = options;
|
516
|
+
const finalDefaultConfig = await presets.apply(
|
517
|
+
"rsbuildFinal",
|
518
|
+
defaultConfig,
|
519
|
+
options
|
520
|
+
);
|
521
|
+
return finalDefaultConfig;
|
522
|
+
};
|
523
|
+
var getConfig = async (options) => {
|
524
|
+
const { presets } = options;
|
525
|
+
const typescriptOptions = await presets.apply("typescript", {}, options);
|
526
|
+
const frameworkOptions = await presets.apply("frameworkOptions");
|
527
|
+
return rsbuild({}, {
|
528
|
+
...options,
|
529
|
+
typescriptOptions,
|
530
|
+
frameworkOptions
|
531
|
+
});
|
532
|
+
};
|
533
|
+
var server;
|
534
|
+
async function bail() {
|
535
|
+
return server?.close();
|
536
|
+
}
|
537
|
+
var start = async ({
|
538
|
+
startTime,
|
539
|
+
options,
|
540
|
+
router,
|
541
|
+
server: storybookServer,
|
542
|
+
channel
|
543
|
+
}) => {
|
544
|
+
const { createRsbuild } = await executor.get(options);
|
545
|
+
const config = await getConfig(options);
|
546
|
+
const rsbuildBuild = await createRsbuild({
|
547
|
+
cwd: process.cwd(),
|
548
|
+
rsbuildConfig: {
|
549
|
+
...config,
|
550
|
+
server: {
|
551
|
+
...config.server,
|
552
|
+
port: options.port,
|
553
|
+
host: "localhost",
|
554
|
+
htmlFallback: false,
|
555
|
+
strictPort: true,
|
556
|
+
printUrls: false
|
557
|
+
},
|
558
|
+
dev: {
|
559
|
+
client: {}
|
560
|
+
}
|
561
|
+
}
|
562
|
+
});
|
563
|
+
const rsbuildServer = await rsbuildBuild.createDevServer();
|
564
|
+
server = rsbuildServer;
|
565
|
+
if (!rsbuildBuild) {
|
566
|
+
throw new import_server_errors.WebpackInvocationError({
|
567
|
+
// eslint-disable-next-line local-rules/no-uncategorized-errors
|
568
|
+
error: new Error(`Missing Rsbuild build instance at runtime!`)
|
569
|
+
});
|
570
|
+
}
|
571
|
+
const previewResolvedDir = getAbsolutePath2("@storybook/preview");
|
572
|
+
const previewDirOrigin = (0, import_path4.join)(previewResolvedDir, "dist");
|
573
|
+
router.use(
|
574
|
+
`/sb-preview`,
|
575
|
+
import_express.default.static(previewDirOrigin, { immutable: true, maxAge: "5m" })
|
576
|
+
);
|
577
|
+
router.use(rsbuildServer.middlewares);
|
578
|
+
storybookServer.on("upgrade", rsbuildServer.onHTTPUpgrade);
|
579
|
+
return {
|
580
|
+
bail,
|
581
|
+
stats: {
|
582
|
+
toJson: () => {
|
583
|
+
throw new import_server_errors.NoStatsForViteDevError();
|
584
|
+
}
|
585
|
+
},
|
586
|
+
totalTime: process.hrtime(startTime)
|
587
|
+
};
|
588
|
+
};
|
589
|
+
var build = async ({ options }) => {
|
590
|
+
const { createRsbuild } = await executor.get(options);
|
591
|
+
const config = await getConfig(options);
|
592
|
+
const rsbuildBuild = await createRsbuild({
|
593
|
+
cwd: process.cwd(),
|
594
|
+
rsbuildConfig: config
|
595
|
+
});
|
596
|
+
const previewResolvedDir = getAbsolutePath2("@storybook/preview");
|
597
|
+
const previewDirOrigin = (0, import_path4.join)(previewResolvedDir, "dist");
|
598
|
+
const previewDirTarget = (0, import_path4.join)(options.outputDir || "", `sb-preview`);
|
599
|
+
const previewFiles = import_fs_extra.default.copy(previewDirOrigin, previewDirTarget, {
|
600
|
+
filter: (src) => {
|
601
|
+
const { ext } = (0, import_path4.parse)(src);
|
602
|
+
if (ext) {
|
603
|
+
return ext === ".js";
|
604
|
+
}
|
605
|
+
return true;
|
606
|
+
}
|
607
|
+
});
|
608
|
+
await Promise.all([rsbuildBuild.build(), previewFiles]);
|
609
|
+
};
|
610
|
+
var corePresets = [(0, import_path4.join)(__dirname, "./preview-preset.js")];
|
611
|
+
var previewMainTemplate = () => require.resolve("storybook-builder-rsbuild/templates/preview.ejs");
|
612
|
+
// Annotate the CommonJS export names for ESM import in node:
|
613
|
+
0 && (module.exports = {
|
614
|
+
bail,
|
615
|
+
build,
|
616
|
+
corePresets,
|
617
|
+
executor,
|
618
|
+
getConfig,
|
619
|
+
getVirtualModules,
|
620
|
+
importPipeline,
|
621
|
+
previewMainTemplate,
|
622
|
+
printDuration,
|
623
|
+
rsbuild,
|
624
|
+
start,
|
625
|
+
toImportFn,
|
626
|
+
toImportFnPart
|
627
|
+
});
|