From ab979a67372bde848ba884118ae4f2e456d12a8b Mon Sep 17 00:00:00 2001 From: Manfred Steyer Date: Sun, 11 Oct 2020 01:59:10 +0200 Subject: [PATCH] make port a number in angular.json --- e2e/mf-e2e/tests/mf.test.ts | 2 +- packages/mf/README.md | 4 +++ packages/mf/package.json | 12 +++++++- packages/mf/src/create-config.ts | 1 + packages/mf/src/schematics/mf/schematic.ts | 32 +++++++++++----------- 5 files changed, 33 insertions(+), 18 deletions(-) diff --git a/e2e/mf-e2e/tests/mf.test.ts b/e2e/mf-e2e/tests/mf.test.ts index ac824de9..56d06013 100644 --- a/e2e/mf-e2e/tests/mf.test.ts +++ b/e2e/mf-e2e/tests/mf.test.ts @@ -14,7 +14,7 @@ describe('mf e2e', () => { fs.writeFileSync('tmp/nx-e2e/proj/angular.json', angularJson); fs.mkdirSync('tmp/nx-e2e/proj/apps/shell'); - await runNxCommandAsync(`generate @angular-architects/module-federation:init shell 5000`); + await runNxCommandAsync(`generate @angular-architects/module-federation:config shell 5000`); expect(fs.existsSync('tmp/nx-e2e/proj/apps/shell/webpack.config.js')).toBeTruthy(); expect(fs.existsSync('tmp/nx-e2e/proj/apps/shell/webpack.prod.config.js')).toBeTruthy(); diff --git a/packages/mf/README.md b/packages/mf/README.md index 1aa828ae..68e86888 100644 --- a/packages/mf/README.md +++ b/packages/mf/README.md @@ -35,6 +35,10 @@ Big thanks to the following people who helped to make this possible: - Run **yarn** to install all packages +## Example + +See https://github.com/manfredsteyer/module-federation-plugin-example + ## More Details Have a look at this [article series about Module Federation](https://www.angulararchitects.io/aktuelles/the-microfrontend-revolution-part-2-module-federation-with-angular/) diff --git a/packages/mf/package.json b/packages/mf/package.json index 659123b4..cdc4415e 100644 --- a/packages/mf/package.json +++ b/packages/mf/package.json @@ -1,6 +1,16 @@ { "name": "@angular-architects/module-federation", - "version": "0.9.0", + "version": "0.9.3", + "access": "public", + "repository": { + "type": "GitHub", + "url": "https://github.com/angular-architects/module-federation-plugin" + }, + "author": { + "name": "Manfred Steyer", + "email": "manfred.steyer@gmx.net", + "url": "https://www.angulararchitects.io" + }, "main": "src/index.js", "schematics": "./collection.json", "builders": "./builders.json", diff --git a/packages/mf/src/create-config.ts b/packages/mf/src/create-config.ts index 655c7323..6422579d 100644 --- a/packages/mf/src/create-config.ts +++ b/packages/mf/src/create-config.ts @@ -13,6 +13,7 @@ export function createConfig(projectName: string, root: string, port: number): s }, plugins: [ new ModuleFederationPlugin({ + // For remotes (please adjust) /* name: "${projectName}", diff --git a/packages/mf/src/schematics/mf/schematic.ts b/packages/mf/src/schematics/mf/schematic.ts index fe890334..4db9ffc3 100644 --- a/packages/mf/src/schematics/mf/schematic.ts +++ b/packages/mf/src/schematics/mf/schematic.ts @@ -87,26 +87,26 @@ export default function config (options: MfSchematicSchema): Rule { tree.create(configPath, webpackConfig); tree.create(configProdPath, prodConfig); - // const useYarn = (workspace.cli?.packageManager === 'yarn'); + projectConfig.architect.build.options.extraWebpackConfig = configPath; + projectConfig.architect.build.configurations.production.extraWebpackConfig = configProdPath; + projectConfig.architect.serve.options.extraWebpackConfig = configPath; + projectConfig.architect.serve.options.port = port; + projectConfig.architect.serve.configurations.production.extraWebpackConfig = configProdPath; + projectConfig.architect.test.options.extraWebpackConfig = configPath; - // if (useYarn) { - // await yarnAdd('ngx-build-plus'); - // } - // else { - // await npmInstall('ngx-build-plus'); - // } + tree.overwrite('angular.json', JSON.stringify(workspace, null, '\t')); return chain([ externalSchematic('ngx-build-plus', 'ng-add', { project: options.project }), - updateWorkspace((workspace) => { - const proj = workspace.projects.get(options.project); - proj.targets.get('build').options.extraWebpackConfig = configPath; - proj.targets.get('build').configurations.production.extraWebpackConfig = configProdPath; - proj.targets.get('serve').options.extraWebpackConfig = configPath; - proj.targets.get('serve').options.port = options.port; - proj.targets.get('serve').configurations.production.extraWebpackConfig = configProdPath; - proj.targets.get('test').options.extraWebpackConfig = configPath; - }) + // updateWorkspace((workspace) => { + // const proj = workspace.projects.get(options.project); + // proj.targets.get('build').options.extraWebpackConfig = configPath; + // proj.targets.get('build').configurations.production.extraWebpackConfig = configProdPath; + // proj.targets.get('serve').options.extraWebpackConfig = configPath; + // proj.targets.get('serve').options.port = port; + // proj.targets.get('serve').configurations.production.extraWebpackConfig = configProdPath; + // proj.targets.get('test').options.extraWebpackConfig = configPath; + // }) ]); }