-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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: Introduce the common build
folder to be used by all modules
#6584
Conversation
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.
Seems like a good improvement to me, I wonder why we didn't do this in the first place. Any idea @aduth ?
I'm not sure how it aligns with the plan to expose Gutenberg modules to npm to make it possible to use them with other projects. In particular, the changes I proposed to have one build folder, might not work well in the scenario where we want to publish every such module separately to npm. It all depends which direction we are going to pick - continue to move all modules to |
Related: #6087 (cc @kanishkdudeja) |
I don't have a strong opinion one way or the other, but yes, a build folder in each is in line with treating them as independent modules. |
It looks like a similar approach to what @kanishkdudeja did. It might be also the case that there should be a different version of build files exposed for Gutenberg than for npm modules. For example we will have to expose source files for RN because web ignores ‘*.native.js’ overrides. |
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.
I think it's an nice devx improvement for now. Let's reconsider once we tackle publishing packages as npm dependencies later, as not certain how that would work (packages repository or this one)
} ).then( function() { | ||
return wp.editPost.initializeEditor( 'editor', window._wpGutenbergPost, editorSettings ); | ||
wp.api.init().then( function() { | ||
wp.domReady.default( function() { |
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.
Why are we calling default
? Is this an ES2015 module issue ? This should be called on as wp.domReady( fn );
. Seems like a bug.
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.
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.
I dug into this a bit, and it's trickier than it appears on the surface.
This is what Webpack's output.libraryExport
configuration is meant to support: Setting a specific property as the value assigned on the library target (window
).
However, we have mixed needs: For something like wp.editor
or wp.i18n
, we want named exports to be respected, and assigned as nested properties within. For dom-ready
though, the default export function should be assigned as wp.domReady
.
In my head, it's as though we want libraryExport: 'default'
when there are no other named exports, otherwise using the default _entry_return_
.
So far as implementation, we might need to get our hands dirty with a custom Webpack plugin to achieve this. It probably needs to extend (whether via classical inheritance or just dynamically instantiating during apply
, I'm uncertain) Webpack's ExportPropertyMainTemplatePlugin.js
. Where I started having trouble was determining the exports of a module to decide what to assign as libraryExport
.
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.
Alternative: have separate output
configurations for specific edge-case modules like dom-ready
, where we can assign libraryExport: 'default'
. This too is not made very simple in an all-in-one Webpack configuration like we have.
Alternative alternative: Don't allow default
exports on packages.
Alternative alternative alternative: Use CommonJS module.exports
instead of export default
from the packages
implementation.
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.
Alternative Alternative Alternative, assign the globals manually in "enqueues" importing things from the regular built modules :)
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.
Moving task to #6748 for further discussion.
Description
This PR changes the way we manage
build
folders. Instead of having a subfolder for each module, the changes proposed cause to have one commonbuild
folder. It should make it easier to reason which folders contain the source code and which are external ones. This will also make easier to excludebuild
folders from search results in your IDEs.As part of this PR I also extracted
a11y
anddom-ready
to be served as external packages. This allowed to movedomReady
call fromeditPost
module toclient-assets.php
file as suggested by @aduth in #6448 (comment):Having
dom-ready
anda11y
extracted was also discussed in #6526 (comment):How has this been tested?
Manually made sure there are no regressions.
All commands should work as before, in particular, the following must be double checked:
npm test
npm run build
npm run dev
npm run package-plugin
Screenshots
Types of changes
Checklist: