292 Commits

Author SHA1 Message Date
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
Charles Lyding
5804fec902 refactor(@angular-devkit/build-angular): remove Webpack 4 specific type casting
Webpack 5 contains improved types and exports that reduce the need to perform additional type casting throughout the internal Webpack plugins.
2021-04-19 20:32:13 +02:00
Charles Lyding
e55923656c fix(@angular-devkit/build-angular): avoid double build optimizer processing
TypeScript files had the potential to be processed twice by the build optimizer. This did not affect the output code but could lead to longer production build times. The build optimizer is now configured in one centralized location for both TypeScript and JavaScript files. The Webpack configuration partial for TypeScript support is also reduced to one common function for both AOT and JIT as a result.
2021-04-19 20:30:21 +02:00
Charles Lyding
bac563e5ee feat(@angular-devkit/build-angular): support specifying stylesheet language for inline component styles
A new build option named `inlineStyleLanguage` has been introduced that will allow a project to define the stylesheet language used in an application's inline component styles. Inline component styles are styles defined via the `styles` property within the Angular `Component` decorator. Both JIT and AOT mode are supported. However, JIT mode requires that inline styles only be string literals (compile-time partial evaluation is not supported in JIT mode). Currently supported language options are: `CSS` (default), `Sass`, `SCSS`, and `Less`. If the option is not specified, `CSS` will be used and enables existing projects to continue to function as expected.
2021-04-14 07:21:11 -04:00
Charles Lyding
330235230c refactor(@angular-devkit/build-angular): remove redundant webpack-sources dependency
The `webpack` package now exports the `Source` based classes directly.
2021-04-13 15:34:54 -04:00
Alan Agius
c609e7104c build: update to cssnano to version 5.0.0
Closes #19106
2021-04-13 10:50:02 -04:00
Alan Agius
cc52e5453c fix(@angular-devkit/build-angular): remove duplicate application bundle generation complete message
In some scenarios in Webpack 5 percentage goes from 1 back to 0.99, ex: 0.99 -> 1 -> 0.99 -> 1. This causes the "complete" message to be displayed multiple times.
2021-04-13 10:49:40 -04:00
Alan Agius
1532e32cc2 refactor: clean up webpack 4 code 2021-04-13 10:49:17 -04:00
Charles Lyding
d47b4417d4 feat(@angular-devkit/build-angular): support processing component inline CSS styles
The internal Webpack configuration now includes support for style rules with MIME type conditions. This allows the data URIs generated for inline component CSS styles by the Angular Webpack plugin to be processed with the same loaders as file based styles.
2021-04-12 14:08:43 -04:00
Alan Agius
dee6b79489 refactor: remove @types/webpack 2021-04-12 10:02:07 -04:00
Alan Agius
0f4bbb58d4 refactor(@angular-devkit/build-angular): remove webpack 4 checks
These are no longer needed as we don't support Webpack 4 any longer
2021-04-12 10:02:07 -04:00
Alan Agius
bd0aba7c80 fix(@angular-devkit/build-angular): disable webpack cache when using NG_BUILD_CACHE 2021-04-12 10:02:07 -04:00
Charles Lyding
79f369c26f refactor(@angular-devkit/build-angular): optimize analytics plugin bundle stats for Webpack 5
Newer Webpack 5 APIs allow the bundle stat generation for analytics to be optimized including less iteration of chunks and assets.
2021-04-08 09:42:47 -04:00
Charles Lyding
d883ce5d7e feat(@angular-devkit/build-angular): upgrade to Webpack 5 throughout the build system
With this change Webpack 5 is now used by the Angular tooling to build applications. Webpack 4 usage and support has been removed.
No project level configuration changes are required to take advantage of the upgraded Webpack version when using the official Angular builders.
Custom builders based on this package that use the experimental programmatic APIs may need to be updated to become compatible with Webpack 5.

BREAKING CHANGE: Webpack 5 lazy loaded file name changes
Webpack 5 generates similar but differently named files for lazy loaded JavaScript files in development configurations (when the `namedChunks` option is enabled).
For the majority of users this change should have no effect on the application and/or build process. Production builds should also not be affected as the `namedChunks` option is disabled by default in production configurations.
However, if a project's post-build process makes assumptions as to the file names then adjustments may need to be made to account for the new naming paradigm.
Such post-build processes could include custom file transformations after the build, integration into service-side frameworks, or deployment procedures.
Example development file name change: `lazy-lazy-module.js` --> `src_app_lazy_lazy_module_ts.js`

BREAKING CHANGE: Webpack 5 web worker support
Webpack 5 now includes web worker support. However, the structure of the URL within the `Worker` constructor must be in a specific format that differs from the current requirement.
Web worker usage should be updated as shown below (where `./app.worker` should be replaced with the actual worker name):
Before: `new Worker('./app.worker', ...)`
After:  `new Worker(new URL('./app.worker', import.meta.url), ...)`
2021-04-08 09:42:47 -04:00
Charles Lyding
8770d5f015 refactor(@angular-devkit/build-angular): remove use of deprecated ngtools ivy namespace export
With the removal of the deprecated ViewEngine-based Webpack plugin, the ivy namespace export that was previously used is now deprecated in favor of direct exports of the Ivy-based plugin.
2021-04-05 19:20:56 +02:00
Charles Lyding
677913fc38 fix(@angular-devkit/build-angular): remove usage of deprecated View Engine compiler
BREAKING CHANGE: Removal of View Engine support from application builds
With the removal of the deprecated View Engine compiler in Angular version 12 for applications, Ivy-based compilation will always be used when building an application.
The default behavior for applications is to use the Ivy compiler when building and no changes are required for these applications.
For applications that have opted-out of Ivy, a warning will be shown and an Ivy-based build will be attempted. If the build fails,
the application may need to be updated to become Ivy compatible.
2021-04-02 08:11:11 +02:00
Alan Agius
3d1bd01641 refactor(@angular-devkit/build-angular): remove ngfactories checks 2021-03-30 14:37:09 -06:00
Alan Agius
b35517505f refactor(@angular-devkit/build-angular): remove view engine check from analytics collector 2021-03-30 14:37:09 -06:00
Charles Lyding
ac4c109beb fix(@angular-devkit/build-angular): ensure output directory is present before writing stats JSON
If an error occurs during a build, it is possible that the output path directory may not be present and then cause the stats JSON file write to fail.

Fixes: #20349
2021-03-22 15:41:41 -04:00
Alan Agius
2616ef0d3f feat(@angular-devkit/build-angular): integrate JIT mode linker
With this change we intergate JIT mode linker into the Angular CLI.

Closes #20281
2021-03-18 15:38:52 +01:00
Charles Lyding
d5645675fd fix(@angular-devkit/build-angular): support writing large Webpack stat outputs
When using the `statsJson` browser builder option, the resulting JSON data is now streamed into a file instead of written in one large block.  This mitigates crashes due to the generated string exceeded the Node.js limit.
2021-03-17 11:27:27 +01:00
Alan Agius
6cc8c26083 refactor(@ngtools/webpack): remove suppressZoneJsIncompatibilityWarning option
BREAKING CHANGE

`suppressZoneJsIncompatibilityWarning` option has been removed. If you are using this plugin directly and `async/await` in ES2017 make sure you downlevel the async syntax using Babel.

See: https://github.com/angular/zone.js/pull/1140 for more information.
2021-03-15 20:31:25 +01:00
Charles Lyding
699b641b85 perf(@angular-devkit/build-angular): remove Webpack Stats.toJson usage in karma plugin
Webpack's `Stats.toJson` function is an expensive operation and is recommended to be avoided where possible. In the case of the karma plugin, the compilation errors can be accessed directly without the need for the function call.
2021-03-15 09:01:50 +01:00
Charles Lyding
3affd28f5e perf(@angular-devkit/build-angular): remove Webpack Stats.toJson usage in analytics plugin
Webpack's Stats.toJson function is an expensive operation and is recommended to be avoided where possible. In the case of the analytics plugin, the chunks and assets can be accessed directly from the Webpack compilation.
2021-03-15 09:01:36 +01:00
Alan Agius
1e9881bcb4 refactor(@angular-devkit/build-angular): replace lazy loading resources context path 2021-03-10 12:44:04 -06:00
Alan Agius
988b05a8e5 refactor(@angular/cli): remove deprecated lazyModules option from schema 2021-03-10 12:44:04 -06:00
Alan Agius
8d66912323 refactor(@angular-devkit/build-angular): remove deprecated lazyModules option
BREAKING CHANGE:

Server and Browser builder `lazyModules` option has been removed without replacement.
2021-03-10 12:44:04 -06:00
Charles Lyding
240727aefa refactor(@angular-devkit/build-angular): separate global script configuration logic
This change moves the global script resolution logic to a separate function to aid in reducing the complexity of the Webpack styles configuration partial generation function.
2021-03-08 08:46:20 -06:00
Charles Lyding
1b5798dba3 refactor(@angular-devkit/build-angular): use nested Webpack rules to define style processing
By using Webpack's nested rule and `oneOf` rule support, a large amount of conditional logic and array processing can be removed from the Webpack style configuration generator function.
2021-03-08 08:46:20 -06:00
Charles Lyding
3408c3df49 refactor(@angular-devkit/build-angular): only inline component stylesheet sourcemaps
This change also ensures that hidden sourcemaps will be propagated through the loader chain and are extracted for global stylesheets.
2021-03-02 06:13:19 -05:00
Alan Agius
2ef39498b0 fix(@angular-devkit/build-angular): disable declaration and declarationMap
When building an application or testing a library. TypeScript declarations are not needed.

Closes #20103
2021-02-22 16:55:44 +01:00
Alan Agius
f309516bcd refactor(@angular-devkit/build-angular): drop support for zone.js 0.10
BREAKING CHANGE:

Minimum supported `zone.js` version is `0.11.4`
2021-02-17 12:44:43 -06:00
Renovate Bot
e2d6df29e7 build: update webpack-dev-middleware to version 4.1.0 2021-02-15 14:46:21 -06:00
Charles Lyding
40dc44b64b refactor(@angular-devkit/build-angular): remove usage of Webpack Stats.ToJsonOutput type
The `Stats.ToJsonOutput` type is not present in the Webpack 5 typings. There was also a large amount of forced typing in the code to successfully compile.
Minimal Webpack JSON stat types are now used that represent the fields used by the tooling.
2021-02-11 12:33:47 -05:00
Charles Lyding
e871f87fa2 refactor(@angular-devkit/build-angular): remove use of Webpack RuleSetLoader type
The `RuleSetLoader` type is not exported from the Webpack 5 types.
2021-02-10 14:08:07 -05:00
Alan Agius
9337617723 feat(@angular-devkit/build-angular): add postcss-preset-env with stage 3 features
With this change we add `postcss-preset-env` with stage 3 features. This stage includes support for:

 - all property
 - break properties
 - custom properties
 - font-variant property
 - gap properties
 - media query ranges

See https://preset-env.cssdb.org/features#stage-3
2021-02-09 10:30:42 -05:00
Alan Agius
fb2d7ee903 refactor(@angular-devkit/build-angular): remove experimental rollup pass
The experimental rollup pass has significant issues with the new Ivy webpack plugin. It also, didn't produce as well as we hoped in real world scenarios infact in many cases this caused build to fail.

REAKING CHANGE:

The experimental rollup pass `--experimental-rollup-pass` option has been removed.

Closes #15836
2021-02-09 08:50:00 -05:00
Alan Agius
aedfcc1862 build: update to @types/node version 12 2021-02-08 14:07:24 -05:00
Amadou Sall
1b5971a0bc fix(@angular-devkit/build-angular): the root Tailwind configuration file is always picked
A configuration file in the project root should take precedence over one in the workspace root, but it's not currently the case.
2021-02-08 09:33:59 -05:00
S. Iftekhar Hossain
a7ffce10ee fix(@angular-devkit/build-angular): fixed ignoring of karma plugins config
Previously `karma-coverage` was validated only when in karma plugins config one of these was added
``'karma-coverage'` or `require('karma-coverage')`

This change will allow cli to validate `karma-coverage` plugin if in `karma.conf.js` `'karma-*'` is used. Example:
```
plugins: [
      ...
      'karma-*',
      require('@angular-devkit/build-angular/plugins/karma'),
      ...
    ]
```

Fixes #19993
2021-02-08 09:30:00 -05:00
Charles Lyding
ab5078d660 fix(@angular-devkit/build-angular): increase resilience of babel cache identifier
This provides a default cache identifer to the babel loader that includes all internal options from the customized babel loader.
2021-02-04 19:44:07 +01:00
Alan Agius
6732294ff3 refactor(@angular-devkit/build-angular): remove file-loader dependency
`file-loader` resolves `import/require()` on a file into a url. This is non standard, undocumented, unsupported Webpack specific functionality. This was introduced in the Angular CLI  before `postcss-cli-resources` existed and was never removed.

Using `file-loader` and `postcss-cli-resources` are no longer needed with Webpack 5, because of the introduction of [Assets Modules](https://webpack.js.org/guides/asset-modules/).

BREAKING CHANGE:

The unsupported/undocumented, Webpack specific functionality to `import`/`require()` a non-module file has been removed.

Before
```js
import img from './images/asset.png';
```

After
```html
<img src="images/asset.png">
```
2021-02-04 08:42:57 +01:00