|
| 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