Skip to content

Commit 6fad00f

Browse files
committed
perf: change build method
1 parent 49b31e5 commit 6fad00f

7 files changed

Lines changed: 104 additions & 59 deletions

File tree

angular.json

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,19 @@
4949
"scripts": [
5050
"jquery/dist/jquery.min.js",
5151
"@ztree/ztree_v3/js/jquery.ztree.all.min.js",
52-
"@ztree/ztree_v3/js/jquery.ztree.exhide.min.js",
53-
"asciinema-player/dist/bundle/asciinema-player.min.js"
52+
"@ztree/ztree_v3/js/jquery.ztree.exhide.min.js"
5453
]
5554
},
5655
"configurations": {
5756
"production": {
58-
"optimization": true,
57+
"optimization": {
58+
"scripts": true,
59+
"styles": {
60+
"minify": true,
61+
"inlineCritical": false
62+
},
63+
"fonts": true
64+
},
5965
"outputHashing": "all",
6066
"baseHref": "/luna/",
6167
"outputPath": {
@@ -68,8 +74,13 @@
6874
"budgets": [
6975
{
7076
"type": "initial",
71-
"maximumWarning": "5mb",
77+
"maximumWarning": "4mb",
7278
"maximumError": "6mb"
79+
},
80+
{
81+
"type": "anyComponentStyle",
82+
"maximumWarning": "200kb",
83+
"maximumError": "300kb"
7384
}
7485
],
7586
"fileReplacements": [

src/app/elements/replay/asciicast/asciicast.component.ts

Lines changed: 47 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ import { formatTime } from '@app/utils/common';
55
import { HttpService } from '@app/services';
66
import { filter } from 'rxjs';
77

8-
declare const AsciinemaPlayer: any;
9-
108
@Component({
119
standalone: false,
1210
selector: 'elements-replay-asciicast',
@@ -29,6 +27,7 @@ export class ElementReplayAsciicastComponent implements OnInit, AfterViewInit {
2927
startTimeStamp = null;
3028
commands: Command[];
3129
page = 0;
30+
private AsciinemaPlayer: any;
3231

3332
constructor(
3433
private route: ActivatedRoute,
@@ -37,7 +36,10 @@ export class ElementReplayAsciicastComponent implements OnInit, AfterViewInit {
3736
this.startAt = 0;
3837
}
3938

40-
ngOnInit() {
39+
async ngOnInit() {
40+
// 动态加载 asciinema-player
41+
await this.loadAsciinemaPlayer();
42+
4143
this.commands = new Array<Command>();
4244
const start = new Date(this.replay.date_start);
4345
const end = new Date(this.replay.date_end);
@@ -62,38 +64,60 @@ export class ElementReplayAsciicastComponent implements OnInit, AfterViewInit {
6264
this.getCommands(this.page);
6365
}
6466

67+
private async loadAsciinemaPlayer() {
68+
try {
69+
// 动态导入 asciinema-player
70+
const module = await import('asciinema-player');
71+
this.AsciinemaPlayer = module.default || module;
72+
} catch (error) {
73+
console.error('Failed to load asciinema-player:', error);
74+
// 如果动态导入失败,尝试从全局变量获取(兼容性)
75+
this.AsciinemaPlayer = (window as any).AsciinemaPlayer;
76+
}
77+
}
78+
6579
ngAfterViewInit() {
66-
this.player = this.createPlayer();
67-
this.player.play();
68-
this.isPlaying = true;
69-
this.createTimer();
80+
if (this.AsciinemaPlayer) {
81+
this.player = this.createPlayer();
82+
this.player.play();
83+
this.isPlaying = true;
84+
this.createTimer();
85+
}
7086
}
7187

7288
@HostListener('window:resize', ['$event'])
7389
onResize(event: Event) {
7490
this.rows = Math.min(25, Math.floor((window.innerHeight - 120) / 16));
75-
this.currentTime = this.player.getCurrentTime();
76-
this.resetPlayer();
91+
if (this.player) {
92+
this.currentTime = this.player.getCurrentTime();
93+
this.resetPlayer();
94+
}
7795
}
7896

7997
speedDown() {
8098
if (this.speed <= 1) {
8199
return;
82100
}
83101
this.speed--;
84-
this.currentTime = this.player.getCurrentTime();
85-
this.resetPlayer();
86-
this.player.seek(this.currentTime);
102+
if (this.player) {
103+
this.currentTime = this.player.getCurrentTime();
104+
this.resetPlayer();
105+
this.player.seek(this.currentTime);
106+
}
87107
}
88108

89109
speedUp() {
90110
this.speed++;
91-
this.currentTime = this.player.getCurrentTime();
92-
this.resetPlayer();
93-
this.player.seek(this.currentTime);
111+
if (this.player) {
112+
this.currentTime = this.player.getCurrentTime();
113+
this.resetPlayer();
114+
this.player.seek(this.currentTime);
115+
}
94116
}
95117

96118
toggle() {
119+
if (!this.player) return;
120+
97121
clearInterval(this.timer);
98122
if (this.isPlaying) {
99123
this.player.pause();
@@ -126,7 +150,7 @@ export class ElementReplayAsciicastComponent implements OnInit, AfterViewInit {
126150

127151
resetPlayer() {
128152
clearInterval(this.timer);
129-
if (!this.player) {
153+
if (!this.player || !this.AsciinemaPlayer) {
130154
return;
131155
}
132156
this.player.pause();
@@ -148,9 +172,13 @@ export class ElementReplayAsciicastComponent implements OnInit, AfterViewInit {
148172
}
149173

150174
createPlayer() {
175+
if (!this.AsciinemaPlayer) {
176+
console.error('AsciinemaPlayer not loaded');
177+
return null;
178+
}
151179
const el = document.getElementById('screen');
152180
const opt = this.getPlayerOptions();
153-
return AsciinemaPlayer.create(this.replay.src, el, opt);
181+
return this.AsciinemaPlayer.create(this.replay.src, el, opt);
154182
}
155183

156184
getUserLang() {
@@ -191,6 +219,8 @@ export class ElementReplayAsciicastComponent implements OnInit, AfterViewInit {
191219
}
192220

193221
commandClick(item: Command) {
222+
if (!this.player) return;
223+
194224
const startPlayTime = new Date(this.replay.date_start).getTime() / 1000;
195225
const instructStartTime = item.timestamp - 5 - startPlayTime;
196226
const time = instructStartTime > 0 ? instructStartTime : 0;

src/app/plugins/ZorroModule.component.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ import { NzPopconfirmModule } from 'ng-zorro-antd/popconfirm';
3030
import { NzFloatButtonModule } from 'ng-zorro-antd/float-button';
3131
import { NzInputNumberModule } from 'ng-zorro-antd/input-number';
3232
import { NzDescriptionsModule } from 'ng-zorro-antd/descriptions';
33+
import { NzMessageModule } from 'ng-zorro-antd/message';
34+
import { NzNotificationModule } from 'ng-zorro-antd/notification';
3335

3436
@NgModule({
3537
exports: [
@@ -63,7 +65,9 @@ import { NzDescriptionsModule } from 'ng-zorro-antd/descriptions';
6365
NzPopconfirmModule,
6466
NzFloatButtonModule,
6567
NzInputNumberModule,
66-
NzDescriptionsModule
68+
NzDescriptionsModule,
69+
NzMessageModule,
70+
NzNotificationModule
6771
]
6872
})
6973
export class NgZorroAntdModule {}

src/app/router.module.ts

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,45 @@ import { NgModule } from '@angular/core';
22
import { RouterModule, Routes } from '@angular/router';
33

44
import { PageMainComponent } from './pages/main/main.component';
5-
import { PageSftpComponent } from './pages/sftp/sftp.component';
65
import { PagesBlankComponent } from './pages/blank/blank.component';
7-
import { PagesShareComponent } from './pages/share/share.component';
8-
import { PageDirectComponent } from './pages/direct/direct.component';
9-
import { PagesReplayComponent } from './pages/replay/replay.component';
10-
import { PagesConnectComponent } from './pages/connect/connect.component';
11-
import { PagesMonitorComponent } from './pages/monitor/monitor.component';
12-
import { PagesKubernetesComponent } from './pages/kubernetes/kubernetes.component';
6+
import { PagesShareComponent } from './pages/share/share.component';
137

148
const appRoutes: Routes = [
159
{ path: '', component: PageMainComponent },
16-
{ path: 'sftp', component: PageSftpComponent },
17-
{ path: 'connect', component: PagesConnectComponent },
10+
{
11+
path: 'sftp',
12+
loadComponent: () => import('./pages/sftp/sftp.component').then(m => m.PageSftpComponent)
13+
},
14+
{
15+
path: 'connect',
16+
loadComponent: () =>
17+
import('./pages/connect/connect.component').then(m => m.PagesConnectComponent)
18+
},
1819
{ path: 'undefined', component: PagesBlankComponent },
1920
{ path: 'share/:id', component: PagesShareComponent },
20-
{ path: 'replay/:sid', component: PagesReplayComponent },
21-
{ path: 'admin-connect', component: PageDirectComponent },
22-
{ path: 'monitor/:sid', component: PagesMonitorComponent },
23-
{ path: 'k8s/:token', component: PagesKubernetesComponent },
21+
{
22+
path: 'replay/:sid',
23+
loadComponent: () => import('./pages/replay/replay.component').then(m => m.PagesReplayComponent)
24+
},
25+
{
26+
path: 'admin-connect',
27+
loadComponent: () => import('./pages/direct/direct.component').then(m => m.PageDirectComponent)
28+
},
29+
{
30+
path: 'monitor/:sid',
31+
loadComponent: () =>
32+
import('./pages/monitor/monitor.component').then(m => m.PagesMonitorComponent)
33+
},
34+
{
35+
path: 'k8s/:token',
36+
loadComponent: () =>
37+
import('./pages/kubernetes/kubernetes.component').then(m => m.PagesKubernetesComponent)
38+
}
2439
// { path: '**', component: PagesNotFoundComponent }
2540
];
2641

2742
@NgModule({
2843
imports: [RouterModule.forRoot(appRoutes, { enableTracing: false })],
29-
exports: [RouterModule],
44+
exports: [RouterModule]
3045
})
31-
3246
export class AppRouterModule {}

src/polyfills.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,12 @@
2828
* Needed for: All but Chrome, Firefox and Opera. http://caniuse.com/#feat=web-animation
2929
**/
3030
// import 'web-animations-js'; // Run `npm install --save web-animations-js`.
31+
3132
/***************************************************************************************************
3233
* Zone JS is required by Angular itself.
3334
*/
3435
import 'zone.js'; // Included with Angular CLI.
3536

36-
3737
/***************************************************************************************************
3838
* APPLICATION IMPORTS
3939
*/
@@ -47,5 +47,3 @@ import 'zone.js'; // Included with Angular CLI.
4747
* Need to import at least one locale-data with intl.
4848
*/
4949
// import 'intl/locale-data/jsonp/en';
50-
51-
(window as any).global = window;

src/tsconfig.app.json

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,9 @@
33
"compilerOptions": {
44
"outDir": "../out-tsc/app",
55
"baseUrl": "./",
6-
"module": "ES2015",
6+
"module": "esnext",
77
"target": "ES2022",
88
"types": []
99
},
10-
"exclude": [
11-
"test.ts",
12-
"**/*.spec.ts"
13-
]
10+
"exclude": ["test.ts", "**/*.spec.ts"]
1411
}

tsconfig.json

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,8 @@
33
"compilerOptions": {
44
"baseUrl": "src",
55
"paths": {
6-
"@src/*": [
7-
"*"
8-
],
9-
"@app/*": [
10-
"app/*"
11-
]
6+
"@src/*": ["*"],
7+
"@app/*": ["app/*"]
128
},
139
"allowJs": true,
1410
"outDir": "./dist/out-tsc",
@@ -19,14 +15,9 @@
1915
"experimentalDecorators": true,
2016
"target": "es2020",
2117
"importHelpers": true,
22-
"typeRoots": [
23-
"node_modules/@types"
24-
],
25-
"lib": [
26-
"es2020",
27-
"dom"
28-
],
29-
"module": "es2015",
18+
"typeRoots": ["node_modules/@types"],
19+
"lib": ["es2020", "dom"],
20+
"module": "esnext",
3021
"allowSyntheticDefaultImports": true
3122
}
3223
}

0 commit comments

Comments
 (0)