292 Commits

Author SHA1 Message Date
Alan Agius
22cd9edfaf feat(@angular-devkit/build-angular): favor es2020 main fields
APF version 13 will include es2020, with this change we favor es2020 entrypoints.
2021-10-01 14:08:14 -05:00
Alan Agius
4e0743c8ad perf(@angular-devkit/build-angular): change webpack hashing function to xxhash64
`xxhash64` uses a faster WASM based hash mechanism.
2021-09-29 11:33:56 -04:00
Alan Agius
ff58f775d3 refactor(@angular-devkit/build-angular): pass SSL cert and key path to dev-server
Since version 4.2.0 webpack-dev-server supports read the mentioned files.

See:
9bb6f78948/CHANGELOG.md (420-2021-09-09)
2021-09-27 16:34:22 -04:00
Charles Lyding
fb1ad7c5b3 feat(@angular-devkit/build-angular): support ESM proxy configuration files for the dev server
The `proxyConfig` option now supports loading ESM configuration files in addition to JSON and CommonJS files. ESM files (such as those ending with `.mjs`) must provide a default export with the configuration object.
For example, a `proxy.config.mjs` containing the follow is now possible:
```
export default { "/api/*": { "target": "http://127.0.0.1:5001" } };
```

Closes #21623
2021-09-24 08:20:40 -04:00
Charles Lyding
77561e796a refactor(@angular-devkit/build-angular): support ESM @angular/compiler-cli linker usage
This is a followup PR for #21771 that addresses partial compilation linker usage.
With the Angular CLI currently being a CommonJS package, this change uses a dynamic import to load `@angular/compiler-cli/linker[/babel]` which may be ESM. CommonJS code can load ESM code via a dynamic import. Unfortunately, TypeScript will currently, unconditionally downlevel dynamic import into a require call. require calls cannot load ESM code and will result in a runtime error. To workaround this, a Function constructor is used to prevent TypeScript from changing the dynamic import. Once TypeScript provides support for keeping the dynamic import this workaround can be dropped and replaced with a standard dynamic import.
2021-09-23 06:52:06 -04:00
Charles Lyding
0d76bf04bc fix(@angular-devkit/build-angular): support WASM-based esbuild optimizer fallback
In the event that the Angular CLI is executed on a platform that does not yet have native support for esbuild, the WASM-based variant of esbuild will now be used. If the first attempt to optimize a file fails to execute the native variant of esbuild, future executions will instead use the WASM-based variant instead which will execute regardless of the native platform. The WASM-based variant, unfortunately, can be significantly slower than the native version (some cases can be several times slower). For install time concerns regarding the esbuild post-install step, esbuild is now listed as an optional dependency which will allow the post-install step to fail but allow the full npm install to pass. This install scenario should only occur in the event that the esbuild native binary cannot be installed or is otherwise unavailable.
2021-09-22 16:09:57 +02:00
Charles Lyding
3e6324f7c7 refactor(@angular-devkit/build-angular): support an ESM-only @angular/compiler-cli package
This uses a dynamic import to load `@angular/compiler-cli` which may be ESM. CommonJS code can load ESM code via a dynamic import. Unfortunately, TypeScript will currently, unconditionally downlevel dynamic import into a require call. require calls cannot load ESM code and will result in a runtime error. To workaround this, a Function constructor is used to prevent TypeScript from changing the dynamic import. Once TypeScript provides support for keeping the dynamic import this workaround can be dropped and replaced with a standard dynamic import.
2021-09-20 10:31:59 +02:00
Charles Lyding
19eb5cb425 refactor(@angular-devkit/build-angular): use type imports for @angular/compiler-cli peer dependency
The `@angular/compiler-cli` is used as a peer dependency and has the potential to not be present. As a result static imports should only be used for types and value imports should be dynamic so that they can be guarded in the event of package absence. There are still several instances of static imports for values but these will be corrected in follow-ups.
2021-09-20 10:31:59 +02:00
Charles Lyding
590c156642 fix(@angular-devkit/build-angular): add web-streams-polyfill to downlevel exclusion list
Polyfill related packages should not be downlevelled due to the nature of their code which may need to perform feature testing or leverage native capabilities to extract browser support information necessary to properly polyfill a given browser. In the case of `web-streams-polyfill`, it leverages the `%AsyncIteratorPrototype%`, when available, to fully polyfill its stream implementations.  To access `%AsyncIteratorPrototype%`, a native async generator is needed and therefore the code present in the package cannot have this case of a native async generator downlevelled. `core-js` is also excluded for similar (and additional reasons).
2021-09-14 09:03:28 +01:00
Charles Lyding
decb1d14b0 fix(@angular-devkit/build-angular): improve Safari browserslist to esbuild target conversion
The browser targets provided by `browserslist` have several differences than what `esbuild` expects for the Safari browsers. The first is that the iOS Safari is named `ios_saf` within browserslist and `ios` by esbuild. The former is now converted to the later when generating the target list for esbuild.  The second difference is that `browserslist` supports a `TP` (Technology Preview) version for Safari but esbuild expects a numeric value for all versions. Since a TP version of Safari is assumed to be the latest unreleased version and as a result supports all currently known features, a high version number (999) is used as a replacement when generating the target list for esbuild.
2021-09-07 17:52:43 +02:00
Alan Agius
32dbf659ac feat(@angular-devkit/build-angular): update webpack-dev-server to version 4
BREAKING CHANGE:

The dev-server now uses WebSockets to communicate changes to the browser during HMR and live-reloaded. If during your development you are using a proxy you will need to enable proxying of WebSockets.
2021-08-27 15:40:10 +02:00
Alan Agius
9a46ba562a build: update dependency webpack-subresource-integrity to v5 2021-08-26 07:30:34 +02:00
Charles Lyding
51f89d633f test: enable no-useless-escape lint rule
The `no-useless-escape` eslint rule has now been enabled which removes unneeded characters and complexity from string literals and regular expressions. All files that were in violation of this rule have also been corrected.
2021-08-24 10:51:14 +01:00
Alan Agius
961218aae7 refactor(@angular-devkit/build-angular): remove differential loading stats generation
This is no longer needed size differential loading was removed.
2021-08-23 11:05:53 +01:00
Alan Agius
aba54ae783 fix(@angular-devkit/build-angular): provide supported browsers to esbuild
With this change we provide the list of supported browsers to Esbuild during CSS optimizations, so it can perform optimizations based on the browser support needed.

Closes #21594
2021-08-18 10:14:39 -04:00
Simon Primetzhofer
9eb599da2b fix(@angular-devkit/build-angular): handle undefined entrypoints when marking async chunks
When using custom builders, it is possible to remove entries from the webpack-configuration
manually. This may eventually lead to undefined entryPoints in async-chunks.ts and aborts
the compilation.
2021-08-13 16:15:12 -04:00
Charles Lyding
8e82263c5e perf(@angular-devkit/build-angular): use esbuild/terser combination to optimize global scripts
`esbuild` and `terser` are now used to optimize global scripts in addition to the previous performance enhancement of optimizing application bundles. This change removes the need for the `terser-webpack-plugin` as a direct dependency and provides further production build time improvements for applications which use global scripts (`scripts` option in the `angular.json` file).
Since `esbuild` does not support optimizing a script with ES2015+ syntax when targetting ES5, the JavaScript optimizer will fallback to only using terser in the event that such a situation occurs. This will only happen if ES5 is the output target for an application and a global script contains ES2015+ syntax. In that case, the global script is technically already invalid for the target environment and may fail at runtime but this is and has been considered a configuration issue. Global scripts must be compatible with the target environment/browsers.
2021-08-11 09:15:49 +02:00
Charles Lyding
1341ad6406 refactor(@angular-devkit/build-angular): remove unused getEsVersionForFileName helper
The `getEsVersionForFileName` helper function was previously used for recently removed differential loading support but is now unused and can also be removed.
2021-08-10 21:40:57 +02:00
Charles Lyding
7b189789d8 refactor(@angular-devkit/build-angular): remove core path usage from normalizeExtraEntryPoints helper
The Node.js `path` builtin module is already imported and provides the necessary functionality to extract the base file name needed within this helper function. By using `path`, all imports from `@angular-devkit/core` can be eliminated from the file.
2021-08-10 21:40:57 +02:00
Alan Agius
cb7d156c23 perf(@angular-devkit/build-angular): use esbuild as a CSS optimizer for global styles
Esbuild now support CSS sourcemaps which now makes it possible to be used to optimize global CSS.

With this change we also reduce the amount of dependencies by removing `css-minimizer-webpack-plugin` which brings in a number of transitive depedencies which we no longer use.
2021-08-10 19:16:14 +02:00
Charles Lyding
1e142cd29a refactor(@angular-devkit/build-angular): remove legacy ES5 build optimizer usage
The legacy standalone build optimizer was still used when targetting ES5 due to the new babel-based build optimizer only supporting the analysis of ES2015+ code. Mainly due to the presence of native classes, the new build optimizer is faster and significantly less complex. To fully remove the legacy build optimizer, ES5 downleveling of application code is now also performed by babel when the TypeScript configuration specifies an ES5 target. TypeScript will now internally emit ES2015 in this configuration and ES2015 code will be used as the input to the remainder of the build pipeline. This has been the behavior for third-party packages and now all code will be consistently downleveled to ES5 using the same tooling.
2021-08-09 16:50:49 +02:00
Charles Lyding
3bcb729a33 refactor(@angular-devkit/build-angular): remove unneeded ivy enabled checks
Applications can now only be built with Ivy. However, several checks were still present in the code to determine if Ivy was enabled. Since Ivy is always enabled these checks have since become unused code and can be removed.
2021-08-09 14:15:13 +02:00
Alan Agius
2aa6f579d7 fix(@angular-devkit/build-angular): do not consume inline sourcemaps when vendor sourcemaps is disabled.
Not removing inline sourcemaps when vendor sourcemaps is disabled causes an issue during the JS optimization sourcemap merging phase.

```
Optimization error [936.cf7797927c7f989bd40d.js]: Error: Transformation map 1 must have exactly one source file.
```

When vendor sourcemaps is disabled we are not interested into the said sourcemaps so now we remove the inline sourcemap.

Closes #21508
2021-08-06 15:46:50 +02:00
Alan Agius
7dcfffafff feat(@angular-devkit/build-angular): drop support for karma-coverage-instanbul-reporter
BREAKING CHANGE:

Support for `karma-coverage-instanbul-reporter` has been dropped in favor of the official karma coverage plugin `karma-coverage`.
2021-08-05 22:02:10 +02:00
Charles Lyding
f5d019f9d6 fix(@angular-devkit/build-angular): avoid attempting to optimize copied JavaScript assets
When in watch mode (`ng serve`/`ng build --watch`), Webpack's `copy-webpack-plugin` is currently used to implement the project `assets` option within `angular.json`. Files specified by the `assets` option are intended to be copied to the output unmodified and in their original form.  However, if any JavaScript assets were present they previously would have been unintentionally subject to their respective optimization plugins which would result in modified asset outputs and the potential for breakage of the assets. `ng build` outside of watch mode uses a direct file copy with copy-on-write (where supported) to process assets and is therefore not affected by this situation.
When the `copy-webpack-plugin` is used, it adds a `copied` flag to an asset's info metadata. This flag is now used to exclude all such copied JavaScript assets from optimization.
2021-08-05 18:42:39 +02:00
Alan Agius
8758e4415d fix(@angular-devkit/build-angular): handle null maps in JavaScript optimizer worker
`asset.map` can be `null` which causes an unhandled exception.

```
Error: Optimization error [generated/js/custom-elements-es5-polyfills.js]: TypeError: Cannot destructure property 'mappings' of 'map' as it is null.
    at decodeSourceMap (/angular/aio/node_modules/@ampproject/remapping/dist/remapping.umd.js:178:15)
    at Array.map (<anonymous>)
    at buildSourceMapTree (/angular/aio/node_modules/@ampproject/remapping/dist/remapping.umd.js:725:37)
    at Object.remapping [as default] (/angular/aio/node_modules/@ampproject/remapping/dist/remapping.umd.js:831:23)
    at default_1 (/angular/aio/node_modules/@angular-devkit/build-angular/src/webpack/plugins/javascript-optimizer-worker.js:44:44)
```

AIO CI failure: https://app.circleci.com/pipelines/github/angular/angular/35940/workflows/c9c91ad3-1645-4a88-bb5b-6a06a9b887b9/jobs/1032993
2021-08-05 16:26:06 +02:00
Alan Agius
f53bf9dc21 feat(@angular-devkit/build-angular): add type=module to all scripts tags
With this change we add `type=module` to all script tags. This is now possible since IE is no longer supported.

More information about modules can be found here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules
2021-08-05 08:34:13 +02:00
Charles Lyding
0afdff028c refactor(@angular-devkit/build-angular): move all builders into a builders subdirectory
All Angular builders are now located within one subdirectory of the `src` directory. This organization provides better discovery of the builders and will allow builder specific code to be stored in a single area.
2021-08-05 06:49:55 +02:00
Charles Lyding
a2bc175dbf refactor(@angular-devkit/build-angular): remove Webpack loader resolve custom setting
The Webpack configuration setup previously walked up the directory structure to find all `node_modules` directories and then pass this list to Webpack's `resolverLoader.modules` option. This was previously done to ensure that hoisted packages were properly resolved. However, all loader paths are now fully resolved prior to being added to the Webpack configuration. Since loader paths will now be absolute, Webpack no longer needs to resolve them which makes the resolve settings no longer necessary.
2021-08-05 06:48:55 +02:00
Alan Agius
20e48a33c1 feat(@angular-devkit/build-angular): remove deprecated options
BREAKING CHANGE:

With this change we removed several deprecated builder options
- `extractCss` has been removed from the browser builder. CSS is now always extracted.
- `servePathDefaultWarning` and `hmrWarning` have been removed from the dev-server builder. These options had no effect.
2021-08-03 15:07:04 +01:00
Charles Lyding
7576136b2f feat(@angular-devkit/build-angular): remove automatic inclusion of ES5 browser polyfills
BREAKING CHANGE:
The automatic inclusion of Angular-required ES2015 polyfills to support ES5 browsers has been removed. Previously when targetting ES5 within the application's TypeScript configuration or listing an ES5 requiring browser in the browserslist file, Angular-required polyfills were included in the built application. However, with Angular no longer supporting IE11, there are now no browsers officially supported by Angular that would require these polyfills. As a result, the automatic inclusion of these ES2015 polyfills has been removed. Any polyfills manually added to an application's code are not affected by this change.
2021-08-03 11:07:16 +01:00
Charles Lyding
701214d174 feat(@angular-devkit/build-angular): remove differential loading support
BREAKING CHANGE:
Differential loading support has been removed. With Angular no longer supporting IE11, there are now no browsers officially supported by Angular that require ES5 code. As a result, differential loading's functionality for creating and conditionally loading ES5 and ES2015+ variants of an application is no longer required.
2021-08-02 16:59:48 +01:00
Alan Agius
ac3fc2752f feat(@angular-devkit/build-angular): drop support for node-sass
BREAKING CHANGE:

Support for `node-sass` has been removed. `sass` will be used by default to compile SASS and SCSS files.
2021-07-30 14:26:39 +01:00
Charles Lyding
bd9e3905b5 refactor(@angular-devkit/build-angular): remove unused code in webpack configuration partials
Several unused imports and variables as well as redundant conditional checks were removed from the Webpack configuration partials.
2021-07-30 12:44:55 +01:00
originalfrostig
d750c686fd fix(@angular-devkit/build-angular): add priority to copy-webpack-plugin patterns 2021-07-28 11:27:00 -04:00
Alan Agius
1be3b07836 fix(@angular-devkit/build-angular): exclude outputPath from persistent build cache key
With this change we exclude `outputPath` from cache key due to i18n extraction which causes it to change on every build 736a5f89de/packages/angular_devkit/build_angular/src/utils/i18n-options.ts (L264-L265)

Closes #21275
2021-07-14 13:13:37 -07:00
Charles Lyding
2c2b499193 fix(@angular-devkit/build-angular): limit advanced terser passes to two
Limiting the terser passes to two helps to workaround an issue with terser wherein terser will errantly inline a function argument containing a `yield` expression inside an inner arrow function.  This results in a syntax error since the yield expression is no longer within the scope of a generator.
2021-07-13 15:21:06 +01:00
Charles Lyding
fefd6d0421 perf(@angular-devkit/build-angular): use esbuild as a CSS optimizer for component styles
The stylesheet optimization pipeline now uses `esbuild` for component stylesheets. The usage of `esbuild` provides noticeable build time improvements as well as, on average, smaller output sizes.
`esbuild` currently does not support stylesheet sourcemaps. However, since the Angular CLI does not support component stylesheet sourcemaps when optimizing, this lack of support is problematic.
Global stylesheets will continue to use `cssnano` as an optimizer due to sourcemaps being required for global stylesheets even when optimizing. When `esbuild` adds stylesheet sourcemap support, global stylesheets may be transitioned to `esbuild` as well.
2021-07-13 15:20:49 +01:00
Alan Agius
9a04975a21 fix(@angular-devkit/build-angular): extractLicenses didn't have an effect when using server builder 2021-07-12 16:39:34 +01:00
Alan Agius
3d71c63b3a fix(@angular-devkit/build-angular): fix issue were @media all causing critical CSS inling to fail
Workaround for Critters as it doesn't work when `@media all {}` is minified to `@media {}`.

Closes #20804
2021-07-09 17:04:23 +01:00
Charles Lyding
6eca86b817 refactor(@angular-devkit/build-angular): replace raw-loader with Webpack 5 asset modules
With Webpack 5, the `raw-loader` is no longer needed and its functionality is provided via configuration options within the Webpack configuration via asset modules.  Asset modules (https://webpack.js.org/guides/asset-modules/) provide a built-in way to provide `raw-loader`, `url-loader`, and `file-loader` functionality without additional dependencies.
2021-07-07 15:51:19 -04:00
Charles Lyding
beb78ef79e refactor(@angular-devkit/build-angular): use Webpack provided watcher typings instead of custom
Webpack 5 now provides type definitions for the majority of the watch subsystem. These type definitions allow the removal of the custom types that were previously used.
2021-07-07 09:24:09 -04:00
Alan Agius
a5c69722ff fix(@angular-devkit/build-angular): ensure NG_PERSISTENT_BUILD_CACHE always creates a cache in the specified cache directory
This change fixes `NG_PERSISTENT_BUILD_CACHE` sometimes creating cache
entries that live outside of the cache directory by using a hex encoding
rather than a base64 encoding. This error is caused because the base64
alphabet includes `/`. According to the webpack documentation [1] the
default `cacheLocation` is:

  path.resolve(cache.cacheDirectory, cache.name)

Which means cache names with a leading `/` would remove the
`cacheDirectory` altogether.

[1]: https://webpack.js.org/configuration/other-options/#cachecachelocation
2021-07-06 11:38:12 -04:00
Charles Lyding
34e66ff4d2 refactor(@angular-devkit/build-angular): use Webpack provided loader types
Webpack now provides loader function type definitions. These type definitions are now used in custom loaders within the package.
This improves type safety and behavior correctness of the loaders when used with Webpack.
2021-07-02 15:44:39 -04:00
Alan Agius
8383c6b421 fix(@angular-devkit/build-angular): silence Sass compiler warnings from 3rd party stylesheets
With this change we enable `quietDeps`, which causes the Sass compiler not to emit warnings from a stylesheet that is loaded through load-path.

The `--verbose` option can be used to opt-out from this behaviour and display all warnings.

Closes #21235
2021-07-02 11:55:56 -04:00
Charles Lyding
9afe185fc6 build: enable noImplicitOverride TypeScript option
The `noImplicitOverride` TypeScript option improves code quality by ensuring that properties from base classes are not accidentally overriden.
Reference: https://www.typescriptlang.org/tsconfig#noImplicitOverride
2021-07-02 06:40:36 -04:00
Alan Agius
212939d6a3 Revert "refactor: disable esbuild worker threads"
This reverts commit 47a1ccc50729ad25e4fa4e38704c8dbd3b1737f7.
2021-07-01 13:29:22 +02:00
Alan Agius
070a133647 fix(@angular-devkit/build-angular): configure webpack target in common configuration
Previously, `target` was unset for `test` which caused the target to be set incorrectly.

Closes #21239
2021-06-30 19:26:36 +02:00
Alan Agius
6a2b11906e perf(@angular-devkit/build-angular): cache JavaScriptOptimizerPlugin results
With this change we cache JavaScriptOptimizerPlugin results in memory or on the file system based on the caching strategy used.
2021-06-30 17:41:01 +02:00
Alan Agius
47a1ccc507 refactor: disable esbuild worker threads
This is a workaround for `TypeError [Error]: Cannot read property 'workerPort' of undefined`.
2021-06-28 17:57:57 +02:00