storybook-builder-rsbuild 0.0.9 → 0.0.10
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 +4 -0
- package/dist/index.js +35 -3
- package/dist/index.mjs +35 -3
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
@@ -29,6 +29,10 @@ type BuilderOptions = {
|
|
29
29
|
* Enable Rspack's lazy compilation (experimental).
|
30
30
|
*/
|
31
31
|
lazyCompilation?: boolean;
|
32
|
+
/**
|
33
|
+
* Which environment to use from the Rsbuild config.
|
34
|
+
*/
|
35
|
+
environment?: string;
|
32
36
|
};
|
33
37
|
interface BuilderResult extends BuilderResult$1 {
|
34
38
|
stats?: Stats;
|
package/dist/index.js
CHANGED
@@ -372,14 +372,46 @@ var iframe_rsbuild_config_default = async (options) => {
|
|
372
372
|
if (!options.cache) {
|
373
373
|
throw new Error("Cache is required");
|
374
374
|
}
|
375
|
+
let contentFromConfig = {};
|
375
376
|
const { content } = await (0, import_core.loadConfig)({
|
376
377
|
cwd: workingDir,
|
377
378
|
path: rsbuildConfigPath
|
378
379
|
});
|
379
|
-
|
380
|
-
content.
|
380
|
+
const { environments, ...withoutEnv } = content;
|
381
|
+
if (content.environments) {
|
382
|
+
const envCount = Object.keys(content.environments).length;
|
383
|
+
if (envCount === 0) {
|
384
|
+
contentFromConfig = withoutEnv;
|
385
|
+
} else if (envCount === 1) {
|
386
|
+
contentFromConfig = (0, import_core.mergeRsbuildConfig)(
|
387
|
+
withoutEnv,
|
388
|
+
content.environments[0]
|
389
|
+
);
|
390
|
+
} else {
|
391
|
+
const userEnv = builderOptions.environment;
|
392
|
+
if (typeof userEnv !== "string") {
|
393
|
+
throw new Error(
|
394
|
+
"You must specify an environment when there are multiple environments in the Rsbuild config."
|
395
|
+
);
|
396
|
+
}
|
397
|
+
if (Object.keys(content.environments).includes(userEnv)) {
|
398
|
+
contentFromConfig = (0, import_core.mergeRsbuildConfig)(
|
399
|
+
withoutEnv,
|
400
|
+
content.environments[userEnv]
|
401
|
+
);
|
402
|
+
} else {
|
403
|
+
throw new Error(
|
404
|
+
`The specified environment "${userEnv}" is not found in the Rsbuild config.`
|
405
|
+
);
|
406
|
+
}
|
407
|
+
}
|
408
|
+
} else {
|
409
|
+
contentFromConfig = content;
|
410
|
+
}
|
411
|
+
contentFromConfig.source ??= {};
|
412
|
+
contentFromConfig.source.entry = {};
|
381
413
|
const resourceFilename = isProd ? "static/media/[name].[contenthash:8][ext]" : "static/media/[path][name][ext]";
|
382
|
-
const merged = (0, import_core.mergeRsbuildConfig)(
|
414
|
+
const merged = (0, import_core.mergeRsbuildConfig)(contentFromConfig, {
|
383
415
|
output: {
|
384
416
|
cleanDistPath: false,
|
385
417
|
dataUriLimit: {
|
package/dist/index.mjs
CHANGED
@@ -315,14 +315,46 @@ var iframe_rsbuild_config_default = async (options) => {
|
|
315
315
|
if (!options.cache) {
|
316
316
|
throw new Error("Cache is required");
|
317
317
|
}
|
318
|
+
let contentFromConfig = {};
|
318
319
|
const { content } = await loadConfig({
|
319
320
|
cwd: workingDir,
|
320
321
|
path: rsbuildConfigPath
|
321
322
|
});
|
322
|
-
|
323
|
-
content.
|
323
|
+
const { environments, ...withoutEnv } = content;
|
324
|
+
if (content.environments) {
|
325
|
+
const envCount = Object.keys(content.environments).length;
|
326
|
+
if (envCount === 0) {
|
327
|
+
contentFromConfig = withoutEnv;
|
328
|
+
} else if (envCount === 1) {
|
329
|
+
contentFromConfig = mergeRsbuildConfig(
|
330
|
+
withoutEnv,
|
331
|
+
content.environments[0]
|
332
|
+
);
|
333
|
+
} else {
|
334
|
+
const userEnv = builderOptions.environment;
|
335
|
+
if (typeof userEnv !== "string") {
|
336
|
+
throw new Error(
|
337
|
+
"You must specify an environment when there are multiple environments in the Rsbuild config."
|
338
|
+
);
|
339
|
+
}
|
340
|
+
if (Object.keys(content.environments).includes(userEnv)) {
|
341
|
+
contentFromConfig = mergeRsbuildConfig(
|
342
|
+
withoutEnv,
|
343
|
+
content.environments[userEnv]
|
344
|
+
);
|
345
|
+
} else {
|
346
|
+
throw new Error(
|
347
|
+
`The specified environment "${userEnv}" is not found in the Rsbuild config.`
|
348
|
+
);
|
349
|
+
}
|
350
|
+
}
|
351
|
+
} else {
|
352
|
+
contentFromConfig = content;
|
353
|
+
}
|
354
|
+
contentFromConfig.source ??= {};
|
355
|
+
contentFromConfig.source.entry = {};
|
324
356
|
const resourceFilename = isProd ? "static/media/[name].[contenthash:8][ext]" : "static/media/[path][name][ext]";
|
325
|
-
const merged = mergeRsbuildConfig(
|
357
|
+
const merged = mergeRsbuildConfig(contentFromConfig, {
|
326
358
|
output: {
|
327
359
|
cleanDistPath: false,
|
328
360
|
dataUriLimit: {
|