create-module-federation 0.0.0-next-20250306073231 → 0.0.0-next-20250310022208
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +40 -1
- package/dist/index.js +45 -52
- package/package.json +1 -1
- package/templates/provider-modern-ts/modern.config.ts +18 -0
- package/templates/provider-rsbuild-ts/rsbuild.config.ts +11 -0
- /package/templates/{modern-common → consumer-modern-ts}/modern.config.ts +0 -0
- /package/templates/{rsbuild-common → consumer-rsbuild-ts}/rsbuild.config.ts +0 -0
package/README.md
CHANGED
|
@@ -1 +1,40 @@
|
|
|
1
|
-
|
|
1
|
+
<p align="center">
|
|
2
|
+
<a href="https://module-federation.io/" target="blank"><img src="https://module-federation.io/module-federation.svg" alt="Module Federation 2.0" /></a>
|
|
3
|
+
</p>
|
|
4
|
+
|
|
5
|
+
# create-module-federation
|
|
6
|
+
|
|
7
|
+
Create a new Module Federation project.
|
|
8
|
+
|
|
9
|
+
<p>
|
|
10
|
+
<a href="https://npmjs.com/package/create-module-federation">
|
|
11
|
+
<img src="https://img.shields.io/npm/v/create-module-federation?style=flat-square&colorA=564341&colorB=EDED91" alt="npm version" />
|
|
12
|
+
</a>
|
|
13
|
+
<img src="https://img.shields.io/badge/License-MIT-blue.svg?style=flat-square&colorA=564341&colorB=EDED91" alt="license" />
|
|
14
|
+
<a href="https://npmcharts.com/compare/create-module-federation?minimal=true"><img src="https://img.shields.io/npm/dm/create-module-federation.svg?style=flat-square&colorA=564341&colorB=EDED91" alt="downloads" /></a>
|
|
15
|
+
</p>
|
|
16
|
+
|
|
17
|
+
## Usage
|
|
18
|
+
|
|
19
|
+
Using `npm create`:
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
npm create module-federation@latest
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
Using CLI flags:
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
npx create-module-federation --dir my-project --template provider-modern --name provider
|
|
29
|
+
|
|
30
|
+
# Using abbreviations
|
|
31
|
+
npx create-module-federation -d my-project -t provider-modern -n provider
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## Documentation
|
|
35
|
+
|
|
36
|
+
See [Documentation](https://module-federation.io/guide/start/quick-start).
|
|
37
|
+
|
|
38
|
+
## License
|
|
39
|
+
|
|
40
|
+
[MIT](https://github.com/module-federation/core/blob/main/LICENSE).
|
package/dist/index.js
CHANGED
|
@@ -98,8 +98,8 @@ const packageDir = __WEBPACK_EXTERNAL_MODULE_path__["default"].resolve(create_di
|
|
|
98
98
|
const OTHER_TYPE = {
|
|
99
99
|
zephyr: {
|
|
100
100
|
label: 'zephyr',
|
|
101
|
-
|
|
102
|
-
hint: '
|
|
101
|
+
packageName: 'zephyr-apps@latest',
|
|
102
|
+
hint: 'create zephyr-apps@latest'
|
|
103
103
|
}
|
|
104
104
|
};
|
|
105
105
|
function upperFirst(str) {
|
|
@@ -119,8 +119,7 @@ function logHelpMessage(name, templates) {
|
|
|
119
119
|
--override override files in target directory
|
|
120
120
|
|
|
121
121
|
Templates:
|
|
122
|
-
|
|
123
|
-
${templates.join(', ')}
|
|
122
|
+
${templates.filter((t)=>!t.startsWith('zephyr')).join(', ')}
|
|
124
123
|
`);
|
|
125
124
|
}
|
|
126
125
|
function pkgFromUserAgent(userAgent) {
|
|
@@ -190,6 +189,27 @@ function getTemplateName({ projectType, roleType, framework }, args) {
|
|
|
190
189
|
function getTemplateDir(templateName) {
|
|
191
190
|
return `templates/${templateName}/`;
|
|
192
191
|
}
|
|
192
|
+
async function getProjectType(template) {
|
|
193
|
+
if (!template) return checkCancel(await (0, __WEBPACK_EXTERNAL_MODULE__clack_prompts_3cae1695__.select)({
|
|
194
|
+
message: 'Please select the type of project you want to create:',
|
|
195
|
+
options: [
|
|
196
|
+
{
|
|
197
|
+
value: "app",
|
|
198
|
+
label: 'Application'
|
|
199
|
+
},
|
|
200
|
+
{
|
|
201
|
+
value: "lib",
|
|
202
|
+
label: 'Lib'
|
|
203
|
+
},
|
|
204
|
+
{
|
|
205
|
+
value: "zephyr",
|
|
206
|
+
label: 'Zephyr Powered (Learn more at https://zephyr-cloud.io)'
|
|
207
|
+
}
|
|
208
|
+
]
|
|
209
|
+
}));
|
|
210
|
+
if (template.includes('lib')) return "lib";
|
|
211
|
+
return "app";
|
|
212
|
+
}
|
|
193
213
|
async function forgeTemplate({ projectType, argv, templateParameters, distFolder }) {
|
|
194
214
|
let framework = 'modern';
|
|
195
215
|
let roleType = "provider";
|
|
@@ -247,32 +267,11 @@ async function forgeTemplate({ projectType, argv, templateParameters, distFolder
|
|
|
247
267
|
};
|
|
248
268
|
const templateDir = getTemplateDir(templateName);
|
|
249
269
|
let commonTemplateDir = '';
|
|
250
|
-
|
|
251
|
-
|
|
270
|
+
if ("lib" === projectType) commonTemplateDir = 'templates/lib-common/';
|
|
271
|
+
else if ('app' === projectType) commonTemplateDir = `templates/${framework}-common/`;
|
|
272
|
+
if (commonTemplateDir) await renderTemplate(commonTemplateDir);
|
|
252
273
|
await renderTemplate(templateDir);
|
|
253
274
|
}
|
|
254
|
-
async function getProjectType(template) {
|
|
255
|
-
if (!template) return checkCancel(await (0, __WEBPACK_EXTERNAL_MODULE__clack_prompts_3cae1695__.select)({
|
|
256
|
-
message: 'Please select the type of project you want to create:',
|
|
257
|
-
options: [
|
|
258
|
-
{
|
|
259
|
-
value: "app",
|
|
260
|
-
label: 'Application'
|
|
261
|
-
},
|
|
262
|
-
{
|
|
263
|
-
value: "lib",
|
|
264
|
-
label: 'Lib'
|
|
265
|
-
},
|
|
266
|
-
{
|
|
267
|
-
value: "other",
|
|
268
|
-
label: 'Other'
|
|
269
|
-
}
|
|
270
|
-
]
|
|
271
|
-
}));
|
|
272
|
-
if (template.startsWith('create-')) return "other";
|
|
273
|
-
if (template.includes('lib')) return "lib";
|
|
274
|
-
return "app";
|
|
275
|
-
}
|
|
276
275
|
async function create({ name, templates }) {
|
|
277
276
|
const argv = (0, __WEBPACK_EXTERNAL_MODULE_minimist__["default"])(process.argv.slice(2), {
|
|
278
277
|
alias: {
|
|
@@ -293,6 +292,22 @@ async function create({ name, templates }) {
|
|
|
293
292
|
const pkgInfo = pkgFromUserAgent(process.env['npm_config_user_agent']);
|
|
294
293
|
const pkgManager = pkgInfo ? pkgInfo.name : 'npm';
|
|
295
294
|
const mfVersion = "0.10.0";
|
|
295
|
+
argv.template = templates.includes(argv.template || '') ? argv.template : void 0;
|
|
296
|
+
const projectType = await getProjectType(argv.template);
|
|
297
|
+
if ("zephyr" === projectType) {
|
|
298
|
+
const zephyrPackage = OTHER_TYPE['zephyr'].packageName;
|
|
299
|
+
const zephyrCommand = `${pkgManager} create ${zephyrPackage}`;
|
|
300
|
+
(0, __WEBPACK_EXTERNAL_MODULE__clack_prompts_3cae1695__.note)(`Running: ${zephyrCommand}`, 'Launching Zephyr setup');
|
|
301
|
+
(0, __WEBPACK_EXTERNAL_MODULE_child_process__.spawnSync)(pkgManager, [
|
|
302
|
+
'create',
|
|
303
|
+
zephyrPackage
|
|
304
|
+
], {
|
|
305
|
+
stdio: 'inherit',
|
|
306
|
+
shell: true
|
|
307
|
+
});
|
|
308
|
+
(0, __WEBPACK_EXTERNAL_MODULE__clack_prompts_3cae1695__.outro)('Done.');
|
|
309
|
+
return;
|
|
310
|
+
}
|
|
296
311
|
const mfName = argv.name || checkCancel(await (0, __WEBPACK_EXTERNAL_MODULE__clack_prompts_3cae1695__.text)({
|
|
297
312
|
message: 'Please input Module Federation name:',
|
|
298
313
|
placeholder: 'mf_project_name',
|
|
@@ -319,27 +334,6 @@ async function create({ name, templates }) {
|
|
|
319
334
|
}));
|
|
320
335
|
if ('no' === option) cancelAndExit();
|
|
321
336
|
}
|
|
322
|
-
argv.template = templates.includes(argv.template || '') ? argv.template : void 0;
|
|
323
|
-
const projectType = await getProjectType(argv.template);
|
|
324
|
-
if ("other" === projectType) {
|
|
325
|
-
const otherOptions = Object.keys(OTHER_TYPE).map((key)=>({
|
|
326
|
-
value: key,
|
|
327
|
-
label: OTHER_TYPE[key].label
|
|
328
|
-
}));
|
|
329
|
-
const otherProjectKey = checkCancel(await (0, __WEBPACK_EXTERNAL_MODULE__clack_prompts_3cae1695__.select)({
|
|
330
|
-
message: 'Please select the type of template you want to create:',
|
|
331
|
-
options: otherOptions
|
|
332
|
-
}));
|
|
333
|
-
const { command } = OTHER_TYPE[otherProjectKey];
|
|
334
|
-
const commandWithManager = command.replace(/^npm create /, `${pkgManager} create `);
|
|
335
|
-
const npmParams = 'npm' === pkgManager && pkgInfo?.version && parseInt(pkgInfo.version.split('.')[0], 10) < 7 ? ' --' : '';
|
|
336
|
-
const realCommand = `${commandWithManager}${npmParams} -d ${distFolder} -n ${mfName}${argv.override ? ' --override' : ''}`;
|
|
337
|
-
const [cmd, ...cmdArgs] = realCommand.split(' ');
|
|
338
|
-
const { status } = (0, __WEBPACK_EXTERNAL_MODULE_child_process__.spawnSync)(cmd, cmdArgs, {
|
|
339
|
-
stdio: 'inherit'
|
|
340
|
-
});
|
|
341
|
-
process.exit(status ?? 0);
|
|
342
|
-
}
|
|
343
337
|
await forgeTemplate({
|
|
344
338
|
projectType,
|
|
345
339
|
argv,
|
|
@@ -359,12 +353,11 @@ async function create({ name, templates }) {
|
|
|
359
353
|
}
|
|
360
354
|
const TEMPLATES = [
|
|
361
355
|
'provider-modern',
|
|
362
|
-
'consumer-modern',
|
|
363
356
|
'provider-rsbuild',
|
|
364
|
-
'consumer-rsbuild',
|
|
365
357
|
'rslib',
|
|
366
358
|
'rslib-storybook',
|
|
367
|
-
'
|
|
359
|
+
'consumer-modern',
|
|
360
|
+
'consumer-rsbuild'
|
|
368
361
|
];
|
|
369
362
|
create({
|
|
370
363
|
name: 'Module Federation',
|
package/package.json
CHANGED
|
@@ -0,0 +1,18 @@
|
|
|
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
|
+
server: {
|
|
16
|
+
port: 3001,
|
|
17
|
+
},
|
|
18
|
+
});
|
|
@@ -0,0 +1,11 @@
|
|
|
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
|
+
server: {
|
|
9
|
+
port: 3001,
|
|
10
|
+
},
|
|
11
|
+
});
|
|
File without changes
|
|
File without changes
|