383 Commits

Author SHA1 Message Date
Alan Agius
071c8d10ce fix(@angular-devkit/build-angular): don't parse new Worker syntax when webWorkerTsConfig is not defined in karma builder
This is to retain version 11 behaviour.

Closes #21108
2021-06-11 09:42:25 -04:00
Alan Agius
cc4afa2de6 refactor(@angular-devkit/build-angular): ignore postcss-loader warning
Users should not install `postcss` in their workspace as this is a dependency of `@angular-devkit/build-angular`.
2021-06-11 09:24:48 -04:00
Alan Agius
dc5a58528a fix(@angular-devkit/build-angular): styles CSS files not available in unit tests
With this change we force styles to be extracted in css files during unit tests.

Closes #21054
2021-06-09 08:00:58 +02:00
Alan Agius
c43ace7383 fix(@angular-devkit/build-angular): add web-workers in lazy chunks in stats output
Web-workers are not marked as `initial` since their initialization can be guarded.

Closes #21059
2021-06-07 19:29:58 +02:00
Alan Agius
2d0d82ba5b fix(@angular-devkit/build-angular): correctly mark async chunks as non initial in dev-server 2021-06-07 17:09:49 +02:00
Alan Agius
699802d488 perf(@angular-devkit/build-angular): reduce memory usage by cleaning output directory before emitting
Unless `deleteOutputPath` is false, we should clean, this helps reduce assets in tests.
2021-06-07 17:09:27 +02:00
Charles Lyding
5bdd1cbbb7 refactor(@angular-devkit/build-angular): enable babel build optimizer passes for ES2015+ targets
The new babel-based build optimizer passes are now enabled when targetting ES2015 and higher. ES5 targets will currently continue to use the previous build optimizer. ES5 support will require additional refactoring of the downlevelling process as the new build optimizer passes are designed for ES2015 code.
2021-06-04 21:10:06 +02:00
Alan Agius
bd82967523 fix(@angular-devkit/build-angular): show progress during re-builds
With the recent changes in https://github.com/angular/angular-cli/pull/20960 we moved the spinner to be started outside of the progress callback, this causes a side-effect that after `succeed` is called the spinner will stop reporting progress unless it is started again.
2021-06-04 17:55:41 +02:00
Charles Lyding
1dd5c28f8d fix(@angular-devkit/build-angular): dispose Sass worker resources on Webpack shutdown
Sass Worker instances and resource requests are now cleaned up when the Webpack compiler is shutdown. This removes the need to unreference the workers upon creation.

Fixes #20985
2021-06-04 08:35:02 +02:00
Charles Lyding
11a414e468 fix(@angular-devkit/build-angular): ensure all Webpack Stats assets are present on rebuilds
Webpack will only provide emitted assets in the returned Stats each rebuild unless the `cachedAssets` option is enabled. This is currently needed for the bundle budget calculations.

Fixes #21038
2021-06-03 22:11:33 +02:00
Alan Agius
3a287beab3 refactor: remove left over webpack version 4 code 2021-06-03 15:12:23 +02:00
Alan Agius
023d0937c4 perf(@angular-devkit/build-webpack): include only required stats in webpackStats
Until we depend on `webpackStats` in the browser builder we should only included the required stats.

The below are the needed stats;
```
    all: false,
    colors: true,
    hash: true,
    timings: true,
    chunks: true,
    builtAt: true,
    warnings: true,
    errors: true,
    assets: true,
    ids: true,
    entrypoints: true,
```
2021-06-02 18:25:58 +02:00
Alan Agius
f9acdc75ca fix(@angular-devkit/build-angular): provided earlier build feedback in console
With this change we provide earlier feedback in the console during a build. The setup phase can take some times if the project has a large set of dependencies.

We also move several warnings in the dev-server to an earlier phase so that we don't clutter the progress indicator.

Closes #20957
2021-05-31 12:48:00 +01:00
Alan Agius
77f81dc7f7 fix(@angular-devkit/build-angular): do not resolve web-workers in server builds
Web-workers are not supported on the server and therefore we should not try include them in server builds.

Closes #20877
2021-05-31 12:46:50 +01:00
Charles Lyding
459aa2bc6a refactor(@angular-devkit/build-angular): use new inlineStyleFileExtension option for inline component styles
The new `ngtools/webpack` option leverages the inline resource matching syntax combined with a custom loader instead of data URIs. This provides better resource path in loaders that do not yet fully support scheme-based resource requests.
2021-05-26 10:51:33 -04:00
Alan Agius
861a69567c fix(@angular-devkit/build-angular): resolve absolute outputPath properly
Closes #20935
2021-05-26 10:19:16 -04:00
JoostK
640a749515 perf(@angular-devkit/build-angular): load postcss-preset-env configuration once
Loading the postcss-preset-env plugin includes building a mapping of unsupported
browsers by feature, which is somewhat expensive. In large compilations, this mapping
would be recomputed for each postcss-loader instance, as the plugin was recreated
for each loader invocation. By extracting the plugin instance outside of the dynamic
plugin computation, this overhead is avoided.
2021-05-24 16:26:13 -04:00
Alan Agius
5855374eb5 fix(@ngtools/webpack): re-emit component stylesheet assets
With this change we re-emit assets referenced in component stylesheets which where uneffected by the change that re-triggered a re-compilation.

Since we cache the the result of processed component CSS, during a re-compilation `postcss-cli-resources` plugin will not run which causes assets to be to emit. With this change we now cache the asset and re-emit them on every change.

Closes #20882
2021-05-21 20:04:32 -04:00
Alan Agius
1ab2ef9a3f perf(@angular-devkit/build-angular): disable CSS optimization parallelism for components styles
Since we rely on child compilations to compile components CSS, using the `parallel` option will cause a significant overhead because each compilation will need to spawn a worker, in this mode the worker limit is not be honored because `css-minimizer-webpack-plugin` spawn and calulators workers during the optimization phase of a compilation and not globally per instance hence causes OOM because a large number of workers to be spawned simultaneously.

Closes #20883
2021-05-21 13:13:05 -04:00
Bjarki
c146e9c086 feat(@angular-devkit/build-angular): enable webpack Trusted Types support
As reported in #20113, webpack triggers a Trusted Types violation when
lazy-loading is used. To mitigate that, enable webpack's Trusted Types
module (introduced in webpack/webpack#9856) using 'angular#bundler' as
the policy name.
2021-05-21 13:10:52 -04:00
Alan Agius
bea90a6130 fix(@angular-devkit/build-angular): don't add .hot-update.js script tags
Closes #20855
2021-05-21 13:07:42 -04:00
Alan Agius
f5f41ea929 perf(@angular-devkit/build-angular): clean no-longer used assets during builds
This reduce memory consumption during re-builds.

```
runtime.ba93f81591909b93394f.hot-update.js.map will be removed
styles.ba93f81591909b93394f.hot-update.js.map will be removed
runtime.ba93f81591909b93394f.hot-update.json will be removed
runtime.ba93f81591909b93394f.hot-update.js will be removed
styles.ba93f81591909b93394f.hot-update.js will be removed
```

See https://github.com/webpack/webpack/issues/12947#issuecomment-812108140 and https://github.com/webpack/webpack/issues/13127
2021-05-18 18:55:18 +02:00
Ryan Lester
d34dc8853d fix(@angular-devkit/build-angular): correctly resolve babel runtime helpers
Closes #20800
2021-05-18 07:08:36 +02:00
Alan Agius
ae07d36024 build: update terser-webpack-plugin to version 5 2021-05-17 19:28:51 +02:00
Alan Agius
2643fb11a9 fix(@angular-devkit/build-angular): non injected styles should not count as initial
Closes #20781
2021-05-14 13:11:11 +02:00
Alan Agius
4367c3a562 fix(@angular-devkit/build-angular): add NG_BUILD_MAX_WORKERS settimgs to control maximum number of workers 2021-05-14 08:29:35 +02:00
Alan Agius
0ebf7569f6 perf(@angular-devkit/build-angular): use CSS optimization plugin that leverages workers
With this change we use `css-minimizer-webpack-plugin` which leverages workers and also webpack cache.
2021-05-14 08:29:35 +02:00
Alan Agius
7df9d19297 fix(@angular-devkit/build-angular): add experimental web-assembly
Closes #20762
2021-05-13 19:36:41 +02:00
Alan Agius
d9566bfac8 perf(@angular-devkit/build-angular): reduce JSON stats
With this change we reduce the size of the JSON stats object, the main benefit that this change brings is that unspecified stats now default to `false`, due to the `all: false` configuration in e992c9a70b/packages/angular_devkit/build_angular/src/webpack/configs/stats.ts (L12)
2021-05-13 19:36:26 +02:00
Alan Agius
80a08b5e53 test: fix formatting in src/webpack/configs/styles.ts 2021-05-13 17:10:28 +02:00
Charles Lyding
cc7f75f25b perf(@angular-devkit/build-angular): execute dart-sass in a worker
The dart-sass Sass implementation will now be executed in a separate worker thread. The wrapper worker implementation provides an interface that can be directly used by Webpack's `sass-loader`.
The worker implementation allows dart-sass to be executed in its synchronous mode which can be up to two times faster than its asynchronous mode. The worker thread also allows Webpack to continue other bundling tasks while the Sass stylesheets are being processed.
2021-05-13 12:30:42 +02:00
Alan Agius
5315791c95 build: fix typings to works with webpack 5.37.0 2021-05-13 06:52:37 +02:00
Alan Agius
678773ffd4 fix(@angular-devkit/build-angular): disable CSS declaration sorting optimizations
CSS declaration orders matters in some cases. This optimization is currently causing broken CSS output.

Closes #20693
2021-05-05 10:17:49 -04:00
Alan Agius
e992c9a70b build: update files to be fix eslint header/header failures 2021-05-04 09:59:40 -04:00
Alan Agius
50078ac7b2 refactor(@angular-devkit/build-angular): remove redundant any casting 2021-05-03 11:39:05 -04:00
Charles Lyding
c1512e4274 build: update files to be eslint compliant
All TypeScript files have been updated to pass the new eslint-based linting checks. eslint compatible disabling comments have also been added in place of the previous tslint comments.
2021-05-03 07:31:02 -04:00
Charles Lyding
37a06a7c37 build: format all files
All files are now formatted using the ng-dev tools via prettier.
2021-04-28 16:05:49 -07:00
Joey Perrott
003854257c build: migrate all file header to use Google LLC rather than Google Inc 2021-04-27 08:35:22 +02:00
Alan Agius
2d5987102a refactor(@angular-devkit/build-angular): remove no longer needed casting 2021-04-25 11:50:09 +02:00
Alan Agius
b55fc08aa4 fix(@angular-devkit/build-angular): output webpack-dev-server and webpack-dev-middleware errors
With this change we configure `webpack-dev-middleware` and `webpack-dev-server` to print errors to the console, which previously were not displayed. This is because both of these libraries log/emit errors using the logger and the compilation API.

Certain errors such as the one below, were being swallowed during `ng serve`.
```
An unhandled exception occurred: Prevent writing to file that only differs in casing or query string from already written file.
This will lead to a race-condition and corrupted files on case-insensitive file systems.
/home/circleci/ng/aio/dist/generated/docs/api/router/Routes.json
/home/circleci/ng/aio/dist/generated/docs/api/router/ROUTES.json
```
2021-04-23 14:33:55 +02:00
Alan Agius
b2e1d90c63 perf(@angular-devkit/build-angular): improve incremental time during Karma tests
With this change we now use Webpack memory cache when running Karma in watch mode.
2021-04-22 15:40:50 +02:00
Alan Agius
eed56ab839 fix(@angular-devkit/build-angular): avoid triggering file change after file build
When using the `ContextReplacementPlugin` https://github.com/angular/angular-cli/blob/master/packages/angular_devkit/build_angular/src/webpack/configs/common.ts#L496 the new resource path will be watched by Webpack file watcher. This causes a redundant file remove event after the first build, which causes another partial rebuild right way.

Note: changing the call to ` new ContextReplacementPlugin(/\@angular(\\|\/)core(\\|\/)/);` doesn't address the problem.
2021-04-21 12:41:56 -07:00
Charles Lyding
2ac73c75e7 fix(@angular-devkit/build-angular): set Tailwind CSS mode when using Tailwind
Tailwind now suppports an environment variable named `TAILWIND_MODE` with possible values of `build` and `watch`. If the variable has not been set, the tooling will now set the variable based on the builder's `watch` option.
2021-04-21 12:39:39 -07:00
Alan Agius
82ca7d0852 fix(@angular-devkit/build-angular): show warning when using stylus
Stylus is not actively maintained and only 0.3% of the Angular CLI users use it.
2021-04-21 12:39:18 -07:00
Charles Lyding
85ce5ec3b0 fix(@angular-devkit/build-angular): always inject live reload client when using live reload
The current stable version of `webpack-dev-server` does not fully handle Webpack 5's configuration options. In this case, the `target` option can now be an array. However, the array form is ignored by the dev server which can cause the live reload client code to not be included in the output bundles. To remedy this, the `injectClient` option is used when live reload is enabled which forces the client code to be included regardless of the `target` option.
2021-04-21 12:34:56 -07:00
Charles Lyding
ef6996aeff perf(@angular-devkit/build-angular): use Webpack's GC memory caching in watch mode
The GC caching mode will remove any unused cache entries after each rebuild. This prevents old modules from being retained indefinitely during long-lived development sessions.
2021-04-21 12:34:10 -07:00
Charles Lyding
e107055b6f fix(@angular-devkit/build-angular): disable Webpack 5 automatic public path support
The Webpack 5 automatic public path support can cause an incorrect public path to be used to load assets and lazy loaded routes. The current logic relies on the last script element found at runtime in the application's index HTML which may not be related to the application scripts. Now if a `deployUrl` is not specified, the Webpack `publicPath` option is defaulted to an empty string which provides equivalent behavior to Webpack 4.
2021-04-20 09:29:49 -05:00
Alan Agius
7d56d480c1 fix(@angular-devkit/build-angular): recover from CSS optimization errors 2021-04-20 09:29:12 -05:00
Alan Agius
04f5dfe5e2 fix(@angular-devkit/build-angular): use new Webpack watch API in karma webpack plugin
In Webpack 5, the Webpack callback must be used when Webpack is running in watch mode.

Related warning
```
.(node:6565) [DEP_WEBPACK_WATCH_WITHOUT_CALLBACK] DeprecationWarning: A 'callback' argument need to be provided to the 'webpack(options, callback)' function when the 'watch' option is set. There is no way to handle the 'watch' option without a callback.
```
2021-04-20 09:27:05 -05:00
Alan Agius
cb9e51f687 refactor(@angular-devkit/build-angular): remove custom Webpack Stats types
Webpack 5 contains improved types that we can leverage.
2021-04-20 09:27:05 -05:00