Skip to content

Commit

Permalink
feat(angular): remove unnecessarily generated code for remotes (#9844)
Browse files Browse the repository at this point in the history
  • Loading branch information
Coly010 committed Apr 19, 2022
1 parent 4f1c14c commit fc235de
Showing 1 changed file with 66 additions and 1 deletion.
67 changes: 66 additions & 1 deletion packages/angular/src/generators/remote/remote.ts
@@ -1,4 +1,4 @@
import type { Tree } from '@nrwl/devkit';
import { joinPathFragments, Tree } from '@nrwl/devkit';
import type { Schema } from './schema';
import { getProjects, readProjectConfiguration } from '@nrwl/devkit';
import applicationGenerator from '../application/application';
Expand Down Expand Up @@ -36,5 +36,70 @@ export default async function remote(tree: Tree, options: Schema) {
port: options.port ?? findNextAvailablePort(tree),
});

removeDeadCode(tree, options);

return installTask;
}

function removeDeadCode(tree: Tree, options: Schema) {
const project = readProjectConfiguration(tree, options.name);

['css', 'less', 'scss', 'sass'].forEach((style) => {
const pathToComponentStyle = joinPathFragments(
project.sourceRoot,
`app/app.component.${style}`
);
if (tree.exists(pathToComponentStyle)) {
tree.delete(pathToComponentStyle);
}
});

tree.delete(
joinPathFragments(project.sourceRoot, 'app/nx-welcome.component.ts')
);
tree.delete(
joinPathFragments(project.sourceRoot, 'app/app.component.spec.ts')
);
tree.delete(joinPathFragments(project.sourceRoot, 'app/app.component.html'));

const pathToComponent = joinPathFragments(
project.sourceRoot,
'app/app.component.ts'
);
const component =
tree.read(pathToComponent, 'utf-8').split('templateUrl')[0] +
`template: '<router-outlet></router-outlet>'
})
export class AppComponent {}`;

tree.write(pathToComponent, component);

tree.write(
joinPathFragments(project.sourceRoot, 'app/app.module.ts'),
`/*
* This RemoteEntryModule is imported here to allow TS to find the Module during
* compilation, allowing it to be included in the built bundle. This is required
* for the Module Federation Plugin to expose the Module correctly.
* */
import { RemoteEntryModule } from './remote-entry/entry.module';
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import { RouterModule } from '@angular/router';
@NgModule({
declarations: [AppComponent],
imports: [
BrowserModule,
RouterModule.forRoot([{
path: '',
loadChildren: () => import('./remote-entry/entry.module').then(m => m.RemoteEntryModule)
}], { initialNavigation: 'enabledBlocking' }),
],
providers: [],
bootstrap: [AppComponent],
})
export class AppModule {}`
);
}

0 comments on commit fc235de

Please sign in to comment.