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

Externalize all @woocommerce packages via DEWP and remove the selective bundling implementation #2072

Merged
merged 5 commits into from
Sep 1, 2023

Conversation

eason9487
Copy link
Member

@eason9487 eason9487 commented Aug 25, 2023

Changes proposed in this Pull Request:

Closes #1527
Closes #1971

This PR externalizes all @woocommerce packages via DEWP, and it can also fix #1971 by the way.

  • Change the bundled @woocommerce packages to use external sources from DEWP.
    • @woocommerce/currency
    • @woocommerce/date
    • @woocommerce/number
    • @woocommerce/tracks
  • Remove the selective bundling implementation that gradually externalizes packages into DEWP.
  • Rebalance the max size config of bundlewatch for each non-wildcard file to 1.2 times.
  • Update DEWP document.

Screenshots:

image

Detailed test instructions:

  1. Check if all build scripts, npm start, npm run dev, npm run start:hot and npm run build, can run successfully.
  2. Run bundle analyzer: npm run env -- NODE_ENV=production wp-scripts build --webpack-bundle-analyzer
    • Check if there is no DEWPable @woocommerce/* package included in the build bundle.
  3. Read through Selective bundling & extracting to see if the updated description is appropriate.
  4. Follow the reproduction steps in moment.tz gets conflicted when the site timezone is other than UTC #1971 to check if wp.date.getDate() can run successfully.

Additional details:

The current versions of @woocommerce/currency, @woocommerce/date, @woocommerce/number and @woocommerce/tracks packages are the same versions as the latest WooCoomerce release (8.0.2):

Therefore, switching to DEWP should not have any effect.

Changelog entry

Dev - Externalize all WooCommerce JavaScript packages via Dependency Extraction Webpack Plugin (DEWP) and remove the selective bundling implementation that gradually externalizes packages into DEWP.

@eason9487 eason9487 requested a review from a team August 25, 2023 10:39
@eason9487 eason9487 self-assigned this Aug 25, 2023
@github-actions github-actions bot added the changelog: dev Developer-facing only change. label Aug 25, 2023
@tomalec tomalec self-requested a review August 31, 2023 12:36
@tomalec
Copy link
Member

tomalec commented Aug 31, 2023

The current versions of @woocommerce/currency, @woocommerce/date, @woocommerce/number and @woocommerce/tracks packages are the same versions as the latest WooCoomerce release (8.0.2):

👍 They also stay at those versions since our L-2 7.8.2:

 dewped pdep --wpVersion=6.2.2 --wcVersion=7.8.2 -d .externalized.json
 ›   Warning: @woocommerce/settings version not found in WooCommerce 7.8.2 at 
 ›   https://raw.githubusercontent.com/woocommerce/woocommerce/7.8.2/packages/js/settings/package.json.
 Name                               WordPress 6.2.2 WooCommerce 7.8.2 Local    
 ────────────────────────────────── ─────────────── ───────────────── ──────── 
 @woocommerce/components                            12.0.0            ^10.3.0  
 @woocommerce/currency                              4.2.0             ^4.2.0   
 @woocommerce/customer-effort-score                 2.2.0             ^2.2.0   
 @woocommerce/data                                  4.1.0             ^4.1.0   
 @woocommerce/date                                  4.2.0             ^4.2.0   
 @woocommerce/navigation                            8.1.0             8.1.0    
 @woocommerce/number                                2.4.0             ^2.4.0   
 @woocommerce/settings                              unknown                    
 @woocommerce/tracks                                1.3.0             ^1.3.0   

Maybe we could consider (not necessarily here) bumping @woocommerce/components to 12.0.0

@tomalec
Copy link
Member

tomalec commented Aug 31, 2023

I'm not a native English speaker, but I passed .md section through Grammarly and added a few tweaks, WDYT of the below:

In the past, we did bundle some packages provided by WordPress/WooCommerce instances. We did so to use a specific package version, for example, to ship a new feature we need, fix, or avoid a bug. However, bundling a package tends to introduce other errors, as some packages are not effectively modular, so we face version conflicts, style collisions, etc.
Also, we'd like to reduce the size of our bundle, so eventually, we aim to extract/externalize as much as possible and import from an external package when possible.

To help with that, we had implemented the `extracted/` prefix in the past. It was also a custom implementation in [`webpack.config.js`](webpack.config.js).
Thanks to that, even though a package is bundled, the given import would fetch it from external.

Now, we have already externalized all DEWP-able packages, so we also removed the implementation of the `extracted/` prefix.
If someday we ever need it again, please refer to:
- The PR implemented it: https://github.com/woocommerce/google-listings-and-ads/pull/1762
- The commit removed it: https://github.com/woocommerce/google-listings-and-ads/commit/5a2e20409a53ccb3b7fcbfe5c46988ca2b153b38
Alternatively, we can consider an opposite approach and selectively **bundle** with a similar prefix implementation.

Copy link
Member

@tomalec tomalec left a comment

Choose a reason for hiding this comment

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

Reviewed the code, tested the build scripts, smoke tested the site, LGTM.

Thank you for such a significant cleanup :) and removing w big chunk from our bundle
image

@eason9487
Copy link
Member Author

Thanks for the review, @tomalec

The current versions of @woocommerce/currency, @woocommerce/date, @woocommerce/number and @woocommerce/tracks packages are the same versions as the latest WooCoomerce release (8.0.2):

👍 They also stay at those versions since our L-2 7.8.2:
[...]
Maybe we could consider (not necessarily here) bumping @woocommerce/components to 12.0.0

I tried bumping the WP and WC packages to L-2 while working on #2069, but there were quite a few problems with npm install, so more time is needed for further investigation. I'll revisit this some other time.

I'm not a native English speaker, but I passed .md section through Grammarly and added a few tweaks, WDYT of the below: [...]

Thanks for the suggestion! Updated in 0157e87.

@eason9487 eason9487 merged commit 2854ba9 into develop Sep 1, 2023
4 checks passed
@eason9487 eason9487 deleted the dev/externalize-wc-packages branch September 1, 2023 02:46
@puntope puntope mentioned this pull request Sep 5, 2023
17 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog: dev Developer-facing only change.
Projects
None yet
2 participants