create-module-federation 0.0.0-1737428758075 → 0.0.0-codex-node24-dev-node20-compat-ci-20260713063237
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 +119 -96
- package/package.json +20 -14
- package/templates/consumer-modern-ts/modern.config.ts +7 -0
- package/templates/consumer-modern-ts/module-federation.config.ts.handlebars +12 -0
- package/templates/consumer-modern-ts/src/routes/page.tsx +21 -0
- package/templates/consumer-rsbuild-ts/module-federation.config.ts.handlebars +13 -0
- package/templates/consumer-rsbuild-ts/rsbuild.config.ts +8 -0
- package/templates/consumer-rsbuild-ts/src/App.tsx +12 -0
- package/templates/lib-common/module-federation.config.ts.handlebars +17 -0
- package/templates/lib-common/rslib.config.ts +57 -0
- package/templates/lib-common/src/index.css +53 -0
- package/templates/lib-common/src/index.tsx +19 -0
- package/templates/lib-common/tsconfig.json +14 -0
- package/templates/modern-common/.browserslistrc +5 -0
- package/templates/modern-common/.vscode/extensions.json +14 -0
- package/templates/modern-common/.vscode/settings.json +88 -0
- package/templates/modern-common/README.md +37 -0
- package/templates/modern-common/biome.json +34 -0
- package/templates/modern-common/package.json.handlebars +44 -0
- package/templates/modern-common/src/modern-app-env.d.ts +3 -0
- package/templates/modern-common/src/modern.runtime.ts +3 -0
- package/templates/modern-common/src/routes/index.css +41 -0
- package/templates/modern-common/src/routes/layout.tsx +9 -0
- package/templates/modern-common/tsconfig.json +15 -0
- package/templates/provider-modern-ts/modern.config.ts +10 -0
- package/templates/provider-modern-ts/module-federation.config.ts.handlebars +12 -0
- package/templates/provider-modern-ts/src/components/ProviderComponent.css +52 -0
- package/templates/provider-modern-ts/src/components/ProviderComponent.tsx +19 -0
- package/templates/provider-modern-ts/src/routes/page.tsx +21 -0
- package/templates/provider-rsbuild-ts/module-federation.config.ts.handlebars +12 -0
- package/templates/provider-rsbuild-ts/rsbuild.config.ts +11 -0
- package/templates/provider-rsbuild-ts/src/App.tsx +12 -0
- package/templates/provider-rsbuild-ts/src/components/ProviderComponent.css +52 -0
- package/templates/provider-rsbuild-ts/src/components/ProviderComponent.tsx +19 -0
- package/templates/provider-rslib-storybook-ts/.storybook/main.ts.handlebars +41 -0
- package/templates/provider-rslib-storybook-ts/README.md +27 -0
- package/templates/provider-rslib-storybook-ts/package.json.handlebars +52 -0
- package/templates/provider-rslib-storybook-ts/stories/Index.stories.tsx +11 -0
- package/templates/provider-rslib-ts/README.md +17 -0
- package/templates/provider-rslib-ts/package.json.handlebars +37 -0
- package/templates/rsbuild-common/README.md +29 -0
- package/templates/rsbuild-common/package.json.handlebars +22 -0
- package/templates/rsbuild-common/public/.gitkeep +0 -0
- package/templates/rsbuild-common/src/App.css +15 -0
- package/templates/rsbuild-common/src/bootstrap.tsx +13 -0
- package/templates/rsbuild-common/src/env.d.ts +1 -0
- package/templates/rsbuild-common/src/index.tsx +1 -0
- package/templates/rsbuild-common/tsconfig.json +26 -0
- package/dist/LICENSE +0 -21
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
|
@@ -1,11 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import path_0 from "path";
|
|
3
|
+
import fs from "fs";
|
|
4
|
+
import { spawnSync } from "child_process";
|
|
5
|
+
import { fileURLToPath } from "url";
|
|
6
|
+
import { cancel, isCancel, multiselect, note, outro, select as prompts_select, text as prompts_text } from "@clack/prompts";
|
|
7
|
+
import minimist from "minimist";
|
|
8
|
+
import { logger } from "rslog";
|
|
9
|
+
import glob from "glob";
|
|
10
|
+
import { mkdir, readFile, writeFile } from "fs/promises";
|
|
11
|
+
import handlebars from "handlebars";
|
|
9
12
|
const IMAGE_EXT_LIST = [
|
|
10
13
|
'.jpg',
|
|
11
14
|
'.jpeg',
|
|
@@ -26,56 +29,58 @@ class FsResource {
|
|
|
26
29
|
this.resourceKey = resourceKey;
|
|
27
30
|
}
|
|
28
31
|
async value() {
|
|
29
|
-
const resourceFileExt =
|
|
32
|
+
const resourceFileExt = path_0.extname(this.filePath);
|
|
30
33
|
if (IMAGE_EXT_LIST.includes(resourceFileExt)) {
|
|
31
|
-
const buffer = await
|
|
34
|
+
const buffer = await readFile(path_0.resolve(this.filePath));
|
|
32
35
|
return {
|
|
33
36
|
content: buffer
|
|
34
37
|
};
|
|
35
38
|
}
|
|
36
|
-
const text = await
|
|
39
|
+
const text = await readFile(path_0.resolve(this.filePath), 'utf8');
|
|
37
40
|
return {
|
|
38
41
|
content: text
|
|
39
42
|
};
|
|
40
43
|
}
|
|
41
44
|
}
|
|
42
45
|
const promisifyGlob = (pattern, options)=>new Promise((resolve, reject)=>{
|
|
43
|
-
(
|
|
46
|
+
glob(pattern, options, (err, files)=>null === err ? resolve(files) : reject(err));
|
|
44
47
|
});
|
|
45
48
|
class FsMaterial {
|
|
46
49
|
constructor(basePath){
|
|
47
50
|
this.basePath = basePath;
|
|
48
51
|
}
|
|
49
52
|
get(resourceKey) {
|
|
50
|
-
return new FsResource(
|
|
53
|
+
return new FsResource(path_0.resolve(this.basePath, resourceKey), resourceKey);
|
|
51
54
|
}
|
|
52
55
|
async find(globStr, options) {
|
|
53
56
|
const matches = await promisifyGlob(globStr, {
|
|
54
|
-
cwd:
|
|
57
|
+
cwd: path_0.resolve(this.basePath),
|
|
55
58
|
nodir: options?.nodir,
|
|
56
59
|
dot: options?.dot,
|
|
57
60
|
ignore: options?.ignore
|
|
58
61
|
});
|
|
59
62
|
return matches.reduce((pre, cur)=>{
|
|
60
|
-
pre[cur] = new FsResource(
|
|
63
|
+
pre[cur] = new FsResource(path_0.resolve(this.basePath, cur), cur);
|
|
61
64
|
return pre;
|
|
62
65
|
}, {});
|
|
63
66
|
}
|
|
64
67
|
}
|
|
65
68
|
function renderString(template, fullData) {
|
|
66
|
-
return
|
|
69
|
+
return handlebars.compile(template)(fullData) || '';
|
|
67
70
|
}
|
|
68
71
|
async function outputFs(file, content, outputPath, options) {
|
|
69
|
-
const filePath =
|
|
70
|
-
await
|
|
71
|
-
|
|
72
|
+
const filePath = path_0.resolve(outputPath, file.toString());
|
|
73
|
+
await mkdir(path_0.dirname(filePath), {
|
|
74
|
+
recursive: true
|
|
75
|
+
});
|
|
76
|
+
await writeFile(filePath, content, options);
|
|
72
77
|
}
|
|
73
78
|
class HandlebarsAPI {
|
|
74
79
|
async renderTemplate(templateResource, target, outputFilePath, parameters = {}) {
|
|
75
80
|
if (templateResource._type !== FS_RESOURCE) throw new Error('resource not match');
|
|
76
81
|
const resourceValue = await templateResource.value();
|
|
77
82
|
if ('string' != typeof resourceValue.content) throw new Error(`resource.value is not string, resourceValue=${resourceValue}`);
|
|
78
|
-
await outputFs(target, renderString(resourceValue.content, parameters), outputFilePath, {
|
|
83
|
+
await outputFs(target, templateResource.resourceKey.endsWith('.handlebars') ? renderString(resourceValue.content, parameters) : resourceValue.content, outputFilePath, {
|
|
79
84
|
encoding: 'utf-8'
|
|
80
85
|
});
|
|
81
86
|
}
|
|
@@ -89,11 +94,21 @@ class HandlebarsAPI {
|
|
|
89
94
|
}));
|
|
90
95
|
}
|
|
91
96
|
}
|
|
97
|
+
const create_filename = fileURLToPath(import.meta.url);
|
|
98
|
+
const create_dirname = path_0.dirname(create_filename);
|
|
99
|
+
const packageDir = path_0.resolve(create_dirname, '..');
|
|
100
|
+
const OTHER_TYPE = {
|
|
101
|
+
zephyr: {
|
|
102
|
+
label: 'zephyr',
|
|
103
|
+
packageName: 'zephyr-apps@latest',
|
|
104
|
+
hint: 'create zephyr-apps@latest'
|
|
105
|
+
}
|
|
106
|
+
};
|
|
92
107
|
function upperFirst(str) {
|
|
93
108
|
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
94
109
|
}
|
|
95
110
|
function logHelpMessage(name, templates) {
|
|
96
|
-
|
|
111
|
+
logger.log(`
|
|
97
112
|
Usage: create-${name} [options]
|
|
98
113
|
|
|
99
114
|
Options:
|
|
@@ -101,11 +116,12 @@ function logHelpMessage(name, templates) {
|
|
|
101
116
|
-h, --help display help for command
|
|
102
117
|
-d, --dir create project in specified directory
|
|
103
118
|
-t, --template specify the template to use
|
|
119
|
+
-n, --name specify the mf name
|
|
120
|
+
-r, --role specify the mf role type: provider or consumer
|
|
104
121
|
--override override files in target directory
|
|
105
122
|
|
|
106
123
|
Templates:
|
|
107
|
-
|
|
108
|
-
${templates.join(', ')}
|
|
124
|
+
${templates.filter((t)=>!t.startsWith('zephyr')).join(', ')}
|
|
109
125
|
`);
|
|
110
126
|
}
|
|
111
127
|
function pkgFromUserAgent(userAgent) {
|
|
@@ -118,49 +134,31 @@ function pkgFromUserAgent(userAgent) {
|
|
|
118
134
|
};
|
|
119
135
|
}
|
|
120
136
|
function cancelAndExit() {
|
|
121
|
-
|
|
137
|
+
cancel('Operation cancelled.');
|
|
122
138
|
process.exit(0);
|
|
123
139
|
}
|
|
124
140
|
function checkCancel(value) {
|
|
125
|
-
if (
|
|
141
|
+
if (isCancel(value)) cancelAndExit();
|
|
126
142
|
return value;
|
|
127
143
|
}
|
|
128
|
-
function
|
|
144
|
+
function formatProjectName(input) {
|
|
145
|
+
const formatted = input.trim().replace(/\/+$/g, '');
|
|
129
146
|
return {
|
|
130
|
-
|
|
147
|
+
packageName: input,
|
|
148
|
+
targetDir: formatted
|
|
131
149
|
};
|
|
132
150
|
}
|
|
133
151
|
function isEmptyDir(path) {
|
|
134
|
-
const files =
|
|
152
|
+
const files = fs.readdirSync(path);
|
|
135
153
|
return 0 === files.length || 1 === files.length && '.git' === files[0];
|
|
136
154
|
}
|
|
137
155
|
async function getAppTemplateName({ roleType, framework }, { template }) {
|
|
138
156
|
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
157
|
return `${roleType}-${framework}-ts`;
|
|
160
158
|
}
|
|
161
|
-
async function getLibTemplateName({ template }) {
|
|
159
|
+
async function getLibTemplateName({ template, role }) {
|
|
162
160
|
if (template) return `${template}-ts`;
|
|
163
|
-
const templateName = checkCancel(await (
|
|
161
|
+
const templateName = checkCancel(await prompts_select({
|
|
164
162
|
message: 'Select template',
|
|
165
163
|
options: [
|
|
166
164
|
{
|
|
@@ -169,7 +167,7 @@ async function getLibTemplateName({ template }) {
|
|
|
169
167
|
}
|
|
170
168
|
]
|
|
171
169
|
}));
|
|
172
|
-
const tools = checkCancel(await
|
|
170
|
+
const tools = checkCancel(await multiselect({
|
|
173
171
|
message: 'Select development tools (Use <space> to select, <enter> to continue)',
|
|
174
172
|
required: false,
|
|
175
173
|
options: [
|
|
@@ -179,9 +177,9 @@ async function getLibTemplateName({ template }) {
|
|
|
179
177
|
}
|
|
180
178
|
].filter(Boolean)
|
|
181
179
|
}));
|
|
182
|
-
const roleType =
|
|
180
|
+
const roleType = role || "provider";
|
|
183
181
|
if (!tools || !Object.keys(tools).length) return `${roleType}-${templateName}-ts`;
|
|
184
|
-
return `${roleType}-${templateName}
|
|
182
|
+
return `${roleType}-${templateName}-${tools[0]}-ts`;
|
|
185
183
|
}
|
|
186
184
|
function getTemplateName({ projectType, roleType, framework }, args) {
|
|
187
185
|
if ('app' === projectType) return getAppTemplateName({
|
|
@@ -193,11 +191,32 @@ function getTemplateName({ projectType, roleType, framework }, args) {
|
|
|
193
191
|
function getTemplateDir(templateName) {
|
|
194
192
|
return `templates/${templateName}/`;
|
|
195
193
|
}
|
|
194
|
+
async function getProjectType(template) {
|
|
195
|
+
if (!template) return checkCancel(await prompts_select({
|
|
196
|
+
message: 'Please select the type of project you want to create:',
|
|
197
|
+
options: [
|
|
198
|
+
{
|
|
199
|
+
value: "app",
|
|
200
|
+
label: 'Application'
|
|
201
|
+
},
|
|
202
|
+
{
|
|
203
|
+
value: "lib",
|
|
204
|
+
label: 'Lib'
|
|
205
|
+
},
|
|
206
|
+
{
|
|
207
|
+
value: "zephyr",
|
|
208
|
+
label: 'Zephyr Powered (Learn more at https://zephyr-cloud.io)'
|
|
209
|
+
}
|
|
210
|
+
]
|
|
211
|
+
}));
|
|
212
|
+
if (template.includes('lib')) return "lib";
|
|
213
|
+
return "app";
|
|
214
|
+
}
|
|
196
215
|
async function forgeTemplate({ projectType, argv, templateParameters, distFolder }) {
|
|
197
216
|
let framework = 'modern';
|
|
198
|
-
let roleType =
|
|
199
|
-
if ('app' === projectType) {
|
|
200
|
-
framework = checkCancel(await (
|
|
217
|
+
let roleType = "provider";
|
|
218
|
+
if (!argv?.template && 'app' === projectType) {
|
|
219
|
+
framework = checkCancel(await prompts_select({
|
|
201
220
|
message: 'Select template',
|
|
202
221
|
options: [
|
|
203
222
|
{
|
|
@@ -210,7 +229,7 @@ async function forgeTemplate({ projectType, argv, templateParameters, distFolder
|
|
|
210
229
|
}
|
|
211
230
|
]
|
|
212
231
|
}));
|
|
213
|
-
roleType = checkCancel(await (
|
|
232
|
+
roleType = argv.role || checkCancel(await prompts_select({
|
|
214
233
|
message: 'Please select the role of project you want to create:',
|
|
215
234
|
initialValue: 'provider',
|
|
216
235
|
options: [
|
|
@@ -230,7 +249,7 @@ async function forgeTemplate({ projectType, argv, templateParameters, distFolder
|
|
|
230
249
|
framework,
|
|
231
250
|
roleType
|
|
232
251
|
}, argv);
|
|
233
|
-
const material = new FsMaterial(
|
|
252
|
+
const material = new FsMaterial(packageDir);
|
|
234
253
|
const renderTemplate = async (templateDir)=>{
|
|
235
254
|
const templatePattern = `${templateDir}**/*`;
|
|
236
255
|
const resourceMap = await material.find(templatePattern, {
|
|
@@ -250,40 +269,56 @@ async function forgeTemplate({ projectType, argv, templateParameters, distFolder
|
|
|
250
269
|
};
|
|
251
270
|
const templateDir = getTemplateDir(templateName);
|
|
252
271
|
let commonTemplateDir = '';
|
|
253
|
-
|
|
254
|
-
|
|
272
|
+
if ("lib" === projectType) commonTemplateDir = 'templates/lib-common/';
|
|
273
|
+
else if ('app' === projectType) commonTemplateDir = `templates/${framework}-common/`;
|
|
274
|
+
if (commonTemplateDir) await renderTemplate(commonTemplateDir);
|
|
255
275
|
await renderTemplate(templateDir);
|
|
256
276
|
}
|
|
257
277
|
async function create({ name, templates }) {
|
|
258
|
-
const argv = (
|
|
278
|
+
const argv = minimist(process.argv.slice(2), {
|
|
259
279
|
alias: {
|
|
260
280
|
h: 'help',
|
|
261
281
|
d: 'dir',
|
|
262
|
-
t: 'template'
|
|
282
|
+
t: 'template',
|
|
283
|
+
n: 'name',
|
|
284
|
+
r: 'role'
|
|
263
285
|
}
|
|
264
286
|
});
|
|
265
287
|
console.log('');
|
|
266
|
-
|
|
267
|
-
if (argv.help)
|
|
268
|
-
logHelpMessage(name, templates);
|
|
269
|
-
return;
|
|
270
|
-
}
|
|
288
|
+
logger.greet(`◆ Create ${upperFirst(name)} Project`);
|
|
289
|
+
if (argv.help) return void logHelpMessage(name, templates);
|
|
271
290
|
const cwd = process.cwd();
|
|
272
291
|
const pkgInfo = pkgFromUserAgent(process.env['npm_config_user_agent']);
|
|
273
292
|
const pkgManager = pkgInfo ? pkgInfo.name : 'npm';
|
|
274
|
-
const
|
|
293
|
+
const mfVersion = "0.0.0-codex-node24-dev-node20-compat-ci-20260713063237";
|
|
294
|
+
argv.template = templates.includes(argv.template || '') ? argv.template : void 0;
|
|
295
|
+
const projectType = await getProjectType(argv.template);
|
|
296
|
+
if ("zephyr" === projectType) {
|
|
297
|
+
const zephyrPackage = OTHER_TYPE['zephyr'].packageName;
|
|
298
|
+
const zephyrCommand = `${pkgManager} create ${zephyrPackage}`;
|
|
299
|
+
note(`Running: ${zephyrCommand}`, 'Launching Zephyr setup');
|
|
300
|
+
spawnSync(pkgManager, [
|
|
301
|
+
'create',
|
|
302
|
+
zephyrPackage
|
|
303
|
+
], {
|
|
304
|
+
stdio: 'inherit',
|
|
305
|
+
shell: true
|
|
306
|
+
});
|
|
307
|
+
outro('Done.');
|
|
308
|
+
return;
|
|
309
|
+
}
|
|
310
|
+
const mfName = argv.name || checkCancel(await prompts_text({
|
|
275
311
|
message: 'Please input Module Federation name:',
|
|
276
|
-
placeholder: '
|
|
277
|
-
defaultValue: '
|
|
312
|
+
placeholder: 'mf_project_name',
|
|
313
|
+
defaultValue: 'mf_project_name',
|
|
278
314
|
validate (value) {
|
|
279
315
|
if (0 === value.length) return 'Name is required';
|
|
280
316
|
}
|
|
281
317
|
}));
|
|
282
|
-
const
|
|
283
|
-
const
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
const option = checkCancel(await (0, __WEBPACK_EXTERNAL_MODULE__clack_prompts_3cae1695__.select)({
|
|
318
|
+
const { targetDir } = formatProjectName(path_0.join(argv.dir || mfName));
|
|
319
|
+
const distFolder = path_0.isAbsolute(targetDir) ? targetDir : path_0.join(cwd, targetDir);
|
|
320
|
+
if (!argv.override && fs.existsSync(distFolder) && !isEmptyDir(distFolder)) {
|
|
321
|
+
const option = checkCancel(await prompts_select({
|
|
287
322
|
message: `"${targetDir}" is not empty, please choose:`,
|
|
288
323
|
options: [
|
|
289
324
|
{
|
|
@@ -298,42 +333,30 @@ async function create({ name, templates }) {
|
|
|
298
333
|
}));
|
|
299
334
|
if ('no' === option) cancelAndExit();
|
|
300
335
|
}
|
|
301
|
-
const projectType = checkCancel(await (0, __WEBPACK_EXTERNAL_MODULE__clack_prompts_3cae1695__.select)({
|
|
302
|
-
message: 'Please select the type of project you want to create:',
|
|
303
|
-
options: [
|
|
304
|
-
{
|
|
305
|
-
value: 'app',
|
|
306
|
-
label: 'Application'
|
|
307
|
-
},
|
|
308
|
-
{
|
|
309
|
-
value: 'lib',
|
|
310
|
-
label: 'Lib'
|
|
311
|
-
}
|
|
312
|
-
]
|
|
313
|
-
}));
|
|
314
336
|
await forgeTemplate({
|
|
315
337
|
projectType,
|
|
316
338
|
argv,
|
|
317
339
|
templateParameters: {
|
|
318
|
-
mfName
|
|
340
|
+
mfName,
|
|
341
|
+
mfVersion
|
|
319
342
|
},
|
|
320
343
|
distFolder
|
|
321
344
|
});
|
|
322
345
|
const nextSteps = [
|
|
323
346
|
`cd ${targetDir}`,
|
|
324
347
|
`${pkgManager} install`,
|
|
325
|
-
`${pkgManager} run dev`
|
|
348
|
+
`${pkgManager} run ${"lib" === projectType ? 'mf-dev' : 'dev'}`
|
|
326
349
|
];
|
|
327
|
-
|
|
328
|
-
|
|
350
|
+
note(nextSteps.join('\n'), 'Next steps');
|
|
351
|
+
outro('Done.');
|
|
329
352
|
}
|
|
330
353
|
const TEMPLATES = [
|
|
331
354
|
'provider-modern',
|
|
332
|
-
'consumer-modern',
|
|
333
355
|
'provider-rsbuild',
|
|
334
|
-
'
|
|
335
|
-
'rslib',
|
|
336
|
-
'
|
|
356
|
+
'provider-rslib',
|
|
357
|
+
'provider-rslib-storybook',
|
|
358
|
+
'consumer-modern',
|
|
359
|
+
'consumer-rsbuild'
|
|
337
360
|
];
|
|
338
361
|
create({
|
|
339
362
|
name: 'Module Federation',
|
package/package.json
CHANGED
|
@@ -3,42 +3,48 @@
|
|
|
3
3
|
"description": "Create a new Module Federation project",
|
|
4
4
|
"public": true,
|
|
5
5
|
"sideEffects": false,
|
|
6
|
-
"version": "0.0.0-
|
|
6
|
+
"version": "0.0.0-codex-node24-dev-node20-compat-ci-20260713063237",
|
|
7
7
|
"license": "MIT",
|
|
8
8
|
"repository": {
|
|
9
9
|
"type": "git",
|
|
10
|
-
"url": "https://github.com/module-federation/core
|
|
10
|
+
"url": "git+https://github.com/module-federation/core.git",
|
|
11
11
|
"directory": "packages/create-module-federation"
|
|
12
12
|
},
|
|
13
13
|
"publishConfig": {
|
|
14
14
|
"access": "public"
|
|
15
15
|
},
|
|
16
16
|
"type": "module",
|
|
17
|
-
"
|
|
18
|
-
"
|
|
17
|
+
"exports": {
|
|
18
|
+
".": "./dist/index.js"
|
|
19
|
+
},
|
|
20
|
+
"engines": {
|
|
21
|
+
"node": ">=16.7.0"
|
|
19
22
|
},
|
|
20
|
-
"main": "./dist/index.js",
|
|
21
23
|
"bin": {
|
|
22
24
|
"create-module-federation": "./dist/index.js"
|
|
23
25
|
},
|
|
24
26
|
"files": [
|
|
25
|
-
"
|
|
27
|
+
"templates",
|
|
26
28
|
"dist"
|
|
27
29
|
],
|
|
28
30
|
"dependencies": {
|
|
29
|
-
"@clack/prompts": "
|
|
31
|
+
"@clack/prompts": "0.8.2",
|
|
30
32
|
"execa": "5.1.1",
|
|
31
|
-
"
|
|
32
|
-
"
|
|
33
|
-
"rslog": "^1.2.3",
|
|
33
|
+
"minimist": "1.2.8",
|
|
34
|
+
"rslog": "1.2.3",
|
|
34
35
|
"glob": "7.2.0",
|
|
35
|
-
"handlebars": "4.7.
|
|
36
|
+
"handlebars": "4.7.9"
|
|
36
37
|
},
|
|
37
38
|
"devDependencies": {
|
|
38
39
|
"@types/glob": "7.2.0",
|
|
39
40
|
"@types/minimist": "^1.2.5",
|
|
40
|
-
"@
|
|
41
|
-
"@rslib/core": "^0.3.1",
|
|
41
|
+
"@rslib/core": "^0.23.2",
|
|
42
42
|
"rsbuild-plugin-publint": "^0.2.1"
|
|
43
|
+
},
|
|
44
|
+
"scripts": {
|
|
45
|
+
"build": "rslib build",
|
|
46
|
+
"lint": "ESLINT_USE_FLAT_CONFIG=false pnpm exec eslint --ignore-pattern node_modules \"**/*.ts\" \"package.json\"",
|
|
47
|
+
"test": "node scripts/verify-rslib-templates.mjs",
|
|
48
|
+
"pre-release": "pnpm run test && pnpm run build"
|
|
43
49
|
}
|
|
44
|
-
}
|
|
50
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { appTools, defineConfig } from '@modern-js/app-tools';
|
|
2
|
+
import { moduleFederationPlugin } from '@module-federation/modern-js-v3';
|
|
3
|
+
|
|
4
|
+
// https://modernjs.dev/en/configure/app/usage
|
|
5
|
+
export default defineConfig({
|
|
6
|
+
plugins: [appTools(), moduleFederationPlugin()],
|
|
7
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { createModuleFederationConfig } from '@module-federation/modern-js-v3';
|
|
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,13 @@
|
|
|
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
|
+
shareStrategy: 'loaded-first',
|
|
9
|
+
shared: {
|
|
10
|
+
react: { singleton: true },
|
|
11
|
+
'react-dom': { singleton: true },
|
|
12
|
+
},
|
|
13
|
+
});
|
|
@@ -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,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,57 @@
|
|
|
1
|
+
import { pluginReact } from '@rsbuild/plugin-react';
|
|
2
|
+
import { defineConfig } from '@rslib/core';
|
|
3
|
+
import { pluginModuleFederation } from '@module-federation/rsbuild-plugin';
|
|
4
|
+
import { pluginPublint } from 'rsbuild-plugin-publint';
|
|
5
|
+
import moduleFederationConfig from './module-federation.config';
|
|
6
|
+
import pkg from './package.json';
|
|
7
|
+
|
|
8
|
+
const shared = {
|
|
9
|
+
dts: {
|
|
10
|
+
bundle: false,
|
|
11
|
+
},
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export default defineConfig({
|
|
15
|
+
lib: [
|
|
16
|
+
{
|
|
17
|
+
...shared,
|
|
18
|
+
format: 'esm',
|
|
19
|
+
output: {
|
|
20
|
+
distPath: {
|
|
21
|
+
root: './dist/esm',
|
|
22
|
+
},
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
...shared,
|
|
27
|
+
format: 'cjs',
|
|
28
|
+
output: {
|
|
29
|
+
distPath: {
|
|
30
|
+
root: './dist/cjs',
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
...shared,
|
|
36
|
+
format: 'mf',
|
|
37
|
+
output: {
|
|
38
|
+
// set unpkg cdn as assetPrefix if you want to publish
|
|
39
|
+
assetPrefix:
|
|
40
|
+
process.env.NODE_ENV === 'production'
|
|
41
|
+
? `https://unpkg.com/${pkg.name}@latest/dist/mf/`
|
|
42
|
+
: undefined,
|
|
43
|
+
distPath: {
|
|
44
|
+
root: './dist/mf',
|
|
45
|
+
},
|
|
46
|
+
},
|
|
47
|
+
},
|
|
48
|
+
],
|
|
49
|
+
server: {
|
|
50
|
+
port: 3001,
|
|
51
|
+
},
|
|
52
|
+
plugins: [
|
|
53
|
+
pluginReact(),
|
|
54
|
+
pluginModuleFederation(moduleFederationConfig),
|
|
55
|
+
pluginPublint(),
|
|
56
|
+
],
|
|
57
|
+
});
|