@module-federation/storybook-addon 0.0.0-docs-remove-invalid-lark-link-20251205062649
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 +163 -0
- package/dist/package.json +101 -0
- package/dist/preset.d.ts +7 -0
- package/dist/preset.js +14 -0
- package/dist/preset.js.map +1 -0
- package/dist/src/index.d.ts +1 -0
- package/dist/src/index.js +2 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/lib/storybook-addon.d.ts +17 -0
- package/dist/src/lib/storybook-addon.js +128 -0
- package/dist/src/lib/storybook-addon.js.map +1 -0
- package/dist/src/utils/correctImportPath.d.ts +1 -0
- package/dist/src/utils/correctImportPath.js +20 -0
- package/dist/src/utils/correctImportPath.js.map +1 -0
- package/dist/src/utils/with-module-federation-enhanced-rsbuild.d.ts +5 -0
- package/dist/src/utils/with-module-federation-enhanced-rsbuild.js +72 -0
- package/dist/src/utils/with-module-federation-enhanced-rsbuild.js.map +1 -0
- package/dist/src/utils/with-module-federation.d.ts +4 -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 +100 -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,163 @@
|
|
|
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 utils `withModuleFederation` in `webpack.config.js` with our utils `withModuleFederation`.
|
|
83
|
+
Example:
|
|
84
|
+
|
|
85
|
+
```javascript
|
|
86
|
+
const { composePlugins, withNx } = require('@nx/webpack');
|
|
87
|
+
const { withReact } = require('@nx/react');
|
|
88
|
+
const { withModuleFederation } = require('@module-federation/storybook-addon');
|
|
89
|
+
|
|
90
|
+
const baseConfig = require('./module-federation.config');
|
|
91
|
+
|
|
92
|
+
const config = {
|
|
93
|
+
...baseConfig,
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
module.exports = composePlugins(withNx(), withReact(), withModuleFederation(config));
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
In file `./storybook/main.js`:
|
|
100
|
+
|
|
101
|
+
```js
|
|
102
|
+
const nxModuleFederationConfig = {
|
|
103
|
+
// Module Federation config
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
const storybookConfig = {
|
|
107
|
+
stories: ['../src/**/*.stories.mdx', '../src/**/*.stories.@(js|jsx|ts|tsx)'],
|
|
108
|
+
addons: [
|
|
109
|
+
// other addons,
|
|
110
|
+
{
|
|
111
|
+
name: '@module-federation/storybook-addon',
|
|
112
|
+
options: {
|
|
113
|
+
nxModuleFederationConfig,
|
|
114
|
+
},
|
|
115
|
+
},
|
|
116
|
+
],
|
|
117
|
+
framework: '@storybook/react',
|
|
118
|
+
core: {
|
|
119
|
+
builder: '@storybook/builder-webpack5', // is required webpack 5 builder
|
|
120
|
+
},
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
module.exports = storybookConfig;
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
## Usage
|
|
127
|
+
|
|
128
|
+
```jsx
|
|
129
|
+
import React, { Suspense } from 'react';
|
|
130
|
+
|
|
131
|
+
const LazyButton = React.lazy(() => import('remote/Button'));
|
|
132
|
+
|
|
133
|
+
const Button = (props) => (
|
|
134
|
+
<Suspense fallback={<p>Please wait...</p>}>
|
|
135
|
+
<LazyButton {...props} />
|
|
136
|
+
</Suspense>
|
|
137
|
+
);
|
|
138
|
+
|
|
139
|
+
export default {
|
|
140
|
+
title: 'ModuleFederation/Button',
|
|
141
|
+
component: Button,
|
|
142
|
+
argTypes: {
|
|
143
|
+
variant: {
|
|
144
|
+
control: 'select',
|
|
145
|
+
options: ['primary', 'secondary'],
|
|
146
|
+
},
|
|
147
|
+
},
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
const Template = (args) => <Button {...args} />;
|
|
151
|
+
|
|
152
|
+
export const Primary = Template.bind({ variant: 'primary' });
|
|
153
|
+
Primary.args = {
|
|
154
|
+
variant: 'primary',
|
|
155
|
+
children: 'Button',
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
export const Secondary = Template.bind({});
|
|
159
|
+
Secondary.args = {
|
|
160
|
+
variant: 'secondary',
|
|
161
|
+
children: 'Button',
|
|
162
|
+
};
|
|
163
|
+
```
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@module-federation/storybook-addon",
|
|
3
|
+
"version": "0.0.0-docs-remove-invalid-lark-link-20251205062649",
|
|
4
|
+
"description": "Storybook addon to consume remote module federated apps/components",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/module-federation/core.git",
|
|
10
|
+
"directory": "packages/storybook-addon"
|
|
11
|
+
},
|
|
12
|
+
"publishConfig": {
|
|
13
|
+
"access": "public"
|
|
14
|
+
},
|
|
15
|
+
"keywords": [
|
|
16
|
+
"module-federation",
|
|
17
|
+
"typescript",
|
|
18
|
+
"storybook",
|
|
19
|
+
"rsbuild",
|
|
20
|
+
"storybook-rsbuild",
|
|
21
|
+
"addon"
|
|
22
|
+
],
|
|
23
|
+
"files": [
|
|
24
|
+
"dist/",
|
|
25
|
+
"README.md"
|
|
26
|
+
],
|
|
27
|
+
"author": "Fiodorov Andrei <hello@fyodorovandrei.com> (https://github.com/fyodorovandrei)",
|
|
28
|
+
"main": "dist/src/index.js",
|
|
29
|
+
"types": "dist/src/index.d.ts",
|
|
30
|
+
"exports": {
|
|
31
|
+
".": {
|
|
32
|
+
"types": "./dist/src/index.d.ts",
|
|
33
|
+
"default": "./dist/src/index.js"
|
|
34
|
+
},
|
|
35
|
+
"./preset": {
|
|
36
|
+
"types": "./dist/preset.d.ts",
|
|
37
|
+
"default": "./dist/preset.js"
|
|
38
|
+
},
|
|
39
|
+
"./*": "./*"
|
|
40
|
+
},
|
|
41
|
+
"typesVersions": {
|
|
42
|
+
"*": {
|
|
43
|
+
".": [
|
|
44
|
+
"./dist/index.d.ts"
|
|
45
|
+
],
|
|
46
|
+
"preset": [
|
|
47
|
+
"./dist/preset.d.ts"
|
|
48
|
+
]
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
"dependencies": {
|
|
52
|
+
"@module-federation/enhanced": "workspace:*",
|
|
53
|
+
"@module-federation/sdk": "workspace:*"
|
|
54
|
+
},
|
|
55
|
+
"devDependencies": {
|
|
56
|
+
"jest-fixed-jsdom": "^0.0.9",
|
|
57
|
+
"@module-federation/utilities": "workspace:*",
|
|
58
|
+
"@rsbuild/core": "^1.3.21",
|
|
59
|
+
"@storybook/node-logger": "7.6.20",
|
|
60
|
+
"@storybook/core": "^8.4.6",
|
|
61
|
+
"webpack": "5.94.0",
|
|
62
|
+
"webpack-virtual-modules": "0.6.2"
|
|
63
|
+
},
|
|
64
|
+
"peerDependencies": {
|
|
65
|
+
"@rsbuild/core": "^1.0.1",
|
|
66
|
+
"@module-federation/sdk": "0.0.0-docs-remove-invalid-lark-link-20251205062649",
|
|
67
|
+
"@nx/react": ">= 16.0.0",
|
|
68
|
+
"@nx/webpack": ">= 16.0.0",
|
|
69
|
+
"@storybook/core": ">= 8.2.0",
|
|
70
|
+
"@storybook/node-logger": "^6.5.16 || ^7.0.0 || ^8.0.0",
|
|
71
|
+
"webpack": "^5.75.0",
|
|
72
|
+
"webpack-virtual-modules": "0.6.2"
|
|
73
|
+
},
|
|
74
|
+
"peerDependenciesMeta": {
|
|
75
|
+
"@rsbuild/core": {
|
|
76
|
+
"optional": true
|
|
77
|
+
},
|
|
78
|
+
"@module-federation/sdk": {
|
|
79
|
+
"optional": true
|
|
80
|
+
},
|
|
81
|
+
"@nx/react": {
|
|
82
|
+
"optional": true
|
|
83
|
+
},
|
|
84
|
+
"@nx/webpack": {
|
|
85
|
+
"optional": true
|
|
86
|
+
},
|
|
87
|
+
"@storybook/core": {
|
|
88
|
+
"optional": true
|
|
89
|
+
},
|
|
90
|
+
"@storybook/node-logger": {
|
|
91
|
+
"optional": true
|
|
92
|
+
},
|
|
93
|
+
"webpack": {
|
|
94
|
+
"optional": true
|
|
95
|
+
},
|
|
96
|
+
"webpack-virtual-modules": {
|
|
97
|
+
"optional": true
|
|
98
|
+
}
|
|
99
|
+
},
|
|
100
|
+
"module": "./src/index.js"
|
|
101
|
+
}
|
package/dist/preset.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { RsbuildConfig } from '@rsbuild/core';
|
|
2
|
+
import type { moduleFederationPlugin } from '@module-federation/sdk';
|
|
3
|
+
declare const _default: {
|
|
4
|
+
rsbuildFinal: (config: RsbuildConfig, options: moduleFederationPlugin.ModuleFederationPluginOptions) => RsbuildConfig;
|
|
5
|
+
};
|
|
6
|
+
export default _default;
|
|
7
|
+
export { PLUGIN_NAME } from './src/utils/with-module-federation-enhanced-rsbuild.js';
|
package/dist/preset.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { withModuleFederation } from './src/utils/with-module-federation-enhanced-rsbuild.js';
|
|
2
|
+
export default {
|
|
3
|
+
rsbuildFinal: (config, options) => {
|
|
4
|
+
const { remotes, shared, name, shareStrategy } = options;
|
|
5
|
+
return withModuleFederation(config, {
|
|
6
|
+
name,
|
|
7
|
+
remotes,
|
|
8
|
+
shared,
|
|
9
|
+
shareStrategy,
|
|
10
|
+
});
|
|
11
|
+
},
|
|
12
|
+
};
|
|
13
|
+
export { PLUGIN_NAME } from './src/utils/with-module-federation-enhanced-rsbuild.js';
|
|
14
|
+
//# sourceMappingURL=preset.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"preset.js","sourceRoot":"","sources":["../preset.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,wDAAwD,CAAC;AAK9F,eAAe;IACb,YAAY,EAAE,CACZ,MAAqB,EACrB,OAA6D,EAC7D,EAAE;QACF,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,aAAa,EAAE,GAAG,OAAO,CAAC;QAEzD,OAAO,oBAAoB,CAAC,MAAM,EAAE;YAClC,IAAI;YACJ,OAAO;YACP,MAAM;YACN,aAAa;SACd,CAAC,CAAC;IACL,CAAC;CACF,CAAC;AACF,OAAO,EAAE,WAAW,EAAE,MAAM,wDAAwD,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './lib/storybook-addon.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,0BAA0B,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { type Configuration } from 'webpack';
|
|
2
|
+
import withModuleFederation from '../utils/with-module-federation.js';
|
|
3
|
+
import type { moduleFederationPlugin } from '@module-federation/sdk';
|
|
4
|
+
import type { ModuleFederationConfig } from '@nx/webpack';
|
|
5
|
+
export type Preset = string | {
|
|
6
|
+
name: string;
|
|
7
|
+
};
|
|
8
|
+
type Options = {
|
|
9
|
+
moduleFederationConfig?: moduleFederationPlugin.ModuleFederationPluginOptions;
|
|
10
|
+
nxModuleFederationConfig?: ModuleFederationConfig;
|
|
11
|
+
presets: {
|
|
12
|
+
apply<T>(preset: Preset): Promise<T>;
|
|
13
|
+
};
|
|
14
|
+
configDir: string;
|
|
15
|
+
};
|
|
16
|
+
export { withModuleFederation };
|
|
17
|
+
export declare const webpack: (webpackConfig: Configuration, options: Options) => Promise<Configuration>;
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import { dirname, join } from 'path';
|
|
3
|
+
import * as process from 'process';
|
|
4
|
+
import VirtualModulesPlugin from 'webpack-virtual-modules';
|
|
5
|
+
import { container, } from 'webpack';
|
|
6
|
+
import { normalizeStories } from '@storybook/core/common';
|
|
7
|
+
import withModuleFederation from '../utils/with-module-federation.js';
|
|
8
|
+
import { correctImportPath } from '../utils/correctImportPath.js';
|
|
9
|
+
// TODO: Only reserve `storybook/internal/node-logger` in next major release.
|
|
10
|
+
// Dynamic import for logger to support multiple Storybook versions
|
|
11
|
+
async function getLogger() {
|
|
12
|
+
try {
|
|
13
|
+
// Try high version first (since Storybook 9)
|
|
14
|
+
const mod = await import('storybook/internal/node-logger');
|
|
15
|
+
return mod.logger;
|
|
16
|
+
}
|
|
17
|
+
catch {
|
|
18
|
+
// Fallback to low version
|
|
19
|
+
const mod = await import('@storybook/node-logger');
|
|
20
|
+
return mod.logger;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
const { ModuleFederationPlugin } = container;
|
|
24
|
+
export { withModuleFederation };
|
|
25
|
+
export const webpack = async (webpackConfig, options) => {
|
|
26
|
+
const { plugins = [], context: webpackContext } = webpackConfig;
|
|
27
|
+
const { moduleFederationConfig, presets, nxModuleFederationConfig } = options;
|
|
28
|
+
const context = webpackContext || process.cwd();
|
|
29
|
+
// Get logger instance (supports multiple Storybook versions)
|
|
30
|
+
const logger = await getLogger();
|
|
31
|
+
// Detect webpack version. More about storybook webpack config https://storybook.js.org/docs/react/addons/writing-presets#webpack
|
|
32
|
+
const webpackVersion = await presets.apply('webpackVersion');
|
|
33
|
+
logger.info(`=> [MF] Webpack ${webpackVersion} version detected`);
|
|
34
|
+
if (webpackVersion !== '5') {
|
|
35
|
+
throw new Error('Webpack 5 required: Configure Storybook to use the webpack5 builder');
|
|
36
|
+
}
|
|
37
|
+
if (nxModuleFederationConfig) {
|
|
38
|
+
logger.info(`=> [MF] Detect NX configuration`);
|
|
39
|
+
const wmf = await withModuleFederation(nxModuleFederationConfig);
|
|
40
|
+
webpackConfig = {
|
|
41
|
+
...webpackConfig,
|
|
42
|
+
...wmf(webpackConfig),
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
if (moduleFederationConfig) {
|
|
46
|
+
logger.info(`=> [MF] Push Module Federation plugin`);
|
|
47
|
+
// @ts-ignore enhanced add new remoteType 'module-import'
|
|
48
|
+
plugins.push(new ModuleFederationPlugin(moduleFederationConfig));
|
|
49
|
+
}
|
|
50
|
+
const entries = await presets.apply('entries');
|
|
51
|
+
const bootstrap = entries.map((entryFile) => `import '${correctImportPath(context, entryFile)}';`);
|
|
52
|
+
const index = plugins.findIndex((plugin) => plugin?.constructor.name === 'VirtualModulesPlugin');
|
|
53
|
+
if (index !== -1) {
|
|
54
|
+
logger.info(`=> [MF] Detected plugin VirtualModulesPlugin`);
|
|
55
|
+
const plugin = plugins[index];
|
|
56
|
+
const virtualEntries = plugin.getModuleList('static');
|
|
57
|
+
const virtualEntriesPaths = Object.keys(virtualEntries);
|
|
58
|
+
logger.info(`=> [MF] Write files from VirtualModulesPlugin`);
|
|
59
|
+
for (const virtualEntryPath of virtualEntriesPaths) {
|
|
60
|
+
const nodeModulesPath = '/node_modules/';
|
|
61
|
+
const filePathFromProjectRootDir = virtualEntryPath.replace(context, '');
|
|
62
|
+
let sourceCode = virtualEntries[virtualEntryPath];
|
|
63
|
+
let finalPath = virtualEntryPath;
|
|
64
|
+
let finalDir = dirname(virtualEntryPath);
|
|
65
|
+
// If virtual file is not in directory node_modules, move file in directory node_modules/.cache/storybook
|
|
66
|
+
if (!filePathFromProjectRootDir.startsWith(nodeModulesPath)) {
|
|
67
|
+
finalPath = join(context, nodeModulesPath, '.cache', 'storybook', filePathFromProjectRootDir);
|
|
68
|
+
finalDir = dirname(finalPath);
|
|
69
|
+
// Fix storybook stories' path in virtual module
|
|
70
|
+
if (
|
|
71
|
+
// For storybook version before 7
|
|
72
|
+
filePathFromProjectRootDir === '/generated-stories-entry.cjs' ||
|
|
73
|
+
// For storybook version 7
|
|
74
|
+
filePathFromProjectRootDir === '/storybook-stories.js') {
|
|
75
|
+
const isStorybookVersion7 = filePathFromProjectRootDir === '/storybook-stories.js';
|
|
76
|
+
const nonNormalizedStories = await presets.apply('stories');
|
|
77
|
+
const stories = normalizeStories(nonNormalizedStories, {
|
|
78
|
+
configDir: options.configDir,
|
|
79
|
+
workingDir: context,
|
|
80
|
+
});
|
|
81
|
+
// For each story fix the import path
|
|
82
|
+
stories.forEach((story) => {
|
|
83
|
+
// Go up 3 times because the file was moved in /node_modules/.cache/storybook
|
|
84
|
+
const newDirectory = join('..', '..', '..', story.directory);
|
|
85
|
+
// Adding trailing slash for story directory in storybook v7
|
|
86
|
+
const oldSrc = isStorybookVersion7
|
|
87
|
+
? `'${story.directory}/'`
|
|
88
|
+
: `'${story.directory}'`;
|
|
89
|
+
const newSrc = isStorybookVersion7
|
|
90
|
+
? `'${newDirectory}/'`
|
|
91
|
+
: `'${newDirectory}'`;
|
|
92
|
+
// Fix story directory
|
|
93
|
+
sourceCode = sourceCode.replace(oldSrc, newSrc);
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
if (!fs.existsSync(finalDir)) {
|
|
98
|
+
fs.mkdirSync(finalDir, { recursive: true });
|
|
99
|
+
}
|
|
100
|
+
fs.writeFileSync(finalPath, sourceCode);
|
|
101
|
+
bootstrap.push(`import '${correctImportPath(context, finalPath)}';`);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Create a new VirtualModulesPlugin plugin to fix error "Shared module is not available for eager consumption"
|
|
106
|
+
* Entry file content is moved in bootstrap file. More details in the webpack documentation:
|
|
107
|
+
* https://webpack.js.org/concepts/module-federation/#uncaught-error-shared-module-is-not-available-for-eager-consumption
|
|
108
|
+
* */
|
|
109
|
+
const virtualModulePlugin = new VirtualModulesPlugin({
|
|
110
|
+
'./__entry.js': `import('./__bootstrap.js');`,
|
|
111
|
+
'./__bootstrap.js': bootstrap.join('\n'),
|
|
112
|
+
});
|
|
113
|
+
let action = 'Push';
|
|
114
|
+
if (index === -1) {
|
|
115
|
+
plugins.push(virtualModulePlugin);
|
|
116
|
+
}
|
|
117
|
+
else {
|
|
118
|
+
plugins[index] = virtualModulePlugin;
|
|
119
|
+
action = 'Replace';
|
|
120
|
+
}
|
|
121
|
+
logger.info(`=> [MF] ${action} plugin VirtualModulesPlugin to bootstrap entry point`);
|
|
122
|
+
return {
|
|
123
|
+
...webpackConfig,
|
|
124
|
+
entry: ['./__entry.js'],
|
|
125
|
+
plugins,
|
|
126
|
+
};
|
|
127
|
+
};
|
|
128
|
+
//# sourceMappingURL=storybook-addon.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"storybook-addon.js","sourceRoot":"","sources":["../../../src/lib/storybook-addon.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AACrC,OAAO,KAAK,OAAO,MAAM,SAAS,CAAC;AACnC,OAAO,oBAAoB,MAAM,yBAAyB,CAAC;AAC3D,OAAO,EACL,SAAS,GAGV,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,oBAAoB,MAAM,oCAAoC,CAAC;AACtE,OAAO,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AAElE,6EAA6E;AAC7E,mEAAmE;AACnE,KAAK,UAAU,SAAS;IACtB,IAAI,CAAC;QACH,6CAA6C;QAC7C,MAAM,GAAG,GAAG,MAAM,MAAM,CAAC,gCAAgC,CAAC,CAAC;QAC3D,OAAO,GAAG,CAAC,MAAM,CAAC;IACpB,CAAC;IAAC,MAAM,CAAC;QACP,0BAA0B;QAC1B,MAAM,GAAG,GAAG,MAAM,MAAM,CAAC,wBAAwB,CAAC,CAAC;QACnD,OAAO,GAAG,CAAC,MAAM,CAAC;IACpB,CAAC;AACH,CAAC;AAKD,MAAM,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AAC,IAAI,CAAC,CAAC;QACvE,CAAC;IACH,CAAC;IAED;;;;SAIK;IACL,MAAM,mBAAmB,GAAG,IAAI,oBAAoB,CAAC;QACnD,cAAc,EAAE,6BAA6B;QAC7C,kBAAkB,EAAE,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC;KACzC,CAAC,CAAC;IAEH,IAAI,MAAM,GAAG,MAAM,CAAC;IACpB,IAAI,KAAK,KAAK,CAAC,CAAC,EAAE,CAAC;QACjB,OAAO,CAAC,IAAI,CAAC,mBAAuD,CAAC,CAAC;IACxE,CAAC;SAAM,CAAC;QACN,OAAO,CAAC,KAAK,CAAC,GAAG,mBAAuD,CAAC;QACzE,MAAM,GAAG,SAAS,CAAC;IACrB,CAAC;IACD,MAAM,CAAC,IAAI,CACT,WAAW,MAAM,uDAAuD,CACzE,CAAC;IAEF,OAAO;QACL,GAAG,aAAa;QAChB,KAAK,EAAE,CAAC,cAAc,CAAC;QACvB,OAAO;KACR,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const correctImportPath: (context: string, entryFile: string) => any;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export const correctImportPath = (context, entryFile) => {
|
|
2
|
+
if (typeof process !== 'undefined') {
|
|
3
|
+
if (process?.platform !== 'win32') {
|
|
4
|
+
return entryFile;
|
|
5
|
+
}
|
|
6
|
+
if (entryFile.match(/^\.?\.\\/) || !entryFile.match(/^[A-Z]:\\\\/i)) {
|
|
7
|
+
return entryFile.replace(/\\/g, '/');
|
|
8
|
+
}
|
|
9
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
10
|
+
const path = require('path');
|
|
11
|
+
const joint = path.win32.relative(context, entryFile);
|
|
12
|
+
const relative = joint.replace(/\\/g, '/');
|
|
13
|
+
if (relative.includes('node_modules/')) {
|
|
14
|
+
return relative.split('node_modules/')[1];
|
|
15
|
+
}
|
|
16
|
+
return `./${relative}`;
|
|
17
|
+
}
|
|
18
|
+
return null;
|
|
19
|
+
};
|
|
20
|
+
//# sourceMappingURL=correctImportPath.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"correctImportPath.js","sourceRoot":"","sources":["../../../src/utils/correctImportPath.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,OAAe,EAAE,SAAiB,EAAE,EAAE;IACtE,IAAI,OAAO,OAAO,KAAK,WAAW,EAAE,CAAC;QACnC,IAAI,OAAO,EAAE,QAAQ,KAAK,OAAO,EAAE,CAAC;YAClC,OAAO,SAAS,CAAC;QACnB,CAAC;QAED,IAAI,SAAS,CAAC,KAAK,CAAC,UAAU,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,cAAc,CAAC,EAAE,CAAC;YACpE,OAAO,SAAS,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;QACvC,CAAC;QAED,8DAA8D;QAC9D,MAAM,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;QAC7B,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC;QACtD,MAAM,QAAQ,GAAG,KAAK,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;QAE3C,IAAI,QAAQ,CAAC,QAAQ,CAAC,eAAe,CAAC,EAAE,CAAC;YACvC,OAAO,QAAQ,CAAC,KAAK,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,CAAC;QAC5C,CAAC;QAED,OAAO,KAAK,QAAQ,EAAE,CAAC;IACzB,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { RsbuildConfig } from '@rsbuild/core';
|
|
2
|
+
import type { moduleFederationPlugin } from '@module-federation/sdk';
|
|
3
|
+
export declare const PLUGIN_NAME = "module-federation-storybook-addon";
|
|
4
|
+
export declare const withModuleFederation: (rsbuildConfig: RsbuildConfig, options: moduleFederationPlugin.ModuleFederationPluginOptions) => RsbuildConfig;
|
|
5
|
+
export default withModuleFederation;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { ModuleFederationPlugin } from '@module-federation/enhanced/rspack';
|
|
4
|
+
import { TEMP_DIR } from '@module-federation/sdk';
|
|
5
|
+
import { correctImportPath } from './correctImportPath.js';
|
|
6
|
+
const tempDirPath = path.resolve(process.cwd(), `node_modules/${TEMP_DIR}`);
|
|
7
|
+
export const PLUGIN_NAME = 'module-federation-storybook-addon';
|
|
8
|
+
// add bootstrap for host project
|
|
9
|
+
const bootstrapPath = path.resolve(process.cwd(), `node_modules/${TEMP_DIR}/storybook-bootstrap.js`);
|
|
10
|
+
const generateBootstrap = (context, entryPath) => {
|
|
11
|
+
return `import('${correctImportPath(context, entryPath)}');`;
|
|
12
|
+
};
|
|
13
|
+
const writeBootstrap = (context, entryPath) => {
|
|
14
|
+
if (!fs.existsSync(tempDirPath)) {
|
|
15
|
+
fs.mkdirSync(tempDirPath);
|
|
16
|
+
}
|
|
17
|
+
if (fs.existsSync(bootstrapPath)) {
|
|
18
|
+
fs.unlinkSync(bootstrapPath);
|
|
19
|
+
}
|
|
20
|
+
fs.writeFileSync(bootstrapPath, generateBootstrap(context, entryPath));
|
|
21
|
+
};
|
|
22
|
+
export const withModuleFederation = (rsbuildConfig, options) => {
|
|
23
|
+
rsbuildConfig.plugins ??= [];
|
|
24
|
+
rsbuildConfig.source ??= {};
|
|
25
|
+
rsbuildConfig.source.entry ??= {};
|
|
26
|
+
const entry = rsbuildConfig.source.entry;
|
|
27
|
+
const context = rsbuildConfig.root || process.cwd();
|
|
28
|
+
for (const entryName in entry) {
|
|
29
|
+
if (Array.isArray(entry[entryName])) {
|
|
30
|
+
writeBootstrap(context, entry[entryName][0]);
|
|
31
|
+
entry[entryName] = [bootstrapPath];
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
const rsbuildPlugin = {
|
|
35
|
+
name: 'module-federation-storybook-plugin',
|
|
36
|
+
setup: function (api) {
|
|
37
|
+
api.modifyRsbuildConfig((config, { mergeRsbuildConfig }) => {
|
|
38
|
+
const mfConfig = {
|
|
39
|
+
dev: {
|
|
40
|
+
// remoteEntry already includes one hmr runtime, and an additional one is not necessary.
|
|
41
|
+
hmr: false,
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
return mergeRsbuildConfig(config, mfConfig);
|
|
45
|
+
});
|
|
46
|
+
api.modifyBundlerChain(async (chain) => {
|
|
47
|
+
chain.plugin(PLUGIN_NAME).use(ModuleFederationPlugin, [
|
|
48
|
+
{
|
|
49
|
+
name: options.name || PLUGIN_NAME,
|
|
50
|
+
shared: {
|
|
51
|
+
react: {
|
|
52
|
+
singleton: true,
|
|
53
|
+
},
|
|
54
|
+
'react-dom': {
|
|
55
|
+
singleton: true,
|
|
56
|
+
},
|
|
57
|
+
...options.shared,
|
|
58
|
+
},
|
|
59
|
+
remotes: {
|
|
60
|
+
...options.remotes,
|
|
61
|
+
},
|
|
62
|
+
shareStrategy: options.shareStrategy,
|
|
63
|
+
},
|
|
64
|
+
]);
|
|
65
|
+
});
|
|
66
|
+
},
|
|
67
|
+
};
|
|
68
|
+
rsbuildConfig.plugins.push(rsbuildPlugin);
|
|
69
|
+
return rsbuildConfig;
|
|
70
|
+
};
|
|
71
|
+
export default withModuleFederation;
|
|
72
|
+
//# sourceMappingURL=with-module-federation-enhanced-rsbuild.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"with-module-federation-enhanced-rsbuild.js","sourceRoot":"","sources":["../../../src/utils/with-module-federation-enhanced-rsbuild.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,sBAAsB,EAAE,MAAM,oCAAo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C,CAAC;QACL,CAAC;KACF,CAAC;IAEF,aAAa,CAAC,OAAO,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;IAC1C,OAAO,aAAa,CAAC;AACvB,CAAC,CAAC;AAEF,eAAe,oBAAoB,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { getModuleFederationConfig } from '@nx/module-federation/src/with-module-federation/webpack/utils';
|
|
2
|
+
import { container } from 'webpack';
|
|
3
|
+
const { ModuleFederationPlugin } = container;
|
|
4
|
+
const updateMappedRemotes = (remotes) => {
|
|
5
|
+
const newRemotes = {};
|
|
6
|
+
Object.keys(remotes).forEach((key) => {
|
|
7
|
+
newRemotes[key] = `${key}@${remotes[key]}`;
|
|
8
|
+
});
|
|
9
|
+
return newRemotes;
|
|
10
|
+
};
|
|
11
|
+
const withModuleFederation = async (options) => {
|
|
12
|
+
const { mappedRemotes, sharedDependencies } = await getModuleFederationConfig(options);
|
|
13
|
+
return (config) => {
|
|
14
|
+
config.experiments = { outputModule: false };
|
|
15
|
+
config.optimization = {
|
|
16
|
+
runtimeChunk: false,
|
|
17
|
+
};
|
|
18
|
+
config.output = {
|
|
19
|
+
publicPath: 'auto',
|
|
20
|
+
};
|
|
21
|
+
config.plugins = config.plugins || [];
|
|
22
|
+
config.plugins.push(new ModuleFederationPlugin({
|
|
23
|
+
name: options.name,
|
|
24
|
+
filename: 'remoteEntry.js',
|
|
25
|
+
shared: sharedDependencies,
|
|
26
|
+
exposes: options.exposes,
|
|
27
|
+
remotes: updateMappedRemotes(mappedRemotes),
|
|
28
|
+
}));
|
|
29
|
+
return config;
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
export default withModuleFederation;
|
|
33
|
+
//# sourceMappingURL=with-module-federation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"with-module-federation.js","sourceRoot":"","sources":["../../../src/utils/with-module-federation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,M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eAAe,oBAAoB,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@module-federation/storybook-addon",
|
|
3
|
+
"version": "0.0.0-docs-remove-invalid-lark-link-20251205062649",
|
|
4
|
+
"description": "Storybook addon to consume remote module federated apps/components",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/module-federation/core.git",
|
|
10
|
+
"directory": "packages/storybook-addon"
|
|
11
|
+
},
|
|
12
|
+
"publishConfig": {
|
|
13
|
+
"access": "public"
|
|
14
|
+
},
|
|
15
|
+
"keywords": [
|
|
16
|
+
"module-federation",
|
|
17
|
+
"typescript",
|
|
18
|
+
"storybook",
|
|
19
|
+
"rsbuild",
|
|
20
|
+
"storybook-rsbuild",
|
|
21
|
+
"addon"
|
|
22
|
+
],
|
|
23
|
+
"files": [
|
|
24
|
+
"dist/",
|
|
25
|
+
"README.md"
|
|
26
|
+
],
|
|
27
|
+
"author": "Fiodorov Andrei <hello@fyodorovandrei.com> (https://github.com/fyodorovandrei)",
|
|
28
|
+
"main": "dist/src/index.js",
|
|
29
|
+
"types": "dist/src/index.d.ts",
|
|
30
|
+
"exports": {
|
|
31
|
+
".": {
|
|
32
|
+
"types": "./dist/src/index.d.ts",
|
|
33
|
+
"default": "./dist/src/index.js"
|
|
34
|
+
},
|
|
35
|
+
"./preset": {
|
|
36
|
+
"types": "./dist/preset.d.ts",
|
|
37
|
+
"default": "./dist/preset.js"
|
|
38
|
+
},
|
|
39
|
+
"./*": "./*"
|
|
40
|
+
},
|
|
41
|
+
"typesVersions": {
|
|
42
|
+
"*": {
|
|
43
|
+
".": [
|
|
44
|
+
"./dist/index.d.ts"
|
|
45
|
+
],
|
|
46
|
+
"preset": [
|
|
47
|
+
"./dist/preset.d.ts"
|
|
48
|
+
]
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
"dependencies": {
|
|
52
|
+
"@module-federation/enhanced": "0.0.0-docs-remove-invalid-lark-link-20251205062649",
|
|
53
|
+
"@module-federation/sdk": "0.0.0-docs-remove-invalid-lark-link-20251205062649"
|
|
54
|
+
},
|
|
55
|
+
"devDependencies": {
|
|
56
|
+
"jest-fixed-jsdom": "^0.0.9",
|
|
57
|
+
"@rsbuild/core": "^1.3.21",
|
|
58
|
+
"@storybook/node-logger": "7.6.20",
|
|
59
|
+
"@storybook/core": "^8.4.6",
|
|
60
|
+
"webpack": "5.94.0",
|
|
61
|
+
"webpack-virtual-modules": "0.6.2",
|
|
62
|
+
"@module-federation/utilities": "0.0.0-docs-remove-invalid-lark-link-20251205062649"
|
|
63
|
+
},
|
|
64
|
+
"peerDependencies": {
|
|
65
|
+
"@rsbuild/core": "^1.0.1",
|
|
66
|
+
"@module-federation/sdk": "0.0.0-docs-remove-invalid-lark-link-20251205062649",
|
|
67
|
+
"@nx/react": ">= 16.0.0",
|
|
68
|
+
"@nx/webpack": ">= 16.0.0",
|
|
69
|
+
"@storybook/core": ">= 8.2.0",
|
|
70
|
+
"@storybook/node-logger": "^6.5.16 || ^7.0.0 || ^8.0.0",
|
|
71
|
+
"webpack": "^5.75.0",
|
|
72
|
+
"webpack-virtual-modules": "0.6.2"
|
|
73
|
+
},
|
|
74
|
+
"peerDependenciesMeta": {
|
|
75
|
+
"@rsbuild/core": {
|
|
76
|
+
"optional": true
|
|
77
|
+
},
|
|
78
|
+
"@module-federation/sdk": {
|
|
79
|
+
"optional": true
|
|
80
|
+
},
|
|
81
|
+
"@nx/react": {
|
|
82
|
+
"optional": true
|
|
83
|
+
},
|
|
84
|
+
"@nx/webpack": {
|
|
85
|
+
"optional": true
|
|
86
|
+
},
|
|
87
|
+
"@storybook/core": {
|
|
88
|
+
"optional": true
|
|
89
|
+
},
|
|
90
|
+
"@storybook/node-logger": {
|
|
91
|
+
"optional": true
|
|
92
|
+
},
|
|
93
|
+
"webpack": {
|
|
94
|
+
"optional": true
|
|
95
|
+
},
|
|
96
|
+
"webpack-virtual-modules": {
|
|
97
|
+
"optional": true
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|