storybook-builder-rsbuild 0.0.9 → 0.0.11

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 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
- content.source ??= {};
380
- content.source.entry = {};
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)(content, {
414
+ const merged = (0, import_core.mergeRsbuildConfig)(contentFromConfig, {
383
415
  output: {
384
416
  cleanDistPath: false,
385
417
  dataUriLimit: {
@@ -431,14 +463,14 @@ var iframe_rsbuild_config_default = async (options) => {
431
463
  },
432
464
  plugins: [
433
465
  shouldCheckTs ? (0, import_plugin_type_check.pluginTypeCheck)(tsCheckOptions) : null,
434
- (0, import_rsbuild_plugin_html_minifier_terser.pluginHtmlMinifierTerser)({
466
+ (0, import_rsbuild_plugin_html_minifier_terser.pluginHtmlMinifierTerser)(() => ({
435
467
  collapseWhitespace: true,
436
468
  removeComments: true,
437
469
  removeRedundantAttributes: true,
438
470
  removeScriptTypeAttributes: false,
439
471
  removeStyleLinkTypeAttributes: true,
440
472
  useShortDoctype: true
441
- })
473
+ }))
442
474
  ].filter(Boolean),
443
475
  tools: {
444
476
  rspack: (config, { addRules, appendPlugins, rspack, mergeConfig }) => {
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
- content.source ??= {};
323
- content.source.entry = {};
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(content, {
357
+ const merged = mergeRsbuildConfig(contentFromConfig, {
326
358
  output: {
327
359
  cleanDistPath: false,
328
360
  dataUriLimit: {
@@ -374,14 +406,14 @@ var iframe_rsbuild_config_default = async (options) => {
374
406
  },
375
407
  plugins: [
376
408
  shouldCheckTs ? pluginTypeCheck(tsCheckOptions) : null,
377
- pluginHtmlMinifierTerser({
409
+ pluginHtmlMinifierTerser(() => ({
378
410
  collapseWhitespace: true,
379
411
  removeComments: true,
380
412
  removeRedundantAttributes: true,
381
413
  removeScriptTypeAttributes: false,
382
414
  removeStyleLinkTypeAttributes: true,
383
415
  useShortDoctype: true
384
- })
416
+ }))
385
417
  ].filter(Boolean),
386
418
  tools: {
387
419
  rspack: (config, { addRules, appendPlugins, rspack, mergeConfig }) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "storybook-builder-rsbuild",
3
- "version": "0.0.9",
3
+ "version": "0.0.11",
4
4
  "description": "Rsbuild builder for Storybook",
5
5
  "keywords": [
6
6
  "storybook",
@@ -56,7 +56,7 @@
56
56
  "!src/**/*"
57
57
  ],
58
58
  "dependencies": {
59
- "@rsbuild/plugin-type-check": "1.0.1-beta.0",
59
+ "@rsbuild/plugin-type-check": "1.0.1-beta.10",
60
60
  "@storybook/addon-docs": "^8.2.1",
61
61
  "@storybook/core-webpack": "^8.2.1",
62
62
  "browser-assert": "^1.2.1",
@@ -78,7 +78,7 @@
78
78
  "util-deprecate": "^1.0.2"
79
79
  },
80
80
  "devDependencies": {
81
- "@rsbuild/core": "1.0.1-beta.0",
81
+ "@rsbuild/core": "1.0.1-beta.10",
82
82
  "@types/express": "^4.17.21",
83
83
  "@types/fs-extra": "^11.0.4",
84
84
  "@types/node": "^18.0.0",
@@ -90,7 +90,7 @@
90
90
  "typescript": "^5.3.2"
91
91
  },
92
92
  "peerDependencies": {
93
- "@rsbuild/core": ">= 1.0.0-alpha.9",
93
+ "@rsbuild/core": ">= 1.0.0-alpha.9 || >= 1.0.1-beta || 1.x",
94
94
  "storybook": "^8.2.1"
95
95
  },
96
96
  "peerDependenciesMeta": {