-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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: Split packages and blocks to their webpack configs #1412
Conversation
), | ||
} ), | ||
new DependencyExtractionPlugin( { | ||
injectPolyfill: true, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like the option for combining assets into one file doesn't quite work with multiple webpack configs so I left it disabled for blocks for now since we have only one file for now. It will require upstream changes.
The issue is that it only outputs only one file for the config that was processed last ...
@youknowriad and @desrosj, let me know what do you think. This is a prerequisite if we still want to wire the JavaScript file necessary for PDF embeds for the FIle block to WordPress 5.8. |
fe0d7d0 provides the way to enqueue the view script for the File block on the front end: |
This patch depends on #1430. Once the planned changes to WordPress npm packages are published to npm and committed to WP core, this branch can be rebased, retested and committed. |
@@ -29,6 +29,9 @@ wp-tests-config.php | |||
/src/wp-includes/css/*.min.css | |||
/src/wp-includes/css/*-rtl.css | |||
/src/wp-includes/blocks/**/*.css | |||
/src/wp-includes/blocks/**/*.js |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The same changes need to be reflected in SVN for the file
subfolder.
I can confirm that it works as expected with all the latest changes applied to the patch. Inline PDF embed enabledThe view script is included in the HTML source of the page together with the polyfill script: Note: Addressed with 446a3d5 Inline PDF embed disabledThe view script is not included in the HTML source as expected: |
This is looking good to me. @desrosj mind doing a quick review here? |
I'm seeing the following notice locally:
Is this because an update to the file block needs to be published? Otherwise it seems to work well for me. |
I'm pretty sure that's unrelated, I did get these tall selects sometimes (outside this PR) but we were not able to reproduce consistently yet. There are probably multiple factors involved there.
This is definitely related to this PR, I need to investigate it more, I wish @gziolo was around :) |
I'm not able to see the notice, though it can be my docker config hiding it I don't know 🤔 |
After several tries, I'm still not able to reproduce the notice. Let's continue monitor this. |
committed in https://core.trac.wordpress.org/changeset/51259 |
Unfortunately this caused a PHP notice that I was unable to solve before it was time to package RC1, so I've had to revert it and the related commits. |
I will give it another try after WordPress 5.8 is out 👍🏻 @desrosj and @youknowriad, thank you for all the help 🙇🏻 |
I reopened this branch and rebased it with the latest changes from I can see the same notice you mentioned in the CI job that runs PHPUnit tests: I will see how we can improve it since it's quite expected because the asset file is generated with a webpack build that doesn't run on CI before unit tests. |
Committing the asset files (and removing from I still think that should be fine as the first step. |
@aristath and @youknowriad – do you think we should some automated handling for the view script? At the moment it's handled manually by the File block in |
Automatically enqueueing the script when the block is rendered would make sense... I don't see why we'd require manually adding it to |
Added in 1791165. If the |
Closed with https://core.trac.wordpress.org/changeset/51501. |
Trac ticket: https://core.trac.wordpress.org/ticket/53690
It aligns with the changes
proposedadded in Gutenberg: WordPress/gutenberg#33293.The idea here is to split the growing webpack config into two parts:
We need to add handling for JavaScript files that are going to be used with blocks on the frontend. They don't work quite well with the current setup for entry points created for packages because of reasons like
wp
globalsIn general, it looks like the split is a good strategy because it nicely separates two independents parts: packages and blocks. There isn't that much overlap between configs anyway.
Add View Script support for block types
As part of the effort, this PR adds support for
viewScript
inblock.json
metadata file that is later translated to$view_script
inWP_Block_Type
class and exposed asview_script
from the REST API endpoint for block types.It would probably be better to have the changes related to the view script in its own ticket, but it's a a bit tricky because we the split for the webpack config into two parts doesn't conceptually make too much sense if the part for blocks don't handle JavaScript files 😅 I'm happy though to split it into two commits if that makes the validation process easier for everyone.
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.