16 Commits

Author SHA1 Message Date
Charles Lyding
34908a3fcb fix(@angular/build): lazy load Node.js inspector for dev server
The Node.js inspector will now only be imported if SSR is enabled and
the `inspect` option is used. This prevents potential failures when a
custom Node.js binary build is used that has not enabled inspector usage.
While this is not common, loading the inspector on demand is a minimal
change that also avoids loading code that will not be used for the majority
of development server usage.
2024-08-07 11:44:35 -04:00
Charles Lyding
421b6e75b4 refactor(@angular/build): provide structured application builder result types
The application builder now provides structured output types to its internal
consumers. The architect builders themselves and the programmatic API is
not changed. These output result types allow for the development server to
receive additional information regarding the build and update the active
browser appropriately. This functionality is not yet implemented but the
additional result types provide the base infrastructure to enable future
features. The result types also allow for reduced complexity inside other
builders such as i18n extraction and the browser compatibility builder.
The usage is not yet fully optimized and will be refined in future changes.
2024-07-19 10:08:38 -04:00
Karel Frederix
394f9ce35f fix(@angular/build): remove Vite "/@id/" prefix for explicit external dependencies
Adds a Vite plugin which will remove the /@id/ prefix (which gets inserted by Vite during import-analysis) for explicit externalDependencies.
2024-07-15 09:29:04 -07:00
Alan Agius
b5af8b59be refactor(@angular/build): move Vite middlewares into separate files
As the number of middlewares has increased over time, this commit enhances code health by relocating them into individual files.
2024-06-28 17:23:46 +02:00
Charles Lyding
741cf7fe1e test: enable @typescript-eslint/await-thenable lint rule
The `@typescript-eslint/await-thenable` rule is now enabled and all failures
have been addressed within the code.
2024-06-25 16:57:03 -04:00
Alan Agius
3e359da8df fix(@angular/build): address rxjs undefined issues during SSR prebundling
Replacing the paths to ESM in Vite can cause prebundling to fail in some cases, resulting in errors similar to the following:

```
12:55:12 PM [vite] Error when evaluating SSR module /chunk-CHB4JJIP.mjs:
|- TypeError: Cannot read properties of undefined (reading 'Subject')
    at eval (//src/app/shared/snackbar/snackbar.service.ts:2:25)
    at async instantiateModule (file:////node_modules/vite/dist/node/chunks/dep-BcXSligG.js:53408:5)

12:55:12 PM [vite] Error when evaluating SSR module /chunk-GQZ5BKXC.mjs:
|- TypeError: Cannot read properties of undefined (reading 'Subject')
    at eval (//src/app/shared/snackbar/snackbar.service.ts:2:25)
    at async instantiateModule (file:////node_modules/vite/dist/node/chunks/dep-BcXSligG.js:53408:5)
```

Closes: #27907
2024-06-24 16:14:08 +02:00
Alan Agius
2324d5a2ec fix(@angular/build): automatically resolve .mjs files when using Vite
Previously, ESM file resolution without extensions failed when using Vite, causing issues in module loading. This commit addresses the problem by automatically resolving `.mjs` files, aligning the behavior with the application builder and ensuring consistent module resolution across different build tools.

**NB**:  This is a workaround as valid ESM imports should always have an extension.

Closes #27841
2024-06-13 22:00:13 +02:00
Ash Ramirez
434a3740f0 refactor(@angular/cli): update aio links -> adev links
Updates for all angular.io links to the new angular.dev domain. Additionally, adjustment to new resources where the equivalent does not exist on the new site (e.g. Tour of Heroes tutorial)
2024-06-06 11:12:06 +02:00
Alan Agius
687a6c7eca feat(@angular/build): add --inspect option to the dev-server
This commit introduces an `--inspect` option to the dev-server, enabling debugging of server-side code when using SSR or SSG. This option is equivalent to `node --inspect=[[host:]port]`.

Usage examples:
```
$ ng serve --inspect
$ ng serve --inspect 9999
$ ng serve --inspect localhost:9999
```

Closes: #27773
2024-06-05 17:12:58 +02:00
Alan Agius
dd94a831b4 perf(@angular/build): enable dependency prebundling for server dependencies
With this commit, we introduce Vite dependencies prebundling for server bundles.

**Before:**
```
ng s
Browser bundles
Initial chunk files     | Names               |  Raw size
polyfills.js            | polyfills           |  90.87 kB
main.js                 | main                |  22.71 kB
styles.css              | styles              |  95 bytes

                        | Initial total       | 113.67 kB

Server bundles
Initial chunk files     | Names               |  Raw size
chunk-4EGJGG5L.mjs      | -                   |   1.80 MB
polyfills.server.mjs    | polyfills.server    | 573.58 kB
main.server.mjs         | main.server         | 224.03 kB
chunk-QDHZVCWX.mjs      | -                   |   2.57 kB
render-utils.server.mjs | render-utils.server | 423 bytes

Lazy chunk files        | Names               |  Raw size
chunk-XD2MYPRT.mjs      | xhr2                |  40.04 kB

Application bundle generation complete. [5.199 seconds]
```

**Now:**
```
ng s
Browser bundles
Initial chunk files     | Names               |  Raw size
polyfills.js            | polyfills           |  90.87 kB
main.js                 | main                |  22.71 kB
styles.css              | styles              |  95 bytes

                        | Initial total       | 113.67 kB

Server bundles
Initial chunk files     | Names               |  Raw size
polyfills.server.mjs    | polyfills.server    | 573.58 kB
main.server.mjs         | main.server         |  23.16 kB
render-utils.server.mjs | render-utils.server | 472 bytes

Application bundle generation complete. [2.880 seconds]
```
2024-05-30 21:41:49 +02:00
Alan Agius
dd06768f06 fix(@angular/build): handle esbuild-browser polyfills option as string during ng serve
With `esbuild-browser` the `polyfills` option can be a string which was not handled properly.

Closes #27693
2024-05-23 09:23:47 -04:00
Alan Agius
0a69322141 refactor: replace vite server.ws.send usages
The above mentioned API is deprecated.
2024-05-21 15:59:40 +02:00
Charles Lyding
8e86184e59 fix(@angular/build): add console note about development server raw file size
An informational note will now be shown upon development server startup
to indicate that the raw file sizes shown in the console do not reflect
any of the per-request transformations that may occur within the Vite-based
development server. The raw file size and the size shown within the browser
may differ as a result of these development workflow based transformations.
2024-05-16 16:15:31 -07:00
Charles Lyding
bc47fa1585 perf(@angular/build): improve rebuild time for file loader usage with prebundling
Rebuilds can now use the optimized external package execute path when using
the `application` builder's `loader` option if only `file` type loaders are
used. The Vite-based development server will now process any `file` type
loader usage for third-party file references which removes the need for the
build itself to handle the loader processing. This change only optimizes
the case where only the `file` loader type is used. If any other loader types
are present, the optimized execution path will not be used. Future further
improvements may allow for all cases to use the optimized rebuild execution
path.
2024-05-15 07:14:25 -04:00
Alan Agius
33cd47c85e fix(@angular/build): properly configure headers for media resources and HTML page
Headers were not configured correctly.

Closes #27464
2024-04-23 18:29:09 +02:00
Charles Lyding
4ffe07aa24 feat(@angular-devkit/build-angular): move Vite-based dev-server for application builder to new build system package
With the `application` builder already within the new `@angular/build` package,
the Vite-based `dev-server` builder is now also contained within this package.
Only the Vite-based aspects of the `dev-server` have been moved and only the
support for the `application` builder. The compatibility builder `browser-esbuild`
is not supported with `@angular/build:dev-server`. The existing `dev-server` builder
found within `@angular-devkit/build-angular` should continue to be used for both the
Webpack-based `browser` builder and the esbuild-based compatibility `browser-esbuild`
builder. To maintain backwards compatibility, the existing `@angular-devkit/build-angular:dev-server`
builder continues to support builders it has previously.

No change to existing applications is required.
2024-04-23 07:27:26 -04:00