Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade tooling to use Webpack 5 #20466

Merged
merged 7 commits into from
Apr 8, 2021
Merged

Conversation

clydin
Copy link
Member

@clydin clydin commented Apr 8, 2021

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), ...)

@clydin clydin added the target: major This PR is targeted for the next major release label Apr 8, 2021
@google-cla google-cla bot added the cla: yes label Apr 8, 2021
@clydin clydin requested a review from alan-agius4 April 8, 2021 02:16
@alan-agius4 alan-agius4 linked an issue Apr 8, 2021 that may be closed by this pull request
Copy link
Collaborator

@alan-agius4 alan-agius4 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good job!

Couple of points that should probably be addressed in a seperate PR.

  • clean up left over withWebpackFourOrFive and isWebpackFiveOrHigher calls especially in build-angular.
  • should peer dependency on webpack 4 be dropped though-out?
  • will a migration for the web-worker syntax change be done?
  • update all 3P webpack plugins and loaders, since some of them are outdated due to the lack of support for Webpack 4.

@clydin
Copy link
Member Author

clydin commented Apr 8, 2021

Once this is in, there are a variety of refactoring and cleanup opportunities throughout the codebase by leveraging new Webpack 5 capabilities. I tried to keep this PR close to a minimal set of changes to enable Webpack 5 to reduce the effort in getting it reviewed and merged.

@clydin clydin added the action: merge The PR is ready for merge by the caretaker label Apr 8, 2021
@alan-agius4
Copy link
Collaborator

alan-agius4 commented Apr 8, 2021

Once this is in, there are a variety of refactoring and cleanup opportunities throughout the codebase by leveraging new Webpack 5 capabilities. I tried to keep this PR close to a minimal set of changes to enable Webpack 5 to reduce the effort in getting it reviewed and merged.

Yeah, that was a good plan!

The `@angular-devkit/build-webpack` package now officially supports Webpack 5.
Webpack 4 support is temporarily maintained while the remainder of the tooling is transitioned.
…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), ...)`
…ndle 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.
The direct Webpack test for the Webpack plugin is now updated to use Webpack 5 as Webpack 5 is now the default for the Angular tooling.
…tion

This change allows multiple instances of the `AngularWebpackPlugin` to be present in a Webpack configuration.
Each plugin instance should reference a different TypeScript configuration file (`tsconfig.json`) and the TypeScript configuration files should be setup to not include source files present in the other TypeScript configuration files. If files are included in more than one TypeScript configuration, the first plugin present in the Webpack configuration that can emit the file will be used.

Closes: angular#5072
Webpack 5 now includes web worker support. However, the structure of the URL within the `Worker` constructor must be in a specific format.
Before: `new Worker('./app.worker', ...)`
After: `new Worker(new URL('./app.worker', import.meta.url), ...)`
@clydin clydin merged commit df988c2 into angular:master Apr 8, 2021
@clydin clydin deleted the webpack5/upgrade branch April 8, 2021 13:42
@@ -133,7 +133,7 @@ export class OptimizeCssWebpackPlugin {
map,
);
} else {
newSource = new RawSource(output.css);
newSource = new sources.RawSource(output.css);
}

compilation.assets[file] = newSource;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just note, we have https://github.com/webpack-contrib/css-minimizer-webpack-plugin - cache and multi threading included

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for sharing, will take a look

@clydin clydin mentioned this pull request Apr 13, 2021
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators May 10, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker target: major This PR is targeted for the next major release
Projects
None yet
3 participants