Skip to content

Commit e090cd5

Browse files
authored
feat(angular): add migration to update the typescript setup for webpack-based server configuration (#33558)
Update the TypeScript setup for webpack-based SSR setups.
1 parent 87c10b0 commit e090cd5

File tree

4 files changed

+646
-0
lines changed

4 files changed

+646
-0
lines changed

packages/angular/migrations.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,15 @@
392392
},
393393
"description": "Update the @angular/cli package version to 21.0.0-rc.5.",
394394
"factory": "./src/migrations/update-22-2-0/update-angular-cli"
395+
},
396+
"update-ssr-webpack-config-22-2-0": {
397+
"cli": "nx",
398+
"version": "22.2.0-beta.0",
399+
"requires": {
400+
"@angular/core": ">=21.0.0"
401+
},
402+
"description": "Updates webpack-based SSR configuration to use preserve module format and bundler module resolution.",
403+
"factory": "./src/migrations/update-22-2-0/update-ssr-webpack-config"
395404
}
396405
},
397406
"packageJsonUpdates": {
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
#### Updates Webpack-Based SSR Configuration
2+
3+
Updates the TypeScript configuration and import syntax for webpack-based server-side rendering (SSR) projects. This migration sets `module: "preserve"` and `moduleResolution: "bundler"` in `tsconfig.server.json` to align with Angular's build requirements, and updates server file imports from namespace imports (`import * as express`) to default imports (`import express`) to work correctly with the new module format.
4+
5+
#### Examples
6+
7+
For webpack-based SSR projects (using `@nx/angular:webpack-server` or `@angular-devkit/build-angular:server`), the migration updates the `tsconfig.server.json` file:
8+
9+
##### Before
10+
11+
```jsonc {7-8}
12+
// apps/my-app/tsconfig.server.json
13+
{
14+
"extends": "./tsconfig.json",
15+
"compilerOptions": {
16+
"outDir": "../../dist/out-tsc",
17+
"target": "es2022",
18+
"module": "commonjs",
19+
"moduleResolution": "node",
20+
"types": ["node"]
21+
},
22+
"files": ["src/main.server.ts", "src/server.ts"]
23+
}
24+
```
25+
26+
##### After
27+
28+
```jsonc {7-8}
29+
// apps/my-app/tsconfig.server.json
30+
{
31+
"extends": "./tsconfig.json",
32+
"compilerOptions": {
33+
"outDir": "../../dist/out-tsc",
34+
"target": "es2022",
35+
"module": "preserve",
36+
"moduleResolution": "bundler",
37+
"types": ["node"]
38+
},
39+
"files": ["src/main.server.ts", "src/server.ts"]
40+
}
41+
```
42+
43+
The migration also updates import statements in the `server.ts` file to use default imports instead of namespace imports:
44+
45+
##### Before
46+
47+
```ts {2-4}
48+
// apps/my-app/src/server.ts
49+
import * as express from 'express';
50+
import * as compression from 'compression';
51+
import * as cors from 'cors';
52+
53+
const app = express();
54+
app.use(compression());
55+
app.use(cors());
56+
```
57+
58+
##### After
59+
60+
```ts {2-4}
61+
// apps/my-app/src/server.ts
62+
import express from 'express';
63+
import compression from 'compression';
64+
import cors from 'cors';
65+
66+
const app = express();
67+
app.use(compression());
68+
app.use(cors());
69+
```
70+
71+
Projects that already have the correct TypeScript configuration or projects without a `tsconfig.server.json` file are not modified by this migration.

0 commit comments

Comments
 (0)