create-module-federation 0.0.0-1737428758075 → 0.0.0-next-20250305075427

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.
Files changed (48) hide show
  1. package/dist/index.js +17 -31
  2. package/package.json +9 -6
  3. package/templates/consumer-modern-ts/module-federation.config.ts.handlebars +12 -0
  4. package/templates/consumer-modern-ts/src/routes/page.tsx +21 -0
  5. package/templates/consumer-rsbuild-ts/module-federation.config.ts.handlebars +12 -0
  6. package/templates/consumer-rsbuild-ts/src/App.tsx +12 -0
  7. package/templates/lib-common/module-federation.config.ts.handlebars +17 -0
  8. package/templates/lib-common/rslib.config.ts +46 -0
  9. package/templates/lib-common/src/index.css +53 -0
  10. package/templates/lib-common/src/index.tsx +19 -0
  11. package/templates/lib-common/tsconfig.json +14 -0
  12. package/templates/modern-common/.browserslistrc +5 -0
  13. package/templates/modern-common/.nvmrc +1 -0
  14. package/templates/modern-common/.vscode/extensions.json +14 -0
  15. package/templates/modern-common/.vscode/settings.json +88 -0
  16. package/templates/modern-common/README.md +37 -0
  17. package/templates/modern-common/biome.json +34 -0
  18. package/templates/modern-common/modern.config.ts +15 -0
  19. package/templates/modern-common/package.json +45 -0
  20. package/templates/modern-common/package.json.handlebars +45 -0
  21. package/templates/modern-common/src/modern-app-env.d.ts +3 -0
  22. package/templates/modern-common/src/modern.runtime.ts +3 -0
  23. package/templates/modern-common/src/routes/index.css +41 -0
  24. package/templates/modern-common/src/routes/layout.tsx +9 -0
  25. package/templates/modern-common/tsconfig.json +15 -0
  26. package/templates/provider-modern-ts/module-federation.config.ts.handlebars +12 -0
  27. package/templates/provider-modern-ts/src/components/ProviderComponent.css +52 -0
  28. package/templates/provider-modern-ts/src/components/ProviderComponent.tsx +19 -0
  29. package/templates/provider-modern-ts/src/routes/page.tsx +21 -0
  30. package/templates/provider-rsbuild-ts/module-federation.config.ts.handlebars +12 -0
  31. package/templates/provider-rsbuild-ts/src/App.tsx +12 -0
  32. package/templates/provider-rsbuild-ts/src/components/ProviderComponent.css +52 -0
  33. package/templates/provider-rsbuild-ts/src/components/ProviderComponent.tsx +19 -0
  34. package/templates/provider-rslib-storybook-ts/.storybook/main.ts.handlebars +41 -0
  35. package/templates/provider-rslib-storybook-ts/README.md +27 -0
  36. package/templates/provider-rslib-storybook-ts/package.json.handlebars +49 -0
  37. package/templates/provider-rslib-storybook-ts/stories/Index.stories.tsx +11 -0
  38. package/templates/provider-rslib-ts/README.md +19 -0
  39. package/templates/provider-rslib-ts/package.json.handlebars +34 -0
  40. package/templates/rsbuild-common/README.md +29 -0
  41. package/templates/rsbuild-common/package.json.handlebars +22 -0
  42. package/templates/rsbuild-common/public/.gitkeep +0 -0
  43. package/templates/rsbuild-common/rsbuild.config.ts +8 -0
  44. package/templates/rsbuild-common/src/App.css +15 -0
  45. package/templates/rsbuild-common/src/bootstrap.tsx +13 -0
  46. package/templates/rsbuild-common/src/env.d.ts +1 -0
  47. package/templates/rsbuild-common/src/index.tsx +1 -0
  48. package/templates/rsbuild-common/tsconfig.json +26 -0
package/dist/index.js CHANGED
@@ -1,5 +1,7 @@
1
+ #!/usr/bin/env node
1
2
  import * as __WEBPACK_EXTERNAL_MODULE_path__ from "path";
2
3
  import * as __WEBPACK_EXTERNAL_MODULE_fs__ from "fs";
4
+ import * as __WEBPACK_EXTERNAL_MODULE_url__ from "url";
3
5
  import * as __WEBPACK_EXTERNAL_MODULE__clack_prompts_3cae1695__ from "@clack/prompts";
4
6
  import * as __WEBPACK_EXTERNAL_MODULE_minimist__ from "minimist";
5
7
  import * as __WEBPACK_EXTERNAL_MODULE_rslog__ from "rslog";
@@ -75,7 +77,7 @@ class HandlebarsAPI {
75
77
  if (templateResource._type !== FS_RESOURCE) throw new Error('resource not match');
76
78
  const resourceValue = await templateResource.value();
77
79
  if ('string' != typeof resourceValue.content) throw new Error(`resource.value is not string, resourceValue=${resourceValue}`);
78
- await outputFs(target, renderString(resourceValue.content, parameters), outputFilePath, {
80
+ await outputFs(target, templateResource.resourceKey.endsWith('.handlebars') ? renderString(resourceValue.content, parameters) : resourceValue.content, outputFilePath, {
79
81
  encoding: 'utf-8'
80
82
  });
81
83
  }
@@ -89,6 +91,9 @@ class HandlebarsAPI {
89
91
  }));
90
92
  }
91
93
  }
94
+ const create_filename = (0, __WEBPACK_EXTERNAL_MODULE_url__.fileURLToPath)(import.meta.url);
95
+ const create_dirname = __WEBPACK_EXTERNAL_MODULE_path__["default"].dirname(create_filename);
96
+ const packageDir = __WEBPACK_EXTERNAL_MODULE_path__["default"].resolve(create_dirname, '..');
92
97
  function upperFirst(str) {
93
98
  return str.charAt(0).toUpperCase() + str.slice(1);
94
99
  }
@@ -125,9 +130,11 @@ function checkCancel(value) {
125
130
  if ((0, __WEBPACK_EXTERNAL_MODULE__clack_prompts_3cae1695__.isCancel)(value)) cancelAndExit();
126
131
  return value;
127
132
  }
128
- function formatDir(input) {
133
+ function formatProjectName(input) {
134
+ const formatted = input.trim().replace(/\/+$/g, '');
129
135
  return {
130
- targetDir: input.trim().replace(/\/+$/g, '')
136
+ packageName: input,
137
+ targetDir: formatted
131
138
  };
132
139
  }
133
140
  function isEmptyDir(path) {
@@ -136,26 +143,6 @@ function isEmptyDir(path) {
136
143
  }
137
144
  async function getAppTemplateName({ roleType, framework }, { template }) {
138
145
  if (template) return `${template}-ts`;
139
- let providerInfo = {
140
- name: '',
141
- entry: ''
142
- };
143
- if ('consumer' === roleType) {
144
- const providerName = checkCancel(await (0, __WEBPACK_EXTERNAL_MODULE__clack_prompts_3cae1695__.text)({
145
- message: 'Please input your provider name (You can skip by press "enter"):',
146
- defaultValue: ''
147
- }));
148
- if (providerName) {
149
- providerInfo.name = providerName;
150
- const providerEntry = checkCancel(await (0, __WEBPACK_EXTERNAL_MODULE__clack_prompts_3cae1695__.text)({
151
- message: `Please input your provider("${providerName}") entry:`,
152
- validate (value) {
153
- if (0 === value.length) return 'Entry is required';
154
- }
155
- }));
156
- providerInfo.entry = providerEntry;
157
- }
158
- }
159
146
  return `${roleType}-${framework}-ts`;
160
147
  }
161
148
  async function getLibTemplateName({ template }) {
@@ -181,7 +168,7 @@ async function getLibTemplateName({ template }) {
181
168
  }));
182
169
  const roleType = 'provider';
183
170
  if (!tools || !Object.keys(tools).length) return `${roleType}-${templateName}-ts`;
184
- return `${roleType}-${templateName}-[${Object.keys(tools)}]-ts`;
171
+ return `${roleType}-${templateName}-${tools[0]}-ts`;
185
172
  }
186
173
  function getTemplateName({ projectType, roleType, framework }, args) {
187
174
  if ('app' === projectType) return getAppTemplateName({
@@ -230,7 +217,7 @@ async function forgeTemplate({ projectType, argv, templateParameters, distFolder
230
217
  framework,
231
218
  roleType
232
219
  }, argv);
233
- const material = new FsMaterial(__dirname);
220
+ const material = new FsMaterial(packageDir);
234
221
  const renderTemplate = async (templateDir)=>{
235
222
  const templatePattern = `${templateDir}**/*`;
236
223
  const resourceMap = await material.find(templatePattern, {
@@ -271,16 +258,15 @@ async function create({ name, templates }) {
271
258
  const cwd = process.cwd();
272
259
  const pkgInfo = pkgFromUserAgent(process.env['npm_config_user_agent']);
273
260
  const pkgManager = pkgInfo ? pkgInfo.name : 'npm';
274
- const mfName = argv.dir ?? checkCancel(await (0, __WEBPACK_EXTERNAL_MODULE__clack_prompts_3cae1695__.text)({
261
+ const mfName = checkCancel(await (0, __WEBPACK_EXTERNAL_MODULE__clack_prompts_3cae1695__.text)({
275
262
  message: 'Please input Module Federation name:',
276
- placeholder: 'mf-project-name',
277
- defaultValue: 'mf-project-name',
263
+ placeholder: 'mf_project_name',
264
+ defaultValue: 'mf_project_name',
278
265
  validate (value) {
279
266
  if (0 === value.length) return 'Name is required';
280
267
  }
281
268
  }));
282
- const dir = argv.dir || 'mf-project';
283
- const { targetDir } = formatDir(dir);
269
+ const { targetDir } = formatProjectName(__WEBPACK_EXTERNAL_MODULE_path__["default"].join(argv.dir || '', mfName));
284
270
  const distFolder = __WEBPACK_EXTERNAL_MODULE_path__["default"].isAbsolute(targetDir) ? targetDir : __WEBPACK_EXTERNAL_MODULE_path__["default"].join(cwd, targetDir);
285
271
  if (!argv.override && __WEBPACK_EXTERNAL_MODULE_fs__["default"].existsSync(distFolder) && !isEmptyDir(distFolder)) {
286
272
  const option = checkCancel(await (0, __WEBPACK_EXTERNAL_MODULE__clack_prompts_3cae1695__.select)({
@@ -322,7 +308,7 @@ async function create({ name, templates }) {
322
308
  const nextSteps = [
323
309
  `cd ${targetDir}`,
324
310
  `${pkgManager} install`,
325
- `${pkgManager} run dev`
311
+ `${pkgManager} run ${'lib' === projectType ? 'mf-dev' : 'dev'}`
326
312
  ];
327
313
  (0, __WEBPACK_EXTERNAL_MODULE__clack_prompts_3cae1695__.note)(nextSteps.join('\n'), 'Next steps');
328
314
  (0, __WEBPACK_EXTERNAL_MODULE__clack_prompts_3cae1695__.outro)('Done.');
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "description": "Create a new Module Federation project",
4
4
  "public": true,
5
5
  "sideEffects": false,
6
- "version": "0.0.0-1737428758075",
6
+ "version": "0.0.0-next-20250305075427",
7
7
  "license": "MIT",
8
8
  "repository": {
9
9
  "type": "git",
@@ -14,15 +14,15 @@
14
14
  "access": "public"
15
15
  },
16
16
  "type": "module",
17
- "scripts": {
18
- "build": "rslib build"
19
- },
20
17
  "main": "./dist/index.js",
18
+ "engines": {
19
+ "node": ">=16.7.0"
20
+ },
21
21
  "bin": {
22
22
  "create-module-federation": "./dist/index.js"
23
23
  },
24
24
  "files": [
25
- "template",
25
+ "templates",
26
26
  "dist"
27
27
  ],
28
28
  "dependencies": {
@@ -40,5 +40,8 @@
40
40
  "@types/fs-extra": "9.0.6",
41
41
  "@rslib/core": "^0.3.1",
42
42
  "rsbuild-plugin-publint": "^0.2.1"
43
+ },
44
+ "scripts": {
45
+ "build": "rslib build"
43
46
  }
44
- }
47
+ }
@@ -0,0 +1,12 @@
1
+ import { createModuleFederationConfig } from '@module-federation/modern-js';
2
+
3
+ export default createModuleFederationConfig({
4
+ name: '{{mfName}}',
5
+ remotes: {
6
+ 'provider': 'rslib_provider@https://unpkg.com/module-federation-rslib-provider@latest/dist/mf/mf-manifest.json',
7
+ },
8
+ shared: {
9
+ react: { singleton: true },
10
+ 'react-dom': { singleton: true },
11
+ },
12
+ });
@@ -0,0 +1,21 @@
1
+ import { Helmet } from '@modern-js/runtime/head';
2
+ import './index.css';
3
+ import Provider from 'provider';
4
+
5
+ const Index = () => (
6
+ <div className="container-box">
7
+ <Helmet>
8
+ <link
9
+ rel="icon"
10
+ type="image/x-icon"
11
+ href="https://lf3-static.bytednsdoc.com/obj/eden-cn/uhbfnupenuhf/favicon.ico"
12
+ />
13
+ </Helmet>
14
+
15
+ <div className="landing-page">
16
+ <Provider />
17
+ </div>
18
+ </div>
19
+ );
20
+
21
+ export default Index;
@@ -0,0 +1,12 @@
1
+ import { createModuleFederationConfig } from '@module-federation/rsbuild-plugin';
2
+
3
+ export default createModuleFederationConfig({
4
+ name: '{{mfName}}',
5
+ remotes: {
6
+ 'provider': 'rslib_provider@https://unpkg.com/module-federation-rslib-provider@latest/dist/mf/mf-manifest.json',
7
+ },
8
+ shared: {
9
+ react: { singleton: true },
10
+ 'react-dom': { singleton: true },
11
+ },
12
+ });
@@ -0,0 +1,12 @@
1
+ import './App.css';
2
+ import Provider from 'provider';
3
+
4
+ const App = () => {
5
+ return (
6
+ <div className="content">
7
+ <Provider />
8
+ </div>
9
+ );
10
+ };
11
+
12
+ export default App;
@@ -0,0 +1,17 @@
1
+ import {createModuleFederationConfig} from '@module-federation/rsbuild-plugin';
2
+ import pkg from './package.json';
3
+
4
+ export default createModuleFederationConfig({
5
+ name: pkg.name,
6
+ exposes: {
7
+ '.': './src/index.tsx',
8
+ },
9
+ shared: {
10
+ react: {
11
+ singleton: true,
12
+ },
13
+ 'react-dom': {
14
+ singleton: true,
15
+ },
16
+ },
17
+ })
@@ -0,0 +1,46 @@
1
+ import { pluginReact } from '@rsbuild/plugin-react';
2
+ import { defineConfig } from '@rslib/core';
3
+ import { pluginModuleFederation } from '@module-federation/rsbuild-plugin';
4
+ import moduleFederationConfig from './module-federation.config';
5
+
6
+ const shared = {
7
+ dts: {
8
+ bundle: false,
9
+ },
10
+ };
11
+
12
+ export default defineConfig({
13
+ lib: [
14
+ {
15
+ ...shared,
16
+ format: 'esm',
17
+ output: {
18
+ distPath: {
19
+ root: './dist/esm',
20
+ },
21
+ },
22
+ },
23
+ {
24
+ ...shared,
25
+ format: 'cjs',
26
+ output: {
27
+ distPath: {
28
+ root: './dist/cjs',
29
+ },
30
+ },
31
+ },
32
+ {
33
+ ...shared,
34
+ format: 'mf',
35
+ output: {
36
+ distPath: {
37
+ root: './dist/mf',
38
+ },
39
+ },
40
+ },
41
+ ],
42
+ server: {
43
+ port: 3001,
44
+ },
45
+ plugins: [pluginReact(), pluginModuleFederation(moduleFederationConfig)],
46
+ });
@@ -0,0 +1,53 @@
1
+ .container {
2
+ display: flex;
3
+ flex-direction: column;
4
+ align-items: center;
5
+ justify-content: center;
6
+ height: 60vh;
7
+ padding: 10vh;
8
+ background: linear-gradient(45deg, #3a65f2, #6a5acd, #8a2be2, #023cfc);
9
+ background-size: 400% 400%;
10
+ animation: gradientFlow 6s ease infinite;
11
+ }
12
+
13
+ .icon-container {
14
+ width: 180px;
15
+ margin-bottom: 20px;
16
+ position: relative;
17
+ transition: all 0.3s ease;
18
+ }
19
+
20
+ .logo-image {
21
+ width: 100%;
22
+ transition: opacity 0.3s ease;
23
+ }
24
+
25
+ .title {
26
+ font-size: 3rem;
27
+ color: #fff;
28
+ margin-bottom: 20px;
29
+ animation: fadeInUp 1s ease-out;
30
+ }
31
+
32
+ @keyframes gradientFlow {
33
+ 0% {
34
+ background-position: 0% 50%;
35
+ }
36
+ 50% {
37
+ background-position: 100% 50%;
38
+ }
39
+ 100% {
40
+ background-position: 0% 50%;
41
+ }
42
+ }
43
+
44
+ @keyframes fadeInUp {
45
+ from {
46
+ opacity: 0;
47
+ transform: translateY(20px);
48
+ }
49
+ to {
50
+ opacity: 1;
51
+ transform: translateY(0);
52
+ }
53
+ }
@@ -0,0 +1,19 @@
1
+ import React from 'react';
2
+ import './index.css';
3
+
4
+ const Provider: React.FC = () => {
5
+ return (
6
+ <div className="container">
7
+ <div className="icon-container">
8
+ <img
9
+ src="https://module-federation.io/svg.svg"
10
+ alt="logo"
11
+ className="logo-image"
12
+ />
13
+ </div>
14
+ <h1 className="title">Hello Module Federation 2.0</h1>
15
+ </div>
16
+ );
17
+ };
18
+
19
+ export default Provider;
@@ -0,0 +1,14 @@
1
+ {
2
+ "compilerOptions": {
3
+ "lib": ["DOM", "ES2021"],
4
+ "module": "ESNext",
5
+ "jsx": "react-jsx",
6
+ "strict": true,
7
+ "skipLibCheck": true,
8
+ "isolatedModules": true,
9
+ "resolveJsonModule": true,
10
+ "moduleResolution": "bundler",
11
+ "useDefineForClassFields": true
12
+ },
13
+ "include": ["src"]
14
+ }
@@ -0,0 +1,5 @@
1
+ chrome >= 51
2
+ edge >= 15
3
+ firefox >= 54
4
+ safari >= 10
5
+ ios_saf >= 10
@@ -0,0 +1 @@
1
+ lts/hydrogen
@@ -0,0 +1,14 @@
1
+ {
2
+ "recommendations": [
3
+ "styled-components.vscode-styled-components",
4
+ "EditorConfig.editorconfig",
5
+ "streetsidesoftware.code-spell-checker",
6
+ "codezombiech.gitignore",
7
+ "aaron-bond.better-comments",
8
+ "jasonnutter.search-node-modules",
9
+ "jock.svg",
10
+ "mikestead.dotenv",
11
+ "vscode-icons-team.vscode-icons",
12
+ "biomejs.biome"
13
+ ]
14
+ }
@@ -0,0 +1,88 @@
1
+ {
2
+ "files.associations": {
3
+ ".code-workspace": "jsonc",
4
+ ".stylelintrc": "jsonc",
5
+ "stylelintrc": "jsonc",
6
+ "README": "markdown"
7
+ },
8
+ "search.useIgnoreFiles": true,
9
+ "search.exclude": {
10
+ "**/dist": true,
11
+ "**/*.log": true,
12
+ "**/*.pid": true,
13
+ "**/.git": true,
14
+ "**/node_modules": true
15
+ },
16
+ //
17
+ "editor.rulers": [80, 120],
18
+ "files.eol": "\n",
19
+ "files.trimTrailingWhitespace": true,
20
+ "files.insertFinalNewline": true,
21
+ //
22
+ "cSpell.diagnosticLevel": "Hint",
23
+ "javascript.validate.enable": false,
24
+ "typescript.validate.enable": true,
25
+ "css.validate": false,
26
+ "scss.validate": false,
27
+ "less.validate": false,
28
+ "[css]": {
29
+ "editor.formatOnType": true,
30
+ "editor.formatOnPaste": true,
31
+ "editor.formatOnSave": true
32
+ },
33
+ "[scss]": {
34
+ "editor.formatOnType": true,
35
+ "editor.formatOnPaste": true,
36
+ "editor.formatOnSave": true
37
+ },
38
+ "[less]": {
39
+ "editor.formatOnType": true,
40
+ "editor.formatOnPaste": true,
41
+ "editor.formatOnSave": true
42
+ },
43
+ "editor.codeActionsOnSave": {
44
+ "quickfix.biome": "explicit"
45
+ },
46
+ "editor.defaultFormatter": "biomejs.biome",
47
+ "editor.formatOnSave": true,
48
+ "[typescript]": {
49
+ "editor.defaultFormatter": "biomejs.biome",
50
+ "editor.codeActionsOnSave": {
51
+ "quickfix.biome": "explicit",
52
+ "source.organizeImports": "never",
53
+ "source.organizeImports.biome": "explicit"
54
+ }
55
+ },
56
+ "[typescriptreact]": {
57
+ "editor.defaultFormatter": "biomejs.biome",
58
+ "editor.codeActionsOnSave": {
59
+ "quickfix.biome": "explicit",
60
+ "source.organizeImports": "never",
61
+ "source.organizeImports.biome": "explicit"
62
+ }
63
+ },
64
+ "[json]": {
65
+ "editor.defaultFormatter": "biomejs.biome"
66
+ },
67
+ "[jsonc]": {
68
+ "editor.defaultFormatter": "biomejs.biome"
69
+ },
70
+ "[javascriptreact]": {
71
+ "editor.defaultFormatter": "biomejs.biome",
72
+ "editor.codeActionsOnSave": {
73
+ "quickfix.biome": "explicit",
74
+ "source.organizeImports": "never",
75
+ "source.organizeImports.biome": "explicit"
76
+ }
77
+ },
78
+ "[javascript]": {
79
+ "editor.defaultFormatter": "biomejs.biome",
80
+ "editor.codeActionsOnSave": {
81
+ "quickfix.biome": "explicit",
82
+ "source.organizeImports": "never",
83
+ "source.organizeImports.biome": "explicit"
84
+ }
85
+ },
86
+ "emmet.triggerExpansionOnTab": true,
87
+ "typescript.tsdk": "node_modules/typescript/lib"
88
+ }
@@ -0,0 +1,37 @@
1
+ # Modern.js App
2
+
3
+ ## Setup
4
+
5
+ Install the dependencies:
6
+
7
+ ```bash
8
+ pnpm install
9
+ ```
10
+
11
+ ## Get Started
12
+
13
+ Start the dev server:
14
+
15
+ ```bash
16
+ pnpm dev
17
+ ```
18
+
19
+ Enable optional features or add a new entry:
20
+
21
+ ```bash
22
+ pnpm new
23
+ ```
24
+
25
+ Build the app for production:
26
+
27
+ ```bash
28
+ pnpm build
29
+ ```
30
+
31
+ Preview the production build locally:
32
+
33
+ ```bash
34
+ pnpm serve
35
+ ```
36
+
37
+ For more information, see the [Modern.js documentation](https://modernjs.dev/en).
@@ -0,0 +1,34 @@
1
+ {
2
+ "$schema": "https://biomejs.dev/schemas/1.8.3/schema.json",
3
+ "vcs": {
4
+ "enabled": true,
5
+ "defaultBranch": "main",
6
+ "clientKind": "git",
7
+ "useIgnoreFile": true
8
+ },
9
+ "formatter": {
10
+ "enabled": true,
11
+ "indentStyle": "space"
12
+ },
13
+ "javascript": {
14
+ "formatter": {
15
+ "quoteStyle": "single",
16
+ "arrowParentheses": "asNeeded",
17
+ "jsxQuoteStyle": "double",
18
+ "lineWidth": 80
19
+ }
20
+ },
21
+ "linter": {
22
+ "enabled": true,
23
+ "rules": {
24
+ "recommended": true
25
+ }
26
+ },
27
+ "organizeImports": {
28
+ "enabled": true
29
+ },
30
+ "files": {
31
+ "ignoreUnknown": true,
32
+ "ignore": [".vscode/**/*", "node_modules/**/*", "dist/**/*"]
33
+ }
34
+ }
@@ -0,0 +1,15 @@
1
+ import { appTools, defineConfig } from '@modern-js/app-tools';
2
+ import { moduleFederationPlugin } from '@module-federation/modern-js';
3
+
4
+ // https://modernjs.dev/en/configure/app/usage
5
+ export default defineConfig({
6
+ runtime: {
7
+ router: true,
8
+ },
9
+ plugins: [
10
+ appTools({
11
+ bundler: 'rspack', // Set to 'webpack' to enable webpack
12
+ }),
13
+ moduleFederationPlugin(),
14
+ ],
15
+ });
@@ -0,0 +1,45 @@
1
+ {
2
+ "name": "new-provider",
3
+ "version": "0.1.0",
4
+ "scripts": {
5
+ "reset": "npx rimraf node_modules ./**/node_modules",
6
+ "dev": "modern dev",
7
+ "build": "modern build",
8
+ "start": "modern start",
9
+ "serve": "modern serve",
10
+ "new": "modern new",
11
+ "lint": "biome check",
12
+ "prepare": "simple-git-hooks",
13
+ "upgrade": "modern upgrade"
14
+ },
15
+ "engines": {
16
+ "node": ">=16.18.1"
17
+ },
18
+ "lint-staged": {
19
+ "*.{js,ts,cjs,mjs,d.cts,d.mts,jsx,tsx,json,jsonc}": [
20
+ "biome check --files-ignore-unknown=true"
21
+ ]
22
+ },
23
+ "simple-git-hooks": {
24
+ "pre-commit": "npx lint-staged"
25
+ },
26
+ "dependencies": {
27
+ "@modern-js/runtime": "2.63.7",
28
+ "react": "^18.3.1",
29
+ "react-dom": "^18.3.1"
30
+ },
31
+ "devDependencies": {
32
+ "@modern-js/app-tools": "2.63.7",
33
+ "@modern-js/tsconfig": "2.63.7",
34
+ "@biomejs/biome": "1.8.3",
35
+ "typescript": "~5.0.4",
36
+ "@types/jest": "~29.2.4",
37
+ "@types/node": "~18.11.9",
38
+ "@types/react": "^18.3.11",
39
+ "@types/react-dom": "~18.3.1",
40
+ "lint-staged": "~13.1.0",
41
+ "simple-git-hooks": "^2.11.1",
42
+ "rimraf": "^6.0.1",
43
+ "@module-federation/modern-js": "^0.8.9"
44
+ }
45
+ }
@@ -0,0 +1,45 @@
1
+ {
2
+ "name": "{{ mfName }}",
3
+ "version": "0.1.0",
4
+ "scripts": {
5
+ "reset": "npx rimraf node_modules ./**/node_modules",
6
+ "dev": "modern dev",
7
+ "build": "modern build",
8
+ "start": "modern start",
9
+ "serve": "modern serve",
10
+ "new": "modern new",
11
+ "lint": "biome check",
12
+ "prepare": "simple-git-hooks",
13
+ "upgrade": "modern upgrade"
14
+ },
15
+ "engines": {
16
+ "node": ">=16.18.1"
17
+ },
18
+ "lint-staged": {
19
+ "*.{js,ts,cjs,mjs,d.cts,d.mts,jsx,tsx,json,jsonc}": [
20
+ "biome check --files-ignore-unknown=true"
21
+ ]
22
+ },
23
+ "simple-git-hooks": {
24
+ "pre-commit": "npx lint-staged"
25
+ },
26
+ "dependencies": {
27
+ "@modern-js/runtime": "2.63.7",
28
+ "react": "^18.3.1",
29
+ "react-dom": "^18.3.1"
30
+ },
31
+ "devDependencies": {
32
+ "@modern-js/app-tools": "2.63.7",
33
+ "@modern-js/tsconfig": "2.63.7",
34
+ "@biomejs/biome": "1.8.3",
35
+ "typescript": "~5.0.4",
36
+ "@types/jest": "~29.2.4",
37
+ "@types/node": "~18.11.9",
38
+ "@types/react": "^18.3.11",
39
+ "@types/react-dom": "~18.3.1",
40
+ "lint-staged": "~13.1.0",
41
+ "simple-git-hooks": "^2.11.1",
42
+ "rimraf": "^6.0.1",
43
+ "@module-federation/modern-js":"^0.8.9"
44
+ }
45
+ }
@@ -0,0 +1,3 @@
1
+ /// <reference types='@modern-js/app-tools/types' />
2
+ /// <reference types='@modern-js/runtime/types' />
3
+ /// <reference types='@modern-js/runtime/types/router' />
@@ -0,0 +1,3 @@
1
+ import { defineRuntimeConfig } from '@modern-js/runtime';
2
+
3
+ export default defineRuntimeConfig({});
@@ -0,0 +1,41 @@
1
+ html,
2
+ body {
3
+ padding: 0;
4
+ margin: 0;
5
+ font-family:
6
+ PingFang SC,
7
+ Hiragino Sans GB,
8
+ Microsoft YaHei,
9
+ Arial,
10
+ sans-serif;
11
+ background: linear-gradient(to bottom, transparent, #fff) #eceeef;
12
+ }
13
+
14
+ p {
15
+ margin: 0;
16
+ }
17
+
18
+ * {
19
+ -webkit-font-smoothing: antialiased;
20
+ -moz-osx-font-smoothing: grayscale;
21
+ box-sizing: border-box;
22
+ }
23
+
24
+ .container-box {
25
+ min-height: 100vh;
26
+ max-width: 100%;
27
+ display: flex;
28
+ flex-direction: column;
29
+ justify-content: center;
30
+ align-items: center;
31
+ padding: 50px;
32
+ }
33
+
34
+ .landing-page {
35
+ padding: 20px;
36
+ flex: 1;
37
+ display: flex;
38
+ flex-direction: column;
39
+ justify-content: center;
40
+ align-items: center;
41
+ }
@@ -0,0 +1,9 @@
1
+ import { Outlet } from '@modern-js/runtime/router';
2
+
3
+ export default function Layout() {
4
+ return (
5
+ <div>
6
+ <Outlet />
7
+ </div>
8
+ );
9
+ }
@@ -0,0 +1,15 @@
1
+ {
2
+ "extends": "@modern-js/tsconfig/base",
3
+ "compilerOptions": {
4
+ "declaration": false,
5
+ "jsx": "preserve",
6
+ "baseUrl": "./",
7
+ "paths": {
8
+ "@/*": ["./src/*"],
9
+ "@shared/*": ["./shared/*"],
10
+ "*": ["./@mf-types/*"]
11
+ }
12
+ },
13
+ "include": ["src", "shared", "config", "modern.config.ts"],
14
+ "exclude": ["**/node_modules"]
15
+ }
@@ -0,0 +1,12 @@
1
+ import { createModuleFederationConfig } from '@module-federation/modern-js';
2
+
3
+ export default createModuleFederationConfig({
4
+ name: '{{mfName}}',
5
+ exposes: {
6
+ '.': './src/components/ProviderComponent.tsx',
7
+ },
8
+ shared: {
9
+ react: { singleton: true },
10
+ 'react-dom': { singleton: true },
11
+ },
12
+ });
@@ -0,0 +1,52 @@
1
+ .container {
2
+ display: flex;
3
+ flex-direction: column;
4
+ align-items: center;
5
+ justify-content: center;
6
+ height: 100vh;
7
+ background: linear-gradient(45deg, #3a65f2, #6a5acd, #8a2be2, #023cfc);
8
+ background-size: 400% 400%;
9
+ animation: gradientFlow 6s ease infinite;
10
+ }
11
+
12
+ .icon-container {
13
+ width: 180px;
14
+ margin-bottom: 20px;
15
+ position: relative;
16
+ transition: all 0.3s ease;
17
+ }
18
+
19
+ .logo-image {
20
+ width: 100%;
21
+ transition: opacity 0.3s ease;
22
+ }
23
+
24
+ .title {
25
+ font-size: 3rem;
26
+ color: #fff;
27
+ margin-bottom: 20px;
28
+ animation: fadeInUp 1s ease-out;
29
+ }
30
+
31
+ @keyframes gradientFlow {
32
+ 0% {
33
+ background-position: 0% 50%;
34
+ }
35
+ 50% {
36
+ background-position: 100% 50%;
37
+ }
38
+ 100% {
39
+ background-position: 0% 50%;
40
+ }
41
+ }
42
+
43
+ @keyframes fadeInUp {
44
+ from {
45
+ opacity: 0;
46
+ transform: translateY(20px);
47
+ }
48
+ to {
49
+ opacity: 1;
50
+ transform: translateY(0);
51
+ }
52
+ }
@@ -0,0 +1,19 @@
1
+ import React from 'react';
2
+ import './ProviderComponent.css';
3
+
4
+ const Provider: React.FC = () => {
5
+ return (
6
+ <div className="container">
7
+ <div className="icon-container">
8
+ <img
9
+ src="https://module-federation.io/svg.svg"
10
+ alt="logo"
11
+ className="logo-image"
12
+ />
13
+ </div>
14
+ <h1 className="title">Hello Module Federation 2.0</h1>
15
+ </div>
16
+ );
17
+ };
18
+
19
+ export default Provider;
@@ -0,0 +1,21 @@
1
+ import { Helmet } from '@modern-js/runtime/head';
2
+ import './index.css';
3
+ import Provider from '../components/ProviderComponent';
4
+
5
+ const Index = () => (
6
+ <div className="container-box">
7
+ <Helmet>
8
+ <link
9
+ rel="icon"
10
+ type="image/x-icon"
11
+ href="https://lf3-static.bytednsdoc.com/obj/eden-cn/uhbfnupenuhf/favicon.ico"
12
+ />
13
+ </Helmet>
14
+
15
+ <div className="landing-page">
16
+ <Provider />
17
+ </div>
18
+ </div>
19
+ );
20
+
21
+ export default Index;
@@ -0,0 +1,12 @@
1
+ import { createModuleFederationConfig } from '@module-federation/rsbuild-plugin';
2
+
3
+ export default createModuleFederationConfig({
4
+ name: '{{mfName}}',
5
+ exposes: {
6
+ '.': './src/components/ProviderComponent.tsx',
7
+ },
8
+ shared: {
9
+ react: { singleton: true },
10
+ 'react-dom': { singleton: true },
11
+ },
12
+ });
@@ -0,0 +1,12 @@
1
+ import './App.css';
2
+ import Provider from './components/ProviderComponent';
3
+
4
+ const App = () => {
5
+ return (
6
+ <div className="content">
7
+ <Provider />
8
+ </div>
9
+ );
10
+ };
11
+
12
+ export default App;
@@ -0,0 +1,52 @@
1
+ .container {
2
+ display: flex;
3
+ flex-direction: column;
4
+ align-items: center;
5
+ justify-content: center;
6
+ height: 100vh;
7
+ background: linear-gradient(45deg, #3a65f2, #6a5acd, #8a2be2, #023cfc);
8
+ background-size: 400% 400%;
9
+ animation: gradientFlow 6s ease infinite;
10
+ }
11
+
12
+ .icon-container {
13
+ width: 180px;
14
+ margin-bottom: 20px;
15
+ position: relative;
16
+ transition: all 0.3s ease;
17
+ }
18
+
19
+ .logo-image {
20
+ width: 100%;
21
+ transition: opacity 0.3s ease;
22
+ }
23
+
24
+ .title {
25
+ font-size: 3rem;
26
+ color: #fff;
27
+ margin-bottom: 20px;
28
+ animation: fadeInUp 1s ease-out;
29
+ }
30
+
31
+ @keyframes gradientFlow {
32
+ 0% {
33
+ background-position: 0% 50%;
34
+ }
35
+ 50% {
36
+ background-position: 100% 50%;
37
+ }
38
+ 100% {
39
+ background-position: 0% 50%;
40
+ }
41
+ }
42
+
43
+ @keyframes fadeInUp {
44
+ from {
45
+ opacity: 0;
46
+ transform: translateY(20px);
47
+ }
48
+ to {
49
+ opacity: 1;
50
+ transform: translateY(0);
51
+ }
52
+ }
@@ -0,0 +1,19 @@
1
+ import React from 'react';
2
+ import './ProviderComponent.css';
3
+
4
+ const Provider: React.FC = () => {
5
+ return (
6
+ <div className="container">
7
+ <div className="icon-container">
8
+ <img
9
+ src="https://module-federation.io/svg.svg"
10
+ alt="logo"
11
+ className="logo-image"
12
+ />
13
+ </div>
14
+ <h1 className="title">Hello Module Federation 2.0</h1>
15
+ </div>
16
+ );
17
+ };
18
+
19
+ export default Provider;
@@ -0,0 +1,41 @@
1
+ import { dirname, join } from 'node:path';
2
+ import type { StorybookConfig } from 'storybook-react-rsbuild';
3
+
4
+ /**
5
+ * This function is used to resolve the absolute path of a package.
6
+ * It is needed in projects that use Yarn PnP or are set up within a monorepo.
7
+ */
8
+ function getAbsolutePath(value: string): any {
9
+ return dirname(require.resolve(join(value, 'package.json')));
10
+ }
11
+
12
+ const config: StorybookConfig = {
13
+ stories: [
14
+ '../stories/**/*.mdx',
15
+ '../stories/**/*.stories.@(js|jsx|mjs|ts|tsx)',
16
+ ],
17
+ framework: {
18
+ name: getAbsolutePath('storybook-react-rsbuild'),
19
+ options: {},
20
+ },
21
+ addons: [
22
+ {
23
+ name: getAbsolutePath('storybook-addon-rslib'),
24
+ options: {
25
+ rslib: {
26
+ include: ['**/stories/**'],
27
+ },
28
+ },
29
+ },
30
+ {
31
+ name: '@module-federation/storybook-addon/preset',
32
+ options: {
33
+ remotes: {
34
+ provider: '{{mfName}}@http://localhost:3001/mf-manifest.json',
35
+ },
36
+ },
37
+ },
38
+ ],
39
+ };
40
+
41
+ export default config;
@@ -0,0 +1,27 @@
1
+ # Rslib MF Project
2
+
3
+ This example demonstrates how to use Rslib to build a simple Module Federation React component.
4
+
5
+ ### Command
6
+
7
+ Build package
8
+
9
+ ```
10
+ pnpm build
11
+ ```
12
+
13
+ Dev package
14
+
15
+ 1.
16
+
17
+ ```
18
+ pnpm mf-dev
19
+ ```
20
+
21
+ 2.
22
+
23
+ ```
24
+ pnpm storybook
25
+ ```
26
+
27
+ visit http://localhost:6006
@@ -0,0 +1,49 @@
1
+ {
2
+ "name": "{{ mfName }}",
3
+ "version": "0.0.0",
4
+ "type": "module",
5
+ "exports": {
6
+ ".": {
7
+ "types": "./dist/index.d.ts",
8
+ "import": "./dist/index.js"
9
+ }
10
+ },
11
+ "module": "./dist/index.js",
12
+ "types": "./dist/index.d.ts",
13
+ "files": [
14
+ "dist"
15
+ ],
16
+ "scripts": {
17
+ "build": "rslib build",
18
+ "build:storybook": "storybook build",
19
+ "dev": "rslib build --watch",
20
+ "storybook": "storybook dev -p 6006",
21
+ "mf-dev": "rslib mf-dev"
22
+ },
23
+ "devDependencies": {
24
+ "@rsbuild/core": "^1.2.15",
25
+ "@rsbuild/plugin-react": "^1.1.1",
26
+ "@rslib/core": "^0.5.3",
27
+ "@storybook/addon-essentials": "^8.4.7",
28
+ "@storybook/addon-interactions": "^8.4.7",
29
+ "@storybook/addon-links": "^8.4.7",
30
+ "@storybook/addon-onboarding": "^8.4.7",
31
+ "@storybook/blocks": "^8.4.7",
32
+ "@storybook/react": "^8.4.7",
33
+ "@storybook/test": "^8.4.7",
34
+ "@types/react": "^18.3.11",
35
+ "@types/react-dom": "~18.3.1",
36
+ "react": "^18.3.1",
37
+ "react-dom": "^18.3.1",
38
+ "storybook": "^8.4.7",
39
+ "storybook-addon-rslib": "^0.1.7",
40
+ "storybook-react-rsbuild": "^0.1.7",
41
+ "typescript": "^5.7.3",
42
+ "@module-federation/rsbuild-plugin":"^0.8.9",
43
+ "@module-federation/storybook-addon":"^4.0.1"
44
+ },
45
+ "peerDependencies": {
46
+ "react": ">=16.9.0",
47
+ "react-dom": ">=16.9.0"
48
+ }
49
+ }
@@ -0,0 +1,11 @@
1
+ import React from 'react';
2
+ import Provider from 'provider';
3
+
4
+ const Component = () => <Provider />;
5
+
6
+ export default {
7
+ title: 'Provider Component',
8
+ component: Component,
9
+ };
10
+
11
+ export const Basic = {};
@@ -0,0 +1,19 @@
1
+ # Rslib MF Project
2
+
3
+ This example demonstrates how to use Rslib to build a simple Module Federation React component.
4
+
5
+ ### Command
6
+
7
+ Build package
8
+
9
+ ```
10
+ pnpm build
11
+ ```
12
+
13
+ Dev package
14
+
15
+
16
+ ```
17
+ pnpm mf-dev
18
+ ```
19
+
@@ -0,0 +1,34 @@
1
+ {
2
+ "name": "{{ mfName }}",
3
+ "version": "0.0.0",
4
+ "type": "module",
5
+ "exports": {
6
+ ".": {
7
+ "types": "./dist/index.d.ts",
8
+ "import": "./dist/index.js"
9
+ }
10
+ },
11
+ "module": "./dist/index.js",
12
+ "types": "./dist/index.d.ts",
13
+ "files": [
14
+ "dist"
15
+ ],
16
+ "scripts": {
17
+ "build": "rslib build",
18
+ "dev": "rslib build --watch",
19
+ "mf-dev": "rslib mf-dev"
20
+ },
21
+ "devDependencies": {
22
+ "@rsbuild/core": "^1.2.15",
23
+ "@rsbuild/plugin-react": "^1.1.1",
24
+ "@rslib/core": "^0.5.3",
25
+ "@types/react": "^18.3.11",
26
+ "react": "^18.3.1",
27
+ "typescript": "^5.7.3",
28
+ "@module-federation/rsbuild-plugin":"^0.8.9"
29
+ },
30
+ "peerDependencies": {
31
+ "react": ">=16.9.0",
32
+ "react-dom": ">=16.9.0"
33
+ }
34
+ }
@@ -0,0 +1,29 @@
1
+ # Rsbuild Project
2
+
3
+ ## Setup
4
+
5
+ Install the dependencies:
6
+
7
+ ```bash
8
+ pnpm install
9
+ ```
10
+
11
+ ## Get Started
12
+
13
+ Start the dev server:
14
+
15
+ ```bash
16
+ pnpm dev
17
+ ```
18
+
19
+ Build the app for production:
20
+
21
+ ```bash
22
+ pnpm build
23
+ ```
24
+
25
+ Preview the production build locally:
26
+
27
+ ```bash
28
+ pnpm preview
29
+ ```
@@ -0,0 +1,22 @@
1
+ {
2
+ "name": "{{ mfName }}",
3
+ "private": true,
4
+ "version": "1.0.0",
5
+ "scripts": {
6
+ "dev": "rsbuild dev --open",
7
+ "build": "rsbuild build",
8
+ "preview": "rsbuild preview"
9
+ },
10
+ "dependencies": {
11
+ "react": "^19.0.0",
12
+ "react-dom": "^19.0.0"
13
+ },
14
+ "devDependencies": {
15
+ "@rsbuild/core": "^1.2.15",
16
+ "@rsbuild/plugin-react": "^1.1.1",
17
+ "@types/react": "^19.0.0",
18
+ "@types/react-dom": "^19.0.0",
19
+ "typescript": "^5.7.2",
20
+ "@module-federation/rsbuild-plugin":"^0.8.9"
21
+ }
22
+ }
File without changes
@@ -0,0 +1,8 @@
1
+ import { defineConfig } from '@rsbuild/core';
2
+ import { pluginReact } from '@rsbuild/plugin-react';
3
+ import { pluginModuleFederation } from '@module-federation/rsbuild-plugin';
4
+ import moduleFederationConfig from './module-federation.config';
5
+
6
+ export default defineConfig({
7
+ plugins: [pluginReact(), pluginModuleFederation(moduleFederationConfig)],
8
+ });
@@ -0,0 +1,15 @@
1
+ body {
2
+ margin: 0;
3
+ color: #fff;
4
+ font-family: Inter, Avenir, Helvetica, Arial, sans-serif;
5
+ background-image: linear-gradient(to bottom, #020917, #101725);
6
+ }
7
+
8
+ .content {
9
+ display: flex;
10
+ min-height: 100vh;
11
+ line-height: 1.1;
12
+ text-align: center;
13
+ flex-direction: column;
14
+ justify-content: center;
15
+ }
@@ -0,0 +1,13 @@
1
+ import React from 'react';
2
+ import ReactDOM from 'react-dom/client';
3
+ import App from './App';
4
+
5
+ const rootEl = document.getElementById('root');
6
+ if (rootEl) {
7
+ const root = ReactDOM.createRoot(rootEl);
8
+ root.render(
9
+ <React.StrictMode>
10
+ <App />
11
+ </React.StrictMode>,
12
+ );
13
+ }
@@ -0,0 +1 @@
1
+ /// <reference types="@rsbuild/core/types" />
@@ -0,0 +1 @@
1
+ import('./bootstrap');
@@ -0,0 +1,26 @@
1
+ {
2
+ "compilerOptions": {
3
+ "lib": ["DOM", "ES2020"],
4
+ "jsx": "react-jsx",
5
+ "target": "ES2020",
6
+ "noEmit": true,
7
+ "skipLibCheck": true,
8
+ "useDefineForClassFields": true,
9
+
10
+ /* modules */
11
+ "module": "ESNext",
12
+ "isolatedModules": true,
13
+ "resolveJsonModule": true,
14
+ "moduleResolution": "Bundler",
15
+ "allowImportingTsExtensions": true,
16
+
17
+ /* type checking */
18
+ "strict": true,
19
+ "noUnusedLocals": true,
20
+ "noUnusedParameters": true,
21
+ "paths": {
22
+ "*": ["./@mf-types/*"]
23
+ }
24
+ },
25
+ "include": ["src"]
26
+ }