Skip to content

Commit 07999ae

Browse files
committed
feat: update angulare/core,cli
1 parent dd112e7 commit 07999ae

File tree

8 files changed

+2547
-1980
lines changed

8 files changed

+2547
-1980
lines changed

angular.json

Lines changed: 15 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,16 @@
1515
"prefix": "app",
1616
"architect": {
1717
"build": {
18-
"builder": "@angular-devkit/build-angular:browser",
18+
"builder": "@angular-devkit/build-angular:application",
1919
"options": {
20-
"outputPath": "dist/ReservationClient/browser",
21-
"localize": ["zh"],
20+
"outputPath": {
21+
"base": "dist/ReservationClient"
22+
},
23+
"localize": [
24+
"zh"
25+
],
2226
"i18nMissingTranslation": "error",
2327
"index": "src/index.html",
24-
"main": "src/main.ts",
2528
"polyfills": [
2629
"zone.js"
2730
],
@@ -34,7 +37,13 @@
3437
"styles": [
3538
"src/styles.less"
3639
],
37-
"scripts": []
40+
"scripts": [],
41+
"browser": "src/main.ts",
42+
"server": "src/main.server.ts",
43+
"prerender": true,
44+
"ssr": {
45+
"entry": "server.ts"
46+
}
3847
},
3948
"configurations": {
4049
"production": {
@@ -50,8 +59,6 @@
5059
"namedChunks": false,
5160
"aot": true,
5261
"extractLicenses": true,
53-
"vendorChunk": false,
54-
"buildOptimizer": true,
5562
"localize": true,
5663
"budgets": [
5764
{
@@ -60,8 +67,7 @@
6067
"maximumError": "5mb"
6168
}
6269
],
63-
"serviceWorker": true,
64-
"ngswConfigPath": "ngsw-config.json"
70+
"serviceWorker": "ngsw-config.json"
6571
},
6672
"development": {
6773
"optimization": false,
@@ -143,64 +149,6 @@
143149
"devServerTarget": "ReservationClient:serve:production"
144150
}
145151
}
146-
},
147-
"server": {
148-
"builder": "@angular-devkit/build-angular:server",
149-
"options": {
150-
"outputPath": "dist/ReservationClient/server",
151-
"main": "server.ts",
152-
"tsConfig": "tsconfig.server.json"
153-
},
154-
"configurations": {
155-
"production": {
156-
"buildOptimizer": true,
157-
"outputHashing": "media",
158-
"fileReplacements": [
159-
{
160-
"replace": "src/environments/environment.ts",
161-
"with": "src/environments/environment.prod.ts"
162-
}
163-
],
164-
"optimization": true,
165-
"sourceMap": false,
166-
"extractLicenses": true,
167-
"vendorChunk": false
168-
}
169-
},
170-
"defaultConfiguration": "production"
171-
},
172-
"serve-ssr": {
173-
"builder": "@angular-devkit/build-angular:ssr-dev-server",
174-
"configurations": {
175-
"development": {
176-
"browserTarget": "ReservationClient:build:development",
177-
"serverTarget": "ReservationClient:server:development"
178-
},
179-
"production": {
180-
"browserTarget": "ReservationClient:build:production",
181-
"serverTarget": "ReservationClient:server:production"
182-
}
183-
},
184-
"defaultConfiguration": "development"
185-
},
186-
"prerender": {
187-
"builder": "@angular-devkit/build-angular:prerender",
188-
"options": {
189-
"routes": [
190-
"/"
191-
]
192-
},
193-
"configurations": {
194-
"production": {
195-
"browserTarget": "ReservationClient:build:production",
196-
"serverTarget": "ReservationClient:server:production"
197-
},
198-
"development": {
199-
"browserTarget": "ReservationClient:build:development",
200-
"serverTarget": "ReservationClient:server:development"
201-
}
202-
},
203-
"defaultConfiguration": "production"
204152
}
205153
},
206154
"i18n": {

package.json

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,27 +8,24 @@
88
"test": "ng test",
99
"lint": "ng lint",
1010
"e2e": "ng e2e",
11-
"dev:ssr": "ng run ReservationClient:serve-ssr",
12-
"serve:ssr": "node dist/ReservationClient/server/main.js",
13-
"build:ssr": "ng build && ng run ReservationClient:server",
14-
"prerender": "ng run ReservationClient:prerender"
11+
"serve:ssr:ReservationClient": "node dist/ReservationClient/server/server.mjs"
1512
},
1613
"private": true,
1714
"dependencies": {
18-
"@angular/animations": "^17.0.2",
15+
"@angular/animations": "^18.0.3",
1916
"@angular/cdk": "^17.0.0",
20-
"@angular/common": "^17.0.2",
21-
"@angular/compiler": "^17.0.2",
22-
"@angular/core": "^17.0.2",
23-
"@angular/forms": "^17.0.2",
24-
"@angular/localize": "^17.0.2",
17+
"@angular/common": "^18.0.3",
18+
"@angular/compiler": "^18.0.3",
19+
"@angular/core": "^18.0.3",
20+
"@angular/forms": "^18.0.3",
21+
"@angular/localize": "^18.0.3",
2522
"@angular/material": "^17.0.0",
26-
"@angular/platform-browser": "^17.0.2",
27-
"@angular/platform-browser-dynamic": "^17.0.2",
28-
"@angular/platform-server": "^17.0.2",
29-
"@angular/router": "^17.0.2",
30-
"@angular/service-worker": "^17.0.2",
31-
"@angular/ssr": "^17.0.0",
23+
"@angular/platform-browser": "^18.0.3",
24+
"@angular/platform-browser-dynamic": "^18.0.3",
25+
"@angular/platform-server": "^18.0.3",
26+
"@angular/router": "^18.0.3",
27+
"@angular/service-worker": "^18.0.3",
28+
"@angular/ssr": "^18.0.5",
3229
"@sentry/browser": "^5.5.0",
3330
"angular-oauth2-oidc": "^15.0.1",
3431
"express": "^4.18.2",
@@ -37,10 +34,10 @@
3734
"zone.js": "~0.14.2"
3835
},
3936
"devDependencies": {
40-
"@angular-devkit/build-angular": "^17.0.0",
41-
"@angular/cli": "^17.0.0",
42-
"@angular/compiler-cli": "^17.0.2",
43-
"@angular/language-service": "^17.0.2",
37+
"@angular-devkit/build-angular": "^18.0.5",
38+
"@angular/cli": "^18.0.5",
39+
"@angular/compiler-cli": "^18.0.3",
40+
"@angular/language-service": "^18.0.3",
4441
"@types/express": "^4.17.17",
4542
"@types/jasmine": "~3.3.8",
4643
"@types/jasminewd2": "~2.0.3",
@@ -53,6 +50,6 @@
5350
"karma-jasmine-html-reporter": "~2.1.0",
5451
"protractor": "~7.0.0",
5552
"tslint": "~6.1.0",
56-
"typescript": "~5.2.2"
53+
"typescript": "~5.4.5"
5754
}
58-
}
55+
}

server.ts

Lines changed: 13 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,40 @@
1-
import 'zone.js/node';
2-
31
import { APP_BASE_HREF } from '@angular/common';
42
import { CommonEngine } from '@angular/ssr';
5-
import * as express from 'express';
6-
import { existsSync } from 'node:fs';
7-
import { join } from 'node:path';
3+
import express from 'express';
4+
import { fileURLToPath } from 'node:url';
5+
import { dirname, join, resolve } from 'node:path';
86
import AppServerModule from './src/main.server';
97

108
// The Express app is exported so that it can be used by serverless Functions.
119
export function app(): express.Express {
1210
const server = express();
13-
const distFolder = join(process.cwd(), 'dist/ReservationClient/browser');
14-
const indexHtml = existsSync(join(distFolder, 'index.original.html'))
15-
? join(distFolder, 'index.original.html')
16-
: join(distFolder, 'index.html');
11+
const serverDistFolder = dirname(fileURLToPath(import.meta.url));
12+
const browserDistFolder = resolve(serverDistFolder, '../browser');
13+
const indexHtml = join(serverDistFolder, 'index.server.html');
1714

1815
const commonEngine = new CommonEngine();
1916

2017
server.set('view engine', 'html');
21-
server.set('views', distFolder);
18+
server.set('views', browserDistFolder);
2219

2320
// Example Express Rest API endpoints
2421
// server.get('/api/**', (req, res) => { });
2522
// Serve static files from /browser
26-
server.get('*.*', express.static(distFolder, {
27-
maxAge: '1y'
23+
server.get('**', express.static(browserDistFolder, {
24+
maxAge: '1y',
25+
index: 'index.html',
2826
}));
2927

3028
// All regular routes use the Angular engine
31-
server.get('*', (req, res, next) => {
29+
server.get('**', (req, res, next) => {
3230
const { protocol, originalUrl, baseUrl, headers } = req;
3331

3432
commonEngine
3533
.render({
3634
bootstrap: AppServerModule,
3735
documentFilePath: indexHtml,
3836
url: `${protocol}://${headers.host}${originalUrl}`,
39-
publicPath: distFolder,
37+
publicPath: browserDistFolder,
4038
providers: [{ provide: APP_BASE_HREF, useValue: baseUrl }],
4139
})
4240
.then((html) => res.send(html))
@@ -56,14 +54,4 @@ function run(): void {
5654
});
5755
}
5856

59-
// Webpack will replace 'require' with '__webpack_require__'
60-
// '__non_webpack_require__' is a proxy to Node 'require'
61-
// The below code is to ensure that the server is run only when not requiring the bundle.
62-
declare const __non_webpack_require__: NodeRequire;
63-
const mainModule = __non_webpack_require__.main;
64-
const moduleFilename = mainModule && mainModule.filename || '';
65-
if (moduleFilename === __filename || moduleFilename.includes('iisnode')) {
66-
run();
67-
}
68-
69-
export default AppServerModule;
57+
run();

src/app/app.module.ts

Lines changed: 34 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { NgModule, ErrorHandler } from '@angular/core';
33
import { AppRoutingModule } from './app-routing.module';
44
import { AppComponent } from './app.component';
55
import { AppMaterialModule } from './app.material.module';
6-
import { HttpClientModule, HTTP_INTERCEPTORS } from '@angular/common/http';
6+
import { HTTP_INTERCEPTORS, provideHttpClient, withInterceptorsFromDi } from '@angular/common/http';
77
import { ReservationListComponent } from './reservation/reservation-list/reservation-list.component';
88
import { NoticeListComponent } from './notice/notice-list/notice-list.component';
99
import { NoticeDetailComponent } from './notice/notice-detail/notice-detail.component';
@@ -20,43 +20,37 @@ import { LoginComponent } from './account/login/login.component';
2020
import { AuthCallbackComponent } from './account/auth-callback/auth-callback.component';
2121
import { MyReservationComponent } from './account/my-reservation/my-reservation.component';
2222

23-
@NgModule({
24-
declarations: [
25-
AppComponent,
26-
NewReservationComponent,
27-
ReservationListComponent,
28-
NoticeListComponent,
29-
NoticeDetailComponent,
30-
AboutComponent,
31-
SanitizeHtmlPipe,
32-
LoginComponent,
33-
AuthCallbackComponent,
34-
MyReservationComponent,
35-
],
36-
imports: [
37-
BrowserModule,
38-
AppRoutingModule,
39-
AppMaterialModule,
40-
HttpClientModule,
41-
FormsModule,
42-
ReactiveFormsModule,
43-
BrowserAnimationsModule,
44-
OAuthModule.forRoot({
45-
resourceServer: {
46-
allowedUrls: ['https://reservation.weihanli.xyz/api'],
47-
sendAccessToken: true
48-
}
49-
}),
50-
ServiceWorkerModule.register('ngsw-worker.js', { enabled: environment.production }),
51-
],
52-
providers: [
53-
{
54-
provide: HTTP_INTERCEPTORS,
55-
useClass: ResponseInterceptor,
56-
multi: true
57-
},
58-
provideClientHydration(),
59-
],
60-
bootstrap: [AppComponent]
61-
})
23+
@NgModule({ declarations: [
24+
AppComponent,
25+
NewReservationComponent,
26+
ReservationListComponent,
27+
NoticeListComponent,
28+
NoticeDetailComponent,
29+
AboutComponent,
30+
SanitizeHtmlPipe,
31+
LoginComponent,
32+
AuthCallbackComponent,
33+
MyReservationComponent,
34+
],
35+
bootstrap: [AppComponent], imports: [BrowserModule,
36+
AppRoutingModule,
37+
AppMaterialModule,
38+
FormsModule,
39+
ReactiveFormsModule,
40+
BrowserAnimationsModule,
41+
OAuthModule.forRoot({
42+
resourceServer: {
43+
allowedUrls: ['https://reservation.weihanli.xyz/api'],
44+
sendAccessToken: true
45+
}
46+
}),
47+
ServiceWorkerModule.register('ngsw-worker.js', { enabled: environment.production })], providers: [
48+
{
49+
provide: HTTP_INTERCEPTORS,
50+
useClass: ResponseInterceptor,
51+
multi: true
52+
},
53+
provideClientHydration(),
54+
provideHttpClient(withInterceptorsFromDi()),
55+
] })
6256
export class AppModule { }

tsconfig.app.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,14 @@
33
"compilerOptions": {
44
"outDir": "./out-tsc/app",
55
"types": [
6-
"@angular/localize"
6+
"@angular/localize",
7+
"node"
78
]
89
},
910
"files": [
10-
"types/global.d.ts"
11+
"types/global.d.ts",
12+
"src/main.server.ts",
13+
"server.ts"
1114
],
1215
"include": [
1316
"src/**/*.ts"

tsconfig.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
To learn more about this file see: https://angular.io/config/solution-tsconfig.
66
*/
77
{
8+
"compilerOptions": {
9+
"esModuleInterop": true
10+
},
811
"files": [],
912
"references": [
1013
{

tsconfig.server.json

Lines changed: 0 additions & 15 deletions
This file was deleted.

0 commit comments

Comments
 (0)