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

Build: Add globalThis DefinePlugin config to webpack #6596

Closed

Conversation

sirreal
Copy link
Member

@sirreal sirreal commented May 21, 2024

This updates the build to account for the following PR:

WordPress/gutenberg#61486

This affects the build of JavaScript packages to ensure dead-code elimination works correctly.

It should be harmless to land this PR before packages are updated. The older configuration can be removed after the packages are updated.

Trac ticket: https://core.trac.wordpress.org/ticket/61262


This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.

This updates the build to account for the following PR:

WordPress/gutenberg#61486
Copy link

github-actions bot commented May 21, 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.

Core Committers: Use this line as a base for the props when committing in SVN:

Props jonsurrell, youknowriad, swissspidy.

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

Copy link

Trac Ticket Missing

This pull request is missing a link to a Trac ticket. For a contribution to be considered, there must be a corresponding ticket in Trac.

To attach a pull request to a Trac ticket, please include the ticket's full URL in your pull request description. More information about contributing to WordPress on GitHub can be found in the Core Handbook.

Copy link

Test using WordPress Playground

The changes in this pull request can previewed and tested using a WordPress Playground instance.

WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

Some things to be aware of

  • The Plugin and Theme Directories cannot be accessed within Playground.
  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

@swissspidy
Copy link
Member

I‘m confused, why does this require a core change?

Does this mean any other projects using these packages also need to update their configs?

I thought those variables in the GB packages are replaced during compile time for dead code elimination and shouldn‘t be present in the distributed packages.

@youknowriad
Copy link
Contributor

Does this mean any other projects using these packages also need to update their configs?

I think it's not mandatory and these values would act as "false" by default but if you want to tree-shake them out of the code base, it's better to update the config.

@youknowriad
Copy link
Contributor

The variables are present in the packages (just like the previous ones were) to allow the folks importing the packages (Gutenberg or Core) to decide whether to enable something or not (disabled by default)

@sirreal
Copy link
Member Author

sirreal commented May 23, 2024

The variables are replaced when they're compiled as Core Scripts or Script Modules. They're shipped in the npm packages (that has not changed at all with WordPress/gutenberg#61486).

Gutenberg does that here:

https://github.com/WordPress/gutenberg/blob/f49e0b5958adad9fbd211d5ded07b4cabf5bfec3/tools/webpack/shared.js#L65-L76

This PR is updating Core's build configuration accordingly.

@sirreal
Copy link
Member Author

sirreal commented May 23, 2024

Does this mean any other projects using these packages also need to update their configs?

Yes and no. If folks are actually compiling projects with the npm packages (bundled, not provided by WordPress) and had configured their bundler to perform replacements then they'd need to update. I believe those are very exceptional conditions.

There shouldn't be anything harmful about this change for most projects, in fact it's safer as it should remove some of the problems that process.env has.

@sirreal sirreal requested a review from youknowriad May 23, 2024 12:16
@youknowriad
Copy link
Contributor

LGTM

@gziolo
Copy link
Member

gziolo commented May 24, 2024

Committed with https://core.trac.wordpress.org/changeset/58193. We will have to follow up with the removal of old replacements when the next version of WP packages gets published to npm.

@gziolo gziolo closed this May 24, 2024
@sirreal sirreal deleted the update/webpack-build-gb-61486 branch May 24, 2024 09:20
@sirreal
Copy link
Member Author

sirreal commented Jun 25, 2024

#6904 is the follow-up to remove the legacy configuration.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Status: Done
Development

Successfully merging this pull request may close these issues.

4 participants