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

fix(@angular-devkit/build-angular): prevent webpack from adding suffixes to polyfill files #16181

Merged
merged 1 commit into from
Nov 18, 2019

Conversation

clydin
Copy link
Member

@clydin clydin commented Nov 13, 2019

The ES5 polyfills file was erroneously being suffixed with es2015. The webpack configuration does not support conditional customization per chunk for the output filenames (chunkFilename option schema only supports string values). This change adds an additional small webpack plugin that allows the chunk filenames to be adjusted based on the chunk name. The plugin is only added when differential loading is enabled as this is the only time that a chunk currently requires its filename to be adjusted.

Closes #15915

@clydin clydin added the target: patch This PR is targeted for the next patch release label Nov 13, 2019
@clydin clydin force-pushed the fix-webpack-chunk-naming branch from 5325f97 to f76fed6 Compare November 13, 2019 17:28
…xes to polyfills files

The ES5 polyfills file was erroneously being suffixed with `es2015`.  The webpack configuration does not support conditional customization per chunk for the output filenames (`chunkFilename` option schema only supports string values).  This change adds an additional small webpack plugin that allows the chunk filenames to be adjusted based on the chunk name.  The plugin is only added when differential loading is enabled as this is the only time that a chunk currently requires its filename to be adjusted.

Closes angular#15915
const isMap = filename && filename.endsWith('.map');

return data.chunk && data.chunk.name === 'polyfills-es5'
? `polyfills-es5${hashFormat.chunk}.js${isMap ? '.map' : ''}`
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm a bit confused here, this doesn't seem to change the name of polyfills-es5-es2015.js, instead it seems to target polyfills-es5.js.

Copy link
Member Author

Choose a reason for hiding this comment

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

The assetPath hook is used by webpack to create the output filename/path for each chunk. The filename that is passed as an argument to the hook is actually the filename template from the webpack configuration (defined here in the CLI). Chunk names are defined via the entry point configuration (polyfills-es5 is defined here).
This plugin allows the template for the output filename to be altered on a per chunk basis. In this case, the polyfills-es5 chunk's filename template is changed to remove the targetInFileName segment (-es2015 in the differential loading case). This causes webpack to generate the correct name and removes the need to patch the stats file and clean up the filenames after the fact.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok I see now, thank you. The logic is a bit circuitous and I worry about someone else altering this code. Can you add it as a comment please?

@dgp1130 dgp1130 merged commit d8438f7 into angular:master Nov 18, 2019
@dgp1130
Copy link
Collaborator

dgp1130 commented Nov 18, 2019

Merged to patch branch 9.0.x: https://github.com/angular/angular-cli/commits/9.0.x

@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 Dec 19, 2019
@clydin clydin deleted the fix-webpack-chunk-naming branch January 9, 2020 16:34
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
target: patch This PR is targeted for the next patch release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

webpack-bundle-analyzer errors out on differential build - no such file
4 participants