storybook-addon-rslib 0.1.2 → 0.1.3

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/README.md CHANGED
@@ -1,59 +1,3 @@
1
1
  # storybook-addon-rslib
2
2
 
3
- ## Usage
4
-
5
- 1. Install the addon
6
-
7
- ```bash
8
- pnpm add storybook-addon-rslib -D
9
- ```
10
-
11
- 2. Add it to `main.js`
12
-
13
- ```ts
14
- export default {
15
- addons: ['storybook-addon-rslib'],
16
- }
17
- ```
18
-
19
- or with config
20
-
21
- ```ts
22
- export default {
23
- addons: [
24
- {
25
- name: 'storybook-addon-rslib',
26
- options: {
27
- // Check options section.
28
- },
29
- },
30
- ],
31
- }
32
- ```
33
-
34
- ## Options
35
-
36
- ```ts
37
- export interface AddonOptions {
38
- rslib?: {
39
- /**
40
- * `cwd` passed to loadConfig of Rslib
41
- * @default undefined
42
- */
43
- cwd?: string
44
- /**
45
- * `path` passed to loadConfig of Rslib
46
- * @default undefined
47
- */
48
- configPath?: string
49
- /**
50
- * The lib config index in `lib` field to use, will be merged with the other fields in the config.
51
- * Set to a number to use the lib config at that index.
52
- * Set to `false` to disable using the lib config.
53
- * @experimental subject to change at any time
54
- * @default 0
55
- */
56
- libIndex?: number | false
57
- }
58
- }
59
- ```
3
+ Check out [rspack-contrib/storybook-rsbuild](https://github.com/rspack-contrib/storybook-rsbuild) for documentation.
package/dist/preset.js CHANGED
@@ -23,15 +23,59 @@ __export(preset_exports, {
23
23
  rsbuildFinal: () => rsbuildFinal
24
24
  });
25
25
  module.exports = __toCommonJS(preset_exports);
26
+ var import_core3 = require("@rsbuild/core");
27
+ var import_core4 = require("@rslib/core");
28
+
29
+ // src/mf.ts
26
30
  var import_core = require("@rsbuild/core");
27
31
  var import_core2 = require("@rslib/core");
32
+ async function startMFDevServer(config) {
33
+ if (process.env.NODE_ENV === "production") {
34
+ return;
35
+ }
36
+ const rsbuildInstance = await initMFRsbuild(config);
37
+ return rsbuildInstance;
38
+ }
39
+ async function initMFRsbuild(rslibConfig) {
40
+ const rsbuildConfigObject = await (0, import_core2.unstable_composeCreateRsbuildConfig)(rslibConfig);
41
+ const mfRsbuildConfig = rsbuildConfigObject.find(
42
+ (config) => config.format === "mf"
43
+ );
44
+ if (!mfRsbuildConfig) {
45
+ return;
46
+ }
47
+ mfRsbuildConfig.config = changeEnvToDev(mfRsbuildConfig.config);
48
+ const rsbuildInstance = await (0, import_core.createRsbuild)({
49
+ rsbuildConfig: mfRsbuildConfig.config
50
+ });
51
+ await rsbuildInstance.startDevServer();
52
+ return rsbuildInstance;
53
+ }
54
+ function changeEnvToDev(rsbuildConfig) {
55
+ return (0, import_core.mergeRsbuildConfig)(rsbuildConfig, {
56
+ mode: "development",
57
+ dev: {
58
+ writeToDisk: true
59
+ },
60
+ tools: {
61
+ rspack: {
62
+ optimization: {
63
+ nodeEnv: "development"
64
+ }
65
+ }
66
+ }
67
+ });
68
+ }
69
+
70
+ // src/preset.ts
28
71
  var rsbuildFinal = async (config, options) => {
29
72
  const { rslib = {} } = options;
30
73
  const { cwd, configPath, libIndex = 0 } = rslib;
31
- const rslibConfig = await (0, import_core2.loadConfig)({
74
+ const rslibConfig = await (0, import_core4.loadConfig)({
32
75
  cwd,
33
76
  path: configPath
34
77
  });
78
+ await startMFDevServer(rslibConfig);
35
79
  const libConfig = libIndex === false ? {} : rslibConfig.lib[libIndex];
36
80
  if (!libConfig) {
37
81
  throw new Error(
@@ -39,14 +83,14 @@ var rsbuildFinal = async (config, options) => {
39
83
  );
40
84
  }
41
85
  const { lib: _lib, ...nonLibConfig } = rslibConfig;
42
- const mergedLibConfig = (0, import_core.mergeRsbuildConfig)(
86
+ const mergedLibConfig = (0, import_core3.mergeRsbuildConfig)(
43
87
  nonLibConfig,
44
88
  libConfig
45
89
  );
46
90
  delete mergedLibConfig.source?.entry;
47
91
  delete mergedLibConfig.output?.distPath;
48
92
  delete mergedLibConfig.output?.filename;
49
- return (0, import_core.mergeRsbuildConfig)(config, mergedLibConfig);
93
+ return (0, import_core3.mergeRsbuildConfig)(config, mergedLibConfig);
50
94
  };
51
95
  // Annotate the CommonJS export names for ESM import in node:
52
96
  0 && (module.exports = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "storybook-addon-rslib",
3
- "version": "0.1.2",
3
+ "version": "0.1.3",
4
4
  "description": "Storybook addon for loading configuration of Rslib",
5
5
  "keywords": [
6
6
  "storybook",
@@ -9,6 +9,7 @@
9
9
  "rspack",
10
10
  "rslib"
11
11
  ],
12
+ "homepage": "https://storybook-rsbuild.netlify.app",
12
13
  "bugs": {
13
14
  "url": "https://github.com/rspack-contrib/storybook-rsbuild/issues"
14
15
  },
@@ -36,12 +37,12 @@
36
37
  "!src/**/*"
37
38
  ],
38
39
  "devDependencies": {
39
- "@rsbuild/core": "1.0.17",
40
- "@rslib/core": "0.0.13",
40
+ "@rsbuild/core": "1.0.19",
41
+ "@rslib/core": "^0.0.16",
41
42
  "@types/node": "^18.0.0",
42
43
  "storybook": "8.4.0-alpha.7",
43
44
  "typescript": "^5.6.3",
44
- "storybook-builder-rsbuild": "0.1.2"
45
+ "storybook-builder-rsbuild": "0.1.3"
45
46
  },
46
47
  "peerDependencies": {
47
48
  "@rsbuild/core": "^1.0.1",