Skip to content

Commit f9d45ec

Browse files
authored
docs: migrate iframe to standalone (#8859)
* docs: migrate iframe to standalone * docs: remove useless templates
1 parent 2762b0a commit f9d45ec

File tree

9 files changed

+45
-219
lines changed

9 files changed

+45
-219
lines changed

scripts/site/_site/iframe/app/app.component.html

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
import { Component } from '@angular/core';
2+
import { RouterOutlet } from '@angular/router';
23

34
@Component({
45
selector: 'app-root',
5-
templateUrl: './app.component.html'
6+
standalone: true,
7+
imports: [RouterOutlet],
8+
template: `<router-outlet></router-outlet>`
69
})
710
export class AppComponent {}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { provideHttpClient, withFetch, withJsonpSupport } from '@angular/common/http';
2+
import { ApplicationConfig } from '@angular/core';
3+
import { provideRouter } from '@angular/router';
4+
import { provideAnimationsAsync } from '@angular/platform-browser/animations/async';
5+
6+
import { IconDefinition } from '@ant-design/icons-angular';
7+
import * as AllIcons from '@ant-design/icons-angular/icons';
8+
import { provideNzIcons } from 'ng-zorro-antd/icon';
9+
10+
import { routes } from './app.routes';
11+
12+
const antDesignIcons = AllIcons as {
13+
[key: string]: IconDefinition;
14+
};
15+
const icons: IconDefinition[] = Object.keys(antDesignIcons).map(key => antDesignIcons[key])
16+
17+
export const appConfig: ApplicationConfig = {
18+
providers: [
19+
provideNzIcons(icons),
20+
provideRouter(routes),
21+
provideHttpClient(withJsonpSupport(), withFetch()),
22+
provideAnimationsAsync()
23+
]
24+
};
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { Routes } from '@angular/router';
2+
3+
export const routes: Routes = [];

scripts/site/_site/iframe/main.ts

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,6 @@
1-
import { registerLocaleData } from '@angular/common';
2-
import zh from '@angular/common/locales/zh';
3-
import { enableProdMode } from '@angular/core';
4-
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
1+
import { bootstrapApplication } from '@angular/platform-browser';
52

6-
import { AppModule } from './app/app.module';
7-
import { environment } from './environments/environment';
3+
import { AppComponent } from './app/app.component';
4+
import { appConfig } from './app/app.config';
85

9-
registerLocaleData(zh);
10-
11-
if (environment.production) {
12-
enableProdMode();
13-
}
14-
15-
platformBrowserDynamic()
16-
.bootstrapModule(AppModule)
17-
.catch(err => console.log(err));
6+
bootstrapApplication(AppComponent, appConfig).catch(err => console.log(err));

scripts/site/template/app.module.template.ts

Lines changed: 0 additions & 39 deletions
This file was deleted.
Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { Routes } from '@angular/router';
2-
{{importPart}}
2+
3+
{{imports}}
4+
35
export const routes: Routes = [
4-
{{routingPart}}
5-
];
6+
{{routes}}
7+
];

scripts/site/template/ng-zorro-antd.module.template.ts

Lines changed: 0 additions & 146 deletions
This file was deleted.
Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,22 @@
11
const fs = require('fs-extra');
22
const path = require('path');
3-
const routingTemplate = String(fs.readFileSync(path.resolve(__dirname, '../template/app.routing.module.template.ts')));
4-
const moduleTemplate = String(fs.readFileSync(path.resolve(__dirname, '../template/app.module.template.ts')));
5-
const zorroModule = String(fs.readFileSync(path.resolve(__dirname, '../template/ng-zorro-antd.module.template.ts')));
3+
const routesTemplate = String(fs.readFileSync(path.resolve(__dirname, '../template/iframe.routes.template.ts')));
64

75
module.exports = function (iframeTargetPath, componentsMap) {
8-
let routing = routingTemplate;
9-
let module = moduleTemplate;
6+
let routes = routesTemplate;
107
let importPart = '';
118
let routingPart = '';
12-
let declarationPart = '';
139
for (const key in componentsMap) {
1410
const demoMap = componentsMap[key];
1511
for (const innerKey in demoMap) {
1612
if (demoMap[innerKey].meta.iframe) {
1713
fs.writeFileSync(path.join(iframeTargetPath, `${key}-${innerKey}.ts`), demoMap[innerKey].ts);
1814
importPart = `import { ${demoMap[innerKey].name} } from './${key}-${innerKey}';\n${importPart}`;
1915
routingPart = ` { path: '${key}-${innerKey}', component: ${demoMap[innerKey].name} },\n${routingPart}`;
20-
declarationPart = ` ${demoMap[innerKey].name},\n${declarationPart}`;
2116
}
2217
}
2318
}
24-
routing = routing.replace(/{{importPart}}/g, importPart);
25-
routing = routing.replace(/{{routingPart}}/g, routingPart);
26-
module = module.replace(/{{importPart}}/g, importPart);
27-
module = module.replace(/{{declarationPart}}/g, declarationPart);
28-
fs.writeFileSync(path.join(iframeTargetPath, `app.routing.module.ts`), routing);
29-
fs.writeFileSync(path.join(iframeTargetPath, `app.module.ts`), module);
30-
fs.writeFileSync(path.join(iframeTargetPath, `ng-zorro-antd.module.ts`), zorroModule);
19+
routes = routes.replace(/{{imports}}/g, importPart);
20+
routes = routes.replace(/{{routes}}/g, routingPart);
21+
fs.writeFileSync(path.join(iframeTargetPath, `app.routes.ts`), routes);
3122
};

0 commit comments

Comments
 (0)