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

Centralize and Automate Plugin Asset Minification in Webpack #1718

Open
wants to merge 11 commits into
base: trunk
Choose a base branch
from

Conversation

ShyamGadde
Copy link
Contributor

Summary

Fixes #1711

This is also an attempt to improve the solution introduced in #1643 by further streamlining the process of generating minified asset files.

Relevant technical choices

  • Removed Webpack configurations for Performance Lab, Embed Optimizer, and Image Prioritizer that existed solely for asset minification, making them redundant with the new centralized approach.
  • Implemented plugin-specific minification:
    • When running npm run build:plugin:optimization-detective (or any specific plugin), only assets for that plugin are minified.
    • This prevents redundant minification when using npm run build-plugins script, which would otherwise re-minify the same assets multiple times (while the overhead may be minimal, this approach avoids redundancy.)
  • When npm run build is executed, it generates minified versions of assets across all plugins.

Added `noErrorOnMissing` to prevent errors when JavaScript or CSS files
are absent for specific plugins.
webpack.config.js Outdated Show resolved Hide resolved
@westonruter westonruter added Infrastructure Issues for the overall performance plugin infrastructure no milestone PRs that do not have a defined milestone for release labels Dec 3, 2024
@ShyamGadde ShyamGadde marked this pull request as ready for review December 4, 2024 00:24
Copy link

github-actions bot commented Dec 4, 2024

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: ShyamGadde <[email protected]>
Co-authored-by: westonruter <[email protected]>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@westonruter westonruter added skip changelog PRs that should not be mentioned in changelogs [Type] Enhancement A suggestion for improvement of an existing feature no milestone PRs that do not have a defined milestone for release and removed no milestone PRs that do not have a defined milestone for release labels Dec 4, 2024
Copy link
Member

@westonruter westonruter left a comment

Choose a reason for hiding this comment

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

Looking good to me, but someone who is more experienced with webpack than me should review this.

webpack.config.js Outdated Show resolved Hide resolved
@@ -16,6 +16,7 @@ on:
- 'tests/multisite.xml'
- 'composer.json'
- 'composer.lock'
- 'webpack.config.js'
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The reason for adding this is that unit tests for the plugins can fail if the minified assets aren’t generated. Since Webpack is responsible for generating these assets and copying necessary libraries from node_modules to the build, it makes sense to include changes to webpack.config.js as a trigger for the unit tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Infrastructure Issues for the overall performance plugin infrastructure no milestone PRs that do not have a defined milestone for release skip changelog PRs that should not be mentioned in changelogs [Type] Enhancement A suggestion for improvement of an existing feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants