Skip to content

Commit c19a0aa

Browse files
committed
don't comment out SharedMappings in webpack config
1 parent 12528da commit c19a0aa

File tree

4 files changed

+30
-10
lines changed

4 files changed

+30
-10
lines changed

packages/mf/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@angular-architects/module-federation",
3-
"version": "1.2.0-rc.5",
3+
"version": "1.2.0-rc.9",
44
"license": "MIT",
55
"repository": {
66
"type": "GitHub",

packages/mf/src/schematics/mf/schematic.ts

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ function makeMainAsync(main: string): Rule {
6161

6262
const mainContent = tree.read(main);
6363
tree.create(bootstrapName, mainContent);
64-
tree.overwrite(main, "import('./bootstrap');")
64+
tree.overwrite(main, "import('./bootstrap');\n");
6565

6666
}
6767
}
@@ -107,7 +107,8 @@ export default function config (options: MfSchematicSchema): Rule {
107107
throw new Error(`Port must be a number!`);
108108
}
109109

110-
const webpackConfig = createConfig(projectName, relTsConfigPath, projectRoot, port);
110+
const remotes = generateRemoteConfig(workspace, projectName);
111+
const webpackConfig = createConfig(projectName, remotes, relTsConfigPath, projectRoot, port);
111112

112113
tree.create(configPath, webpackConfig);
113114
tree.create(configProdPath, prodConfig);
@@ -138,3 +139,21 @@ export default function config (options: MfSchematicSchema): Rule {
138139
}
139140
}
140141

142+
function generateRemoteConfig(workspace: any, projectName: string) {
143+
let remotes = '';
144+
for (const p in workspace.projects) {
145+
const project = workspace.projects[p];
146+
const projectType = project.projectType ?? 'application';
147+
148+
if (p !== projectName && projectType === 'application') {
149+
const pPort = project.architect.serve.options.port ?? 4200;
150+
remotes += ` // "${p}": "${p}@http://localhost:${pPort}/remoteEntry.js",\n`;
151+
}
152+
}
153+
154+
if (!remotes) {
155+
remotes = ' // "mfe1": "mfe1@http://localhost:3000/remoteEntry.js",\n';
156+
}
157+
return remotes;
158+
}
159+

packages/mf/src/utils/create-config.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
export function createConfig(projectName: string, tsConfigName: string, root: string, port: number): string {
1+
export function createConfig(projectName: string, remotes: string, tsConfigName: string, root: string, port: number): string {
22

33
return `const ModuleFederationPlugin = require("webpack/lib/container/ModuleFederationPlugin");
44
const mf = require("@angular-architects/module-federation/webpack");
55
const path = require("path");
66
77
const sharedMappings = new mf.SharedMappings();
8-
sharedMappings.register(path.join(__dirname, '${tsConfigName}'));
8+
sharedMappings.register(
9+
path.join(__dirname, '${tsConfigName}'),
10+
[/* mapped paths to share */]);
911
1012
module.exports = {
1113
output: {
@@ -27,21 +29,19 @@ module.exports = {
2729
2830
// For hosts (please adjust)
2931
// remotes: {
30-
// 'mfe1': "mfe1@http://localhost:3000/remoteEntry.js"
32+
${remotes}
3133
// },
3234
3335
shared: {
3436
"@angular/core": { singleton: true, strictVersion: true },
3537
"@angular/common": { singleton: true, strictVersion: true },
3638
"@angular/router": { singleton: true, strictVersion: true },
3739
38-
// Uncomment for sharing lib of an Angular CLI or Nx workspace
39-
// ...sharedMappings.getDescriptors()
40+
...sharedMappings.getDescriptors()
4041
}
4142
4243
}),
43-
// Uncomment for sharing lib of an Angular CLI or Nx workspace
44-
// sharedMappings.getPlugin(),
44+
sharedMappings.getPlugin(),
4545
],
4646
};
4747
`;

packages/mf/webpack.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './src/webpack';

0 commit comments

Comments
 (0)