@module-federation/storybook-addon 0.0.0-chore-bump-node-22-20260710161714
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 +165 -0
- package/dist/CHANGELOG.md +2108 -0
- package/dist/README.md +165 -0
- package/dist/preset.d.ts +13 -0
- package/dist/preset.js +105 -0
- package/dist/preset.js.map +1 -0
- package/dist/src/index.d.ts +2 -0
- package/dist/src/index.js +3 -0
- package/dist/src/lib/storybook-addon.d.ts +21 -0
- package/dist/src/lib/storybook-addon.js +100 -0
- package/dist/src/lib/storybook-addon.js.map +1 -0
- package/dist/src/utils/correctImportPath.js +17 -0
- package/dist/src/utils/correctImportPath.js.map +1 -0
- package/dist/src/utils/with-module-federation.js +33 -0
- package/dist/src/utils/with-module-federation.js.map +1 -0
- package/package.json +117 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2020 ScriptedAlchemy LLC (Zack Jackson) Zhou Shaw (zhouxiao)
|
|
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,165 @@
|
|
|
1
|
+
# Storybook addon for Module Federation
|
|
2
|
+
|
|
3
|
+
This addon enables to consume remote Module Federated apps/components
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```shell
|
|
8
|
+
# with NPM
|
|
9
|
+
npm install @module-federation/storybook-addon
|
|
10
|
+
|
|
11
|
+
# with Yarn
|
|
12
|
+
yarn add @module-federation/storybook-addon
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Configuration
|
|
16
|
+
|
|
17
|
+
In file `./storybook/main.js`:
|
|
18
|
+
|
|
19
|
+
```js
|
|
20
|
+
const moduleFederationConfig = {
|
|
21
|
+
// Module Federation config
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
const storybookConfig = {
|
|
25
|
+
stories: ['../src/**/*.stories.mdx', '../src/**/*.stories.@(js|jsx|ts|tsx)'],
|
|
26
|
+
addons: [
|
|
27
|
+
// other addons,
|
|
28
|
+
{
|
|
29
|
+
name: '@module-federation/storybook-addon',
|
|
30
|
+
options: {
|
|
31
|
+
moduleFederationConfig,
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
],
|
|
35
|
+
framework: '@storybook/react',
|
|
36
|
+
core: {
|
|
37
|
+
builder: '@storybook/builder-webpack5', // is required webpack 5 builder
|
|
38
|
+
},
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
module.exports = storybookConfig;
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
---
|
|
45
|
+
|
|
46
|
+
### Rsbuild App or Rslib Module
|
|
47
|
+
|
|
48
|
+
```js
|
|
49
|
+
import { dirname, join } from 'node:path';
|
|
50
|
+
import type { StorybookConfig } from 'storybook-react-rsbuild';
|
|
51
|
+
|
|
52
|
+
function getAbsolutePath(value: string): any {
|
|
53
|
+
return dirname(require.resolve(join(value, 'package.json')));
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const config: StorybookConfig = {
|
|
57
|
+
stories: ['../src/**/*.mdx', '../src/**/*.stories.@(js|jsx|mjs|ts|tsx)'],
|
|
58
|
+
framework: {
|
|
59
|
+
name: getAbsolutePath('storybook-react-rsbuild'),
|
|
60
|
+
options: {},
|
|
61
|
+
},
|
|
62
|
+
addons: [
|
|
63
|
+
{
|
|
64
|
+
name: '@module-federation/storybook-addon/preset',
|
|
65
|
+
options: {
|
|
66
|
+
// add remote here and then you can load remote in your story
|
|
67
|
+
remotes: {
|
|
68
|
+
'rslib-module':
|
|
69
|
+
'rslib-module@http://localhost:3000/mf/mf-manifest.json',
|
|
70
|
+
},
|
|
71
|
+
},
|
|
72
|
+
},
|
|
73
|
+
],
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
export default config;
|
|
77
|
+
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
### For the [NX](https://nx.dev/getting-started/intro) projects:
|
|
81
|
+
|
|
82
|
+
Replace Nx module federation wiring in `webpack.config.js` with a plain webpack config that uses `withModuleFederation`.
|
|
83
|
+
Example:
|
|
84
|
+
|
|
85
|
+
```javascript
|
|
86
|
+
const path = require('path');
|
|
87
|
+
const HtmlWebpackPlugin = require('html-webpack-plugin');
|
|
88
|
+
const { withModuleFederation } = require('@module-federation/storybook-addon');
|
|
89
|
+
const baseConfig = require('./module-federation.config');
|
|
90
|
+
|
|
91
|
+
module.exports = withModuleFederation(baseConfig, { dts: false })({
|
|
92
|
+
mode: 'development',
|
|
93
|
+
context: __dirname,
|
|
94
|
+
entry: {
|
|
95
|
+
main: path.resolve(__dirname, 'src/main.ts'),
|
|
96
|
+
},
|
|
97
|
+
plugins: [new HtmlWebpackPlugin({ template: path.resolve(__dirname, 'src/index.html') })],
|
|
98
|
+
});
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
In file `./storybook/main.js`:
|
|
102
|
+
|
|
103
|
+
```js
|
|
104
|
+
const nxModuleFederationConfig = {
|
|
105
|
+
// Module Federation config
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
const storybookConfig = {
|
|
109
|
+
stories: ['../src/**/*.stories.mdx', '../src/**/*.stories.@(js|jsx|ts|tsx)'],
|
|
110
|
+
addons: [
|
|
111
|
+
// other addons,
|
|
112
|
+
{
|
|
113
|
+
name: '@module-federation/storybook-addon',
|
|
114
|
+
options: {
|
|
115
|
+
nxModuleFederationConfig,
|
|
116
|
+
},
|
|
117
|
+
},
|
|
118
|
+
],
|
|
119
|
+
framework: '@storybook/react',
|
|
120
|
+
core: {
|
|
121
|
+
builder: '@storybook/builder-webpack5', // is required webpack 5 builder
|
|
122
|
+
},
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
module.exports = storybookConfig;
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
## Usage
|
|
129
|
+
|
|
130
|
+
```jsx
|
|
131
|
+
import React, { Suspense } from 'react';
|
|
132
|
+
|
|
133
|
+
const LazyButton = React.lazy(() => import('remote/Button'));
|
|
134
|
+
|
|
135
|
+
const Button = (props) => (
|
|
136
|
+
<Suspense fallback={<p>Please wait...</p>}>
|
|
137
|
+
<LazyButton {...props} />
|
|
138
|
+
</Suspense>
|
|
139
|
+
);
|
|
140
|
+
|
|
141
|
+
export default {
|
|
142
|
+
title: 'ModuleFederation/Button',
|
|
143
|
+
component: Button,
|
|
144
|
+
argTypes: {
|
|
145
|
+
variant: {
|
|
146
|
+
control: 'select',
|
|
147
|
+
options: ['primary', 'secondary'],
|
|
148
|
+
},
|
|
149
|
+
},
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
const Template = (args) => <Button {...args} />;
|
|
153
|
+
|
|
154
|
+
export const Primary = Template.bind({ variant: 'primary' });
|
|
155
|
+
Primary.args = {
|
|
156
|
+
variant: 'primary',
|
|
157
|
+
children: 'Button',
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
export const Secondary = Template.bind({});
|
|
161
|
+
Secondary.args = {
|
|
162
|
+
variant: 'secondary',
|
|
163
|
+
children: 'Button',
|
|
164
|
+
};
|
|
165
|
+
```
|