@module-federation/storybook-addon 0.1.0
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/CHANGELOG.md +56 -0
- package/README.md +133 -0
- package/package.json +40 -0
- package/src/index.d.ts +1 -0
- package/src/index.js +5 -0
- package/src/index.js.map +1 -0
- package/src/lib/storybook-addon.d.ts +17 -0
- package/src/lib/storybook-addon.js +105 -0
- package/src/lib/storybook-addon.js.map +1 -0
- package/src/utils/with-module-federation.d.ts +4 -0
- package/src/utils/with-module-federation.js +47 -0
- package/src/utils/with-module-federation.js.map +1 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
This file was generated using [@jscutlery/semver](https://github.com/jscutlery/semver).
|
|
4
|
+
|
|
5
|
+
# 0.1.0 (2023-04-27)
|
|
6
|
+
|
|
7
|
+
### Dependency Updates
|
|
8
|
+
|
|
9
|
+
* `utils` updated to version `1.7.0`
|
|
10
|
+
* `utils` updated to version `1.7.0`
|
|
11
|
+
|
|
12
|
+
### Bug Fixes
|
|
13
|
+
|
|
14
|
+
* add release tooling to storybook addon ([43c66bb](https://github.com/module-federation/nextjs-mf/commit/43c66bbc10af8198e908d35ffde7b7dc0058f9cb))
|
|
15
|
+
* add release tooling to storybook addon ([#817](https://github.com/module-federation/nextjs-mf/issues/817)) ([63d27a8](https://github.com/module-federation/nextjs-mf/commit/63d27a8067a0734d04677948b50454b6704dc387))
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
### Features
|
|
19
|
+
|
|
20
|
+
* add storybook addon that supports Module Federation remote containers ([#598](https://github.com/module-federation/nextjs-mf/issues/598)) ([7547b02](https://github.com/module-federation/nextjs-mf/commit/7547b02937fdef2831060d6a7bfd337d2cc3355c))
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
# 0.1.0 (2023-04-27)
|
|
25
|
+
|
|
26
|
+
### Dependency Updates
|
|
27
|
+
|
|
28
|
+
* `utils` updated to version `1.7.0`
|
|
29
|
+
* `utils` updated to version `1.7.0`
|
|
30
|
+
|
|
31
|
+
### Bug Fixes
|
|
32
|
+
|
|
33
|
+
* add release tooling to storybook addon ([#817](https://github.com/module-federation/nextjs-mf/issues/817)) ([63d27a8](https://github.com/module-federation/nextjs-mf/commit/63d27a8067a0734d04677948b50454b6704dc387))
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
### Features
|
|
37
|
+
|
|
38
|
+
* add storybook addon that supports Module Federation remote containers ([#598](https://github.com/module-federation/nextjs-mf/issues/598)) ([7547b02](https://github.com/module-federation/nextjs-mf/commit/7547b02937fdef2831060d6a7bfd337d2cc3355c))
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
# 0.1.0 (2023-04-27)
|
|
43
|
+
|
|
44
|
+
### Dependency Updates
|
|
45
|
+
|
|
46
|
+
* `utils` updated to version `1.7.0`
|
|
47
|
+
* `utils` updated to version `1.7.0`
|
|
48
|
+
|
|
49
|
+
### Bug Fixes
|
|
50
|
+
|
|
51
|
+
* add release tooling to storybook addon ([#817](https://github.com/module-federation/nextjs-mf/issues/817)) ([63d27a8](https://github.com/module-federation/nextjs-mf/commit/63d27a8067a0734d04677948b50454b6704dc387))
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
### Features
|
|
55
|
+
|
|
56
|
+
* add storybook addon that supports Module Federation remote containers ([#598](https://github.com/module-federation/nextjs-mf/issues/598)) ([7547b02](https://github.com/module-federation/nextjs-mf/commit/7547b02937fdef2831060d6a7bfd337d2cc3355c))
|
package/README.md
ADDED
|
@@ -0,0 +1,133 @@
|
|
|
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
|
+
```js
|
|
19
|
+
const moduleFederationConfig = {
|
|
20
|
+
// Module Federation config
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
const storybookConfig = {
|
|
24
|
+
"stories": [
|
|
25
|
+
"../src/**/*.stories.mdx",
|
|
26
|
+
"../src/**/*.stories.@(js|jsx|ts|tsx)"
|
|
27
|
+
],
|
|
28
|
+
"addons": [
|
|
29
|
+
// other addons,
|
|
30
|
+
{
|
|
31
|
+
name: "@module-federation/storybook-addon",
|
|
32
|
+
options: {
|
|
33
|
+
moduleFederationConfig
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
],
|
|
37
|
+
"framework": "@storybook/react",
|
|
38
|
+
"core": {
|
|
39
|
+
"builder": "@storybook/builder-webpack5" // is required webpack 5 builder
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
module.exports = storybookConfig;
|
|
44
|
+
```
|
|
45
|
+
---
|
|
46
|
+
### For the [NX](https://nx.dev/getting-started/intro) projects:
|
|
47
|
+
|
|
48
|
+
Replace NX utils `withModuleFederation` in `webpack.config.js` with our utils `withModuleFederation`.
|
|
49
|
+
Example:
|
|
50
|
+
```javascript
|
|
51
|
+
const { composePlugins, withNx } = require('@nrwl/webpack');
|
|
52
|
+
const { withReact } = require('@nrwl/react');
|
|
53
|
+
const { withModuleFederation } = require('@module-federation/storybook-addon');
|
|
54
|
+
|
|
55
|
+
const baseConfig = require('./module-federation.config');
|
|
56
|
+
|
|
57
|
+
const config = {
|
|
58
|
+
...baseConfig,
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
module.exports = composePlugins(
|
|
62
|
+
withNx(),
|
|
63
|
+
withReact(),
|
|
64
|
+
withModuleFederation(config)
|
|
65
|
+
);
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
In file `./storybook/main.js`:
|
|
69
|
+
```js
|
|
70
|
+
const nxModuleFederationConfig = {
|
|
71
|
+
// Module Federation config
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
const storybookConfig = {
|
|
75
|
+
"stories": [
|
|
76
|
+
"../src/**/*.stories.mdx",
|
|
77
|
+
"../src/**/*.stories.@(js|jsx|ts|tsx)"
|
|
78
|
+
],
|
|
79
|
+
"addons": [
|
|
80
|
+
// other addons,
|
|
81
|
+
{
|
|
82
|
+
name: "@module-federation/storybook-addon",
|
|
83
|
+
options: {
|
|
84
|
+
nxModuleFederationConfig
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
],
|
|
88
|
+
"framework": "@storybook/react",
|
|
89
|
+
"core": {
|
|
90
|
+
"builder": "@storybook/builder-webpack5" // is required webpack 5 builder
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
module.exports = storybookConfig;
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
## Usage
|
|
98
|
+
|
|
99
|
+
```jsx
|
|
100
|
+
import React, { Suspense } from 'react';
|
|
101
|
+
|
|
102
|
+
const LazyButton = React.lazy(() => import('remote/Button'));
|
|
103
|
+
|
|
104
|
+
const Button = (props) => (
|
|
105
|
+
<Suspense fallback={<p>Please wait...</p>}><LazyButton {...props} /></Suspense>
|
|
106
|
+
);
|
|
107
|
+
|
|
108
|
+
export default {
|
|
109
|
+
title: 'ModuleFederation/Button',
|
|
110
|
+
component: Button,
|
|
111
|
+
argTypes: {
|
|
112
|
+
variant: {
|
|
113
|
+
control: 'select',
|
|
114
|
+
options: ['primary', 'secondary']
|
|
115
|
+
},
|
|
116
|
+
},
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
const Template = (args) => <Button {...args} />;
|
|
120
|
+
|
|
121
|
+
export const Primary = Template.bind({variant: 'primary'});
|
|
122
|
+
Primary.args = {
|
|
123
|
+
variant: 'primary',
|
|
124
|
+
children: 'Button',
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
export const Secondary = Template.bind({});
|
|
128
|
+
Secondary.args = {
|
|
129
|
+
variant: 'secondary',
|
|
130
|
+
children: 'Button',
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
```
|
package/package.json
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@module-federation/storybook-addon",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Storybook addon to consume remote module federated apps/components",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": "https://github.com/module-federation/universe/tree/main/packages/storybook-addon",
|
|
7
|
+
"publishConfig": {
|
|
8
|
+
"registry": "https://registry.npmjs.org/"
|
|
9
|
+
},
|
|
10
|
+
"keywords": [
|
|
11
|
+
"module-federation",
|
|
12
|
+
"typescript",
|
|
13
|
+
"storybook",
|
|
14
|
+
"addon"
|
|
15
|
+
],
|
|
16
|
+
"author": "Fiodorov Andrei <hello@fyodorovandrei.com> (https://github.com/fyodorovandrei)",
|
|
17
|
+
"devDependencies": {
|
|
18
|
+
"@module-federation/utilities": "1.6.0",
|
|
19
|
+
"@storybook/core-common": "^6.5.16",
|
|
20
|
+
"@storybook/node-logger": "^6.5.16",
|
|
21
|
+
"webpack": "^5.75.0",
|
|
22
|
+
"webpack-virtual-modules": "^0.5.0"
|
|
23
|
+
},
|
|
24
|
+
"peerDependencies": {
|
|
25
|
+
"@module-federation/utilities": "1.6.0",
|
|
26
|
+
"@storybook/core-common": "^6.5.16",
|
|
27
|
+
"@storybook/node-logger": "^6.5.16",
|
|
28
|
+
"webpack": "^5.75.0",
|
|
29
|
+
"webpack-virtual-modules": "^0.5.0"
|
|
30
|
+
},
|
|
31
|
+
"dependencies": {
|
|
32
|
+
"@nrwl/devkit": "15.9.2",
|
|
33
|
+
"next": "13.3.0",
|
|
34
|
+
"process": "0.11.10",
|
|
35
|
+
"react": "18.2.0",
|
|
36
|
+
"react-dom": "18.2.0"
|
|
37
|
+
},
|
|
38
|
+
"main": "./src/index.js",
|
|
39
|
+
"types": "./src/index.d.ts"
|
|
40
|
+
}
|
package/src/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './lib/storybook-addon';
|
package/src/index.js
ADDED
package/src/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../packages/storybook-addon/src/index.ts"],"names":[],"mappings":";;;AAAA,gEAAsC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Configuration } from 'webpack';
|
|
2
|
+
import { ModuleFederationPluginOptions } from '@module-federation/utilities';
|
|
3
|
+
import type { ModuleFederationConfig } from '@nrwl/devkit';
|
|
4
|
+
import withModuleFederation from '../utils/with-module-federation';
|
|
5
|
+
export type Preset = string | {
|
|
6
|
+
name: string;
|
|
7
|
+
};
|
|
8
|
+
type Options = {
|
|
9
|
+
moduleFederationConfig?: 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,105 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.webpack = exports.withModuleFederation = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const fs_1 = tslib_1.__importDefault(require("fs"));
|
|
6
|
+
const path_1 = require("path");
|
|
7
|
+
const process = tslib_1.__importStar(require("process"));
|
|
8
|
+
const webpack_virtual_modules_1 = tslib_1.__importDefault(require("webpack-virtual-modules"));
|
|
9
|
+
const webpack_1 = require("webpack");
|
|
10
|
+
const node_logger_1 = require("@storybook/node-logger");
|
|
11
|
+
const core_common_1 = require("@storybook/core-common");
|
|
12
|
+
const utilities_1 = require("@module-federation/utilities");
|
|
13
|
+
const with_module_federation_1 = tslib_1.__importDefault(require("../utils/with-module-federation"));
|
|
14
|
+
exports.withModuleFederation = with_module_federation_1.default;
|
|
15
|
+
const { ModuleFederationPlugin } = webpack_1.container;
|
|
16
|
+
const webpack = async (webpackConfig, options) => {
|
|
17
|
+
const { plugins = [], context: webpackContext } = webpackConfig;
|
|
18
|
+
const { moduleFederationConfig, presets, nxModuleFederationConfig } = options;
|
|
19
|
+
const context = webpackContext || process.cwd();
|
|
20
|
+
// Detect webpack version. More about storybook webpack config https://storybook.js.org/docs/react/addons/writing-presets#webpack
|
|
21
|
+
const webpackVersion = await presets.apply('webpackVersion');
|
|
22
|
+
node_logger_1.logger.info(`=> [MF] Webpack ${webpackVersion} version detected`);
|
|
23
|
+
if (webpackVersion !== '5') {
|
|
24
|
+
throw new Error('Webpack 5 required: Configure Storybook to use the webpack5 builder');
|
|
25
|
+
}
|
|
26
|
+
if (nxModuleFederationConfig) {
|
|
27
|
+
node_logger_1.logger.info(`=> [MF] Detect NX configuration`);
|
|
28
|
+
const wmf = await (0, with_module_federation_1.default)(nxModuleFederationConfig);
|
|
29
|
+
webpackConfig = {
|
|
30
|
+
...webpackConfig,
|
|
31
|
+
...wmf(webpackConfig),
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
if (moduleFederationConfig) {
|
|
35
|
+
node_logger_1.logger.info(`=> [MF] Push Module Federation plugin`);
|
|
36
|
+
plugins.push(new ModuleFederationPlugin(moduleFederationConfig));
|
|
37
|
+
}
|
|
38
|
+
const entries = await presets.apply('entries');
|
|
39
|
+
const bootstrap = entries.map((entryFile) => `import '${(0, utilities_1.correctImportPath)(context, entryFile)}';`);
|
|
40
|
+
const index = plugins.findIndex((plugin) => plugin.constructor.name === 'VirtualModulesPlugin');
|
|
41
|
+
if (index !== -1) {
|
|
42
|
+
node_logger_1.logger.info(`=> [MF] Detected plugin VirtualModulesPlugin`);
|
|
43
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
44
|
+
const plugin = plugins[index];
|
|
45
|
+
const virtualEntries = plugin._staticModules; // TODO: Exist another way to get virtual modules? Or maybe it's good idea to open a PR adding a method to get modules?
|
|
46
|
+
const virtualEntriesPaths = Object.keys(virtualEntries);
|
|
47
|
+
node_logger_1.logger.info(`=> [MF] Write files from VirtualModulesPlugin`);
|
|
48
|
+
for (const virtualEntryPath of virtualEntriesPaths) {
|
|
49
|
+
const nodeModulesPath = '/node_modules/';
|
|
50
|
+
const filePathFromProjectRootDir = virtualEntryPath.replace(context, '');
|
|
51
|
+
let sourceCode = virtualEntries[virtualEntryPath];
|
|
52
|
+
let finalPath = virtualEntryPath;
|
|
53
|
+
let finalDir = (0, path_1.dirname)(virtualEntryPath);
|
|
54
|
+
// If virtual file is not in directory node_modules, move file in directory node_modules/.cache/storybook
|
|
55
|
+
if (!filePathFromProjectRootDir.startsWith(nodeModulesPath)) {
|
|
56
|
+
finalPath = (0, path_1.join)(context, nodeModulesPath, '.cache', 'storybook', filePathFromProjectRootDir);
|
|
57
|
+
finalDir = (0, path_1.dirname)(finalPath);
|
|
58
|
+
// Fix storybook stories' path in virtual module `generated-stories-entry.cjs`
|
|
59
|
+
if (filePathFromProjectRootDir === '/generated-stories-entry.cjs') {
|
|
60
|
+
const nonNormalizedStories = await presets.apply('stories');
|
|
61
|
+
const stories = (0, core_common_1.normalizeStories)(nonNormalizedStories, {
|
|
62
|
+
configDir: options.configDir,
|
|
63
|
+
workingDir: context,
|
|
64
|
+
});
|
|
65
|
+
// For each story fix the import path
|
|
66
|
+
stories.forEach((story) => {
|
|
67
|
+
// Go up 3 times because the file was moved in /node_modules/.cache/storybook
|
|
68
|
+
const newDirectory = (0, path_1.join)('..', '..', '..', story.directory);
|
|
69
|
+
sourceCode = sourceCode.replace(`'${story.directory}'`, `'${newDirectory}'`);
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
if (!fs_1.default.existsSync(finalDir)) {
|
|
74
|
+
fs_1.default.mkdirSync(finalDir, { recursive: true });
|
|
75
|
+
}
|
|
76
|
+
fs_1.default.writeFileSync(finalPath, sourceCode);
|
|
77
|
+
bootstrap.push(`import '${(0, utilities_1.correctImportPath)(context, finalPath)}';`);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Create a new VirtualModulesPlugin plugin to fix error "Shared module is not available for eager consumption"
|
|
82
|
+
* Entry file content is moved in bootstrap file. More details in the webpack documentation:
|
|
83
|
+
* https://webpack.js.org/concepts/module-federation/#uncaught-error-shared-module-is-not-available-for-eager-consumption
|
|
84
|
+
* */
|
|
85
|
+
const virtualModulePlugin = new webpack_virtual_modules_1.default({
|
|
86
|
+
'./__entry.js': `import('./__bootstrap.js');`,
|
|
87
|
+
'./__bootstrap.js': bootstrap.join('\n'),
|
|
88
|
+
});
|
|
89
|
+
let action = 'Push';
|
|
90
|
+
if (index === -1) {
|
|
91
|
+
plugins.push(virtualModulePlugin);
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
plugins[index] = virtualModulePlugin;
|
|
95
|
+
action = 'Replace';
|
|
96
|
+
}
|
|
97
|
+
node_logger_1.logger.info(`=> [MF] ${action} plugin VirtualModulesPlugin to bootstrap entry point`);
|
|
98
|
+
return {
|
|
99
|
+
...webpackConfig,
|
|
100
|
+
entry: ['./__entry.js'],
|
|
101
|
+
plugins,
|
|
102
|
+
};
|
|
103
|
+
};
|
|
104
|
+
exports.webpack = webpack;
|
|
105
|
+
//# sourceMappingURL=storybook-addon.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"storybook-addon.js","sourceRoot":"","sources":["../../../../../packages/storybook-addon/src/lib/storybook-addon.ts"],"names":[],"mappings":";;;;AAAA,oDAAoB;AACpB,+BAAqC;AACrC,yDAAmC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QACrC,MAAM,GAAG,SAAS,CAAC;KACpB;IACD,oBAAM,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;AA9HW,QAAA,OAAO,WA8HlB"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const utils_1 = require("@nrwl/react/src/module-federation/utils");
|
|
4
|
+
const project_graph_1 = require("nx/src/project-graph/project-graph");
|
|
5
|
+
const webpack_1 = require("webpack");
|
|
6
|
+
const { ModuleFederationPlugin } = webpack_1.container;
|
|
7
|
+
function determineRemoteUrl(remote) {
|
|
8
|
+
const remoteConfiguration = (0, project_graph_1.readCachedProjectConfiguration)(remote);
|
|
9
|
+
const serveTarget = remoteConfiguration?.targets?.['serve'];
|
|
10
|
+
if (!serveTarget) {
|
|
11
|
+
throw new Error(`Cannot automatically determine URL of remote (${remote}). Looked for property "host" in the project's "serve" target.\n
|
|
12
|
+
You can also use the tuple syntax in your webpack config to configure your remotes. e.g. \`remotes: [['remote1', 'http://localhost:4201']]\``);
|
|
13
|
+
}
|
|
14
|
+
const host = serveTarget.options?.host ?? 'http://localhost';
|
|
15
|
+
const port = serveTarget.options?.port ?? 4201;
|
|
16
|
+
return `${host.endsWith('/') ? host.slice(0, -1) : host}:${port}/remoteEntry.js`;
|
|
17
|
+
}
|
|
18
|
+
const updateMappedRemotes = (remotes) => {
|
|
19
|
+
const newRemotes = {};
|
|
20
|
+
Object.keys(remotes).forEach((key) => {
|
|
21
|
+
newRemotes[key] = `${key}@${remotes[key]}`;
|
|
22
|
+
});
|
|
23
|
+
return newRemotes;
|
|
24
|
+
};
|
|
25
|
+
const withModuleFederation = async (options) => {
|
|
26
|
+
const { mappedRemotes, sharedDependencies } = await (0, utils_1.getModuleFederationConfig)(options, determineRemoteUrl);
|
|
27
|
+
return (config) => {
|
|
28
|
+
config.experiments = { outputModule: false };
|
|
29
|
+
config.optimization = {
|
|
30
|
+
runtimeChunk: false,
|
|
31
|
+
};
|
|
32
|
+
config.output = {
|
|
33
|
+
publicPath: 'auto',
|
|
34
|
+
};
|
|
35
|
+
config.plugins = config.plugins || [];
|
|
36
|
+
config.plugins.push(new ModuleFederationPlugin({
|
|
37
|
+
name: options.name,
|
|
38
|
+
filename: 'remoteEntry.js',
|
|
39
|
+
shared: sharedDependencies,
|
|
40
|
+
exposes: options.exposes,
|
|
41
|
+
remotes: updateMappedRemotes(mappedRemotes),
|
|
42
|
+
}));
|
|
43
|
+
return config;
|
|
44
|
+
};
|
|
45
|
+
};
|
|
46
|
+
exports.default = withModuleFederation;
|
|
47
|
+
//# sourceMappingURL=with-module-federation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"with-module-federation.js","sourceRoot":"","sources":["../../../../../packages/storybook-addon/src/utils/with-module-federation.ts"],"names":[],"mappings":";;AAAA,mEAAoF;AACpF,sEAAoF;AACpF,qCAAmD;AAGnD,MAAM,EAAE,sBAAsB,EAAE,GAAG,mBAAS,CAAC;AAE7C,SAAS,kBAAkB,CAAC,MAAc;IACxC,MAAM,mBAAmB,GAAG,IAAA,8CAA8B,EAAC,MAAM,CAAC,CAAC;IACnE,MAAM,WAAW,GAAG,mBAAmB,EAAE,OAAO,EAAE,CAAC,OAAO,CAAC,CAAC;IAE5D,IAAI,CAAC,WAAW,EAAE;QAChB,MAAM,IAAI,KAAK,CACb,iDAAiD,MAAM;mJACsF,CAC9I,CAAC;KACH;IAED,MAAM,IAAI,GAAG,WAAW,CAAC,OAAO,EAAE,IAAI,IAAI,kBAAkB,CAAC;IAC7D,MAAM,IAAI,GAAG,WAAW,CAAC,OAAO,EAAE,IAAI,IAAI,IAAI,CAAC;IAC/C,OAAO,GACL,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,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