-
Notifications
You must be signed in to change notification settings - Fork 20
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
Refine asset handling to better reflect modern block development #195
Conversation
ESLint Summary View Full Report
[warning] no-console
Report generated by eslint-plus-action |
One of the problems that has not yet been solved is getting HMR of the CSS files to work with this setup. I am currently setting up the entry point based on the @nicholasio do you have any idea how we can get this to work whilst still respecting the filenames of the assets that are getting imported into the JS files? (currently I am not importing them at all) |
77ef172
to
84a61ac
Compare
I think the easiest way to enable HMR of the CSS files would be to create a webpack plugin that would transform the block source file to include something like this: // editorScript
if ( __DEV__ ) {
import('./path-to-source-editor-css-taken-from-block.json');
}
// script
if ( __DEV__ ) {
import('./path-to-source-css-taken-from-block.json');
} |
I had a quick chat with @Antonio-Laguna about this and we wanted to write up some specs for what this webpack plugin would actually need to do. With this change, the webpack entry points for the block-specific assets get automatically registered from the This means that you no longer have to manually go into your This is what we want to fix. I'm not currently familiar enough with how exactly HMR works but at a very high level, we need to make sure that the CSS files get imported to a JS entry point when the watch mode is active. Open Questions:
|
# Conflicts: # package-lock.json # packages/toolkit/package.json
@nicholasio Any idea why the tests started failing after I merged the develop tranch back into this branch? The errors shown in the tests don't seem to be related to the changes I introduced. |
🦋 Changeset detectedLatest commit: 940821a The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
We discussed this PR in out internal 10up-toolkit council call today. We talked about the fact hat given that we are using So we are not actually looking any HMR which unblocks this PR. The next steps are for me @fabiankaegy to rebase this PR and update all the notes @nicholasio had made. Additionally we will be doing some more testing but hopefully this PR should be ready to get merged in the next few weeks :) |
@nicholasio do you have any idea why there are so many changes in the I am using |
@nicholasio @Antonio-Laguna I have just updated this PR to ship the new block asset handling behind a feature flag. After doing some testing it does alter some things in your setup that you need to account for which is why I think we would need to ship this behind a feature flag. My approach would be that after this gets merged I would create a follow-up PR for the 10up wp-scaffold to enable the feature flag so that new projects get this behavior by default. Any other projects that want to use it can feel free to enable it but don't need to and therefore it isn't a breaking change. Would love to hear whether you have any thoughts on that approach or ideas how else this could be solved :) |
@fabiankaegy I think this is good as a feature flag! This way it does not need to be a breaking change. I think it makes sense to document the differences between the flags, what you get/what you don't get so developers can make an informed decision here. I think the lock doesn't get frequently updated, any publishing should update the lock too since changes in internal versions do trigger changes within package-lock.json. I could be wrong and this is already happening but feels odd to get this many changes! |
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.
LGTM.
Made a small change to enable the flag on the test project. Feel free to merge if all looks good to you.
# Conflicts: # package-lock.json
Description of the Change
Refine the asset handling of scripts and styles defined in
block.json
files. For one assets that get defined via thescript
,editorScript
,viewScript
,style
, andeditorStyle
keys in ablock.json
file now get automatically added as entry points. No manual configuration is needed.It also copies the
block.json
file to the dist directory so the file paths can really be relative. Theblock.json
file in thedist
folder is the one that should be registered in WordPress. (a follow-up PR in thewp-scaffold
is required to make this work.)Closes #184 & #130
Alternate Designs
Possible Drawbacks
Verification Process
Checklist:
Changelog Entry
Credits
Props @