You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# Getting started with the CLI's esbuild-based build system
1
+
# Getting started with the Angular CLI's new build system
2
+
3
+
In v17 and higher, the new build system provides an improved way to build Angular applications. This new build system includes:
4
+
5
+
- A modern output format using ESM, with dynamic import expressions to support lazy module loading.
6
+
- Faster build-time performance for both initial builds and incremental rebuilds.
7
+
- Newer JavaScript ecosystem tools such as [esbuild](https://esbuild.github.io/) and [Vite](https://vitejs.dev/).
8
+
- Integrated SSR and prerendering capabilites
9
+
10
+
This new build system is stable and fully supported for use with Angular applications.
11
+
You can migrate to the new build system with applications that use the `browser` builder.
12
+
If using a custom builder, please refer to the documentation for that builder on possible migration options.
2
13
3
14
<divclass="alert is-important">
4
15
5
-
The esbuild-based ECMAScript module (ESM) application build system feature is available for [developer preview](/guide/releases#developer-preview).
6
-
It's ready for you to try, but it might change before it is stable and is not yet recommended for production builds.
16
+
The existing Webpack-based build system is still considered stable and fully supported.
17
+
Applications can continue to use the `browser` builder and will not be automatically migrated when updating.
7
18
8
19
</div>
9
20
10
-
In v16 and higher, the new build system provides a way to build Angular applications. This new build system includes:
21
+
## For new applications
11
22
12
-
- A modern output format using ESM, with dynamic import expressions to support lazy module loading.
13
-
- Faster build-time performance for both initial builds and incremental rebuilds.
14
-
- Newer JavaScript ecosystem tools such as [esbuild](https://esbuild.github.io/) and [Vite](https://vitejs.dev/).
23
+
New applications will use this new build system by default via the `application` builder.
24
+
25
+
## For existing applications
15
26
16
-
You can opt-in to use the new builder on a per application basis with minimal configuration updates required.
27
+
For existing projects, you can opt-in to use the new builder on a per-application basis with two different options.
28
+
Both options are considered stable and fully supported by the Angular team.
29
+
The choice of which option to use is a factor of how many changes you will need to make to migrate and what new features you would like to use in the project.
17
30
18
-
## Trying the ESM build system in an Angular CLI application
| `application` | Multiple option changes required. If using SSR, additional targets will need to be updated. | Yes, if using SSR | Yes
34
+
| `browser-esbuild` | builder name only | No* | No
19
35
20
-
A new builder named `browser-esbuild` is available within the `@angular-devkit/build-angular` package that is present in an Angular CLI generated application. The build is a drop-in replacement for the existing `browser` builder that provides the current stable browser application build system.
21
-
You can try out the new build system for applications that use the `browser` builder.
36
+
The `application` builder is generally preferred as it improves server-side rendered (SSR) builds, and makes it easier for client-side rendered projects to adopt SSR in the future.
37
+
However it requires a little more migration effort, particularly for existing SSR applications.
38
+
If the `application` builder is difficult for your project to adopt, `browser-esbuild` can be an easier solution which gives most of the build performance benefits with fewer breaking changes.
22
39
23
-
### Updating the application configuration
40
+
### Using the `browser-esbuild` builder
24
41
25
-
The new build system was implemented to minimize the amount of changes necessary to transition your applications. Currently, the new build system is provided via an alternate builder (`browser-esbuild`). You can update the `build` target for any application target to try out the new build system.
42
+
A builder named `browser-esbuild` is available within the `@angular-devkit/build-angular` package that is present in an Angular CLI generated application. The builder is a drop-in replacement for the existing `browser` builder that provides the preexisting browser application build system.
43
+
44
+
The compatiblity option was implemented to minimize the amount of changes necessary to initially migrate your applications.
45
+
This is provided via an alternate builder (`browser-esbuild`).
46
+
You can update the `build` target for any application target to migrate to the new build system.
26
47
27
48
The following is what you would typically find in `angular.json` for an application:
28
49
@@ -44,19 +65,79 @@ Changing the `builder` field is the only change you will need to make.
44
65
...
45
66
</code-example>
46
67
47
-
### Executing a build
68
+
### Using the `application` builder
69
+
70
+
A builder named `application` is also available within the `@angular-devkit/build-angular` package that is present in an Angular CLI generated application.
71
+
This builder is the default for all new applications created via `ng new`.
48
72
49
-
Once you have updated the application configuration, builds can be performed using the `ng build` as was previously done. For the remaining options that are currently not yet implemented in the developer preview, a warning will be issued for each and the option will be ignored during the build.
73
+
The following is what you would typically find in `angular.json` for an application:
| `ngswConfigPath` | move value to `serviceWorker` and remove option | `serviceWorker` is now either `false` or a configuration path
106
+
107
+
108
+
If the application is not using SSR currently, this should be the final step to allow `ng build` to function.
109
+
After executing `ng build` for the first time, there may be new warnings or errors based on behavioral differences or application usage of Webpack-specific features.
110
+
Many of the warnings will provide suggestions on how to remedy that problem.
111
+
If it appears that a warning is incorrect or the solution is not apparent, please open an issue on [GitHub](https://github.com/angular/angular-cli/issues).
112
+
Also, the later sections of this guide provide additional information on several specific cases as well as current known issues.
113
+
114
+
For applications that are already using SSR, additional manual adjustments to code will be needed to update the SSR server code to support the new integrated SSR capabilities.
115
+
The `application` builder now provides the integrated functionality for all of the following preexisting builders:
116
+
117
+
*`app-shell`
118
+
*`prerender`
119
+
*`server`
120
+
*`ssr-dev-server`
121
+
122
+
The [Angular SSR Guide](/guide/ssr) provides additional information regarding the new setup process for SSR.
123
+
124
+
## Executing a build
125
+
126
+
Once you have updated the application configuration, builds can be performed using the `ng build` as was previously done.
127
+
Depending on the choice of builder migration, some of the command line options may be different.
128
+
If the build command is contained in any `npm` or other scripts, ensure they are reviewed and updated.
129
+
For applications that have migrated to the `application` builder and that use SSR and/or prererending, you also may be able to remove extra `ng run` commands from scripts now that `ng build` has integrated SSR support.
50
130
51
131
<code-examplelanguage="shell">
52
132
53
133
ng build
54
134
55
135
</code-example>
56
136
57
-
###Starting the development server
137
+
## Starting the development server
58
138
59
-
The development server now has the ability to automatically detect the new build system and use it to build the application. To start the development server no changes are necessary to the `dev-server` builder configuration or command line.
139
+
The development server will automatically detect the new build system and use it to build the application.
140
+
To start the development server no changes are necessary to the `dev-server` builder configuration or command line.
60
141
61
142
<code-examplelanguage="shell">
62
143
@@ -68,22 +149,21 @@ You can continue to use the [command line options](/cli/serve) you have used in
68
149
69
150
<divclass="alert is-important">
70
151
71
-
The developer preview currently does not provide HMR support and the HMR related options will be ignored if used. Angular focused HMR capabilities are currently planned and will be introduced in a future version.
152
+
JavaScript-based Hot Module Replacement (HMR) is currently not supported.
153
+
However, global stylesheet (`styles` build option) HMR is available and enabled by default.
154
+
Angular focused HMR capabilities are currently planned and will be introduced in a future version.
72
155
73
156
</div>
74
157
75
-
###Unimplemented options and behavior
158
+
## Unimplemented options and behavior
76
159
77
160
Several build options are not yet implemented but will be added in the future as the build system moves towards a stable status. If your application uses these options, you can still try out the build system without removing them. Warnings will be issued for any unimplemented options but they will otherwise be ignored. However, if your application relies on any of these options to function, you may want to wait to try.
-[WASM imports](https://github.com/angular/angular-cli/issues/25102) -- WASM can still be loaded manually via [standard web APIs](https://developer.mozilla.org/en-US/docs/WebAssembly/Loading_and_running).
83
163
84
164
Building libraries with the new build system via `ng-packagr` is also not yet possible but library build support will be available in a future release.
85
165
86
-
###ESM default imports vs. namespace imports
166
+
## ESM default imports vs. namespace imports
87
167
88
168
TypeScript by default allows default exports to be imported as namespace imports and then used in call expressions. This is unfortunately a divergence from the ECMAScript specification. The underlying bundler (`esbuild`) within the new build system expects ESM code that conforms to the specification. The build system will now generate a warning if your application uses an incorrect type of import of a package. However, to allow TypeScript to accept the correct usage, a TypeScript option must be enabled within the application's `tsconfig` file. When enabled, the [`esModuleInterop`](https://www.typescriptlang.org/tsconfig#esModuleInterop) option provides better alignment with the ECMAScript specification and is also recommended by the TypeScript team. Once enabled, you can update package imports where applicable to an ECMAScript conformant form.
89
169
@@ -129,28 +209,11 @@ The usage of Vite in the Angular CLI is currently only within a _development ser
129
209
130
210
There are currently several known issues that you may encounter when trying the new build system. This list will be updated to stay current. If any of these issues are currently blocking you from trying out the new build system, please check back in the future as it may have been solved.
131
211
132
-
### Runtime-evaluated dynamic import expressions
133
-
134
-
Dynamic import expressions that do not contain static values will be kept in their original form and not processed at build time. This is a limitation of the underlying bundler but is [planned](https://github.com/evanw/esbuild/pull/2508) to be implemented in the future. In many cases, application code can be made to work by changing the import expressions into static strings with some form of conditional statement such as an `if` or `switch` for the known potential files.
135
-
136
-
Unsupported:
137
-
138
-
```ts
139
-
returnawaitimport(`/abc/${name}.json`);
140
-
```
141
-
142
-
Supported:
212
+
### Type-checking of Web Worker code and processing of nested Web Workers
143
213
144
-
```ts
145
-
switch (name) {
146
-
case'x':
147
-
returnawaitimport('/abc/x.json');
148
-
case'y':
149
-
returnawaitimport('/abc/y.json');
150
-
case'z':
151
-
returnawaitimport('/abc/z.json');
152
-
}
153
-
```
214
+
Web Workers can be used within application code using the same syntax (`new Worker(new URL('<workerfile>', import.meta.url))`) that is supported with the `browser` builder.
215
+
However, the code within the Worker will not currently be type-checked by the TypeScript compiler. TypeScript code is supported just not type-checked.
216
+
Additionally, any nested workers will not be processed by the build system. A nested worker is a Worker instantiation within another Worker file.
154
217
155
218
### Order-dependent side-effectful imports in lazy modules
156
219
@@ -164,14 +227,6 @@ Avoiding the use of modules with non-local side effects (outside of polyfills) i
164
227
165
228
</div>
166
229
167
-
### Long build times when using Sass combined with pnpm or yarn PnP
168
-
169
-
Applications may have increased build times due to the need to workaround Sass resolution incompatibilities when using either the pnpm or Yarn PnP package managers.
170
-
Sass files with `@import` or `@use` directives referencing a package when using either of these package managers can trigger the performance problem.
171
-
172
-
An alternative workaround that alleviates the build time increases is in development and will be available before the build system moves to stable status.
173
-
Both the Yarn package manager in node modules mode and the `npm` package manager are not affected by this problem.
174
-
175
230
## Bug reports
176
231
177
232
Report issues and feature requests on [GitHub](https://github.com/angular/angular-cli/issues).
0 commit comments