-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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 config into two parts - blocks and packages #33293
Conversation
Size Change: -221 B (0%) Total Size: 1.07 MB
ℹ️ View Unchanged
|
1951805
to
93de573
Compare
93de573
to
a674d33
Compare
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!
filename: ( pathData ) => { | ||
const { chunk } = pathData; | ||
const { entryModule } = chunk; | ||
const { rawRequest, rootModule } = entryModule; | ||
|
||
// When processing ESM files, the requested path | ||
// is defined in `entryModule.rootModule.rawRequest`, instead of | ||
// being present in `entryModule.rawRequest`. | ||
// In the context of frontend view files, they would be processed | ||
// as ESM if they use `import` or `export` within it. | ||
const request = rootModule?.rawRequest || rawRequest; | ||
|
||
if ( request.includes( '/view.js' ) ) { | ||
return `./build/block-library/[name]/view.min.js`; | ||
} | ||
|
||
return `./build/[name]/index.min.js`; | ||
}, | ||
filename: './build/[name]/index.min.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.
Perfect, love to see this super polished. 🎉
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.
Yes, when we have two configs some parts become simpler 😄
It aligns with the changes proposed added in Gutenberg: WordPress/gutenberg#33293. The idea here is to split the growing webpack config into two parts: blocks and packages. We need to add handling for JavaScript files that are going to be used with blocks on the frontend. They didn't work quite well with the current setup for entry points created for packages. As part of the effort, it adds support for `viewScript` in `block.json` metadata file that is later translated to `$view_script` in `WP_Block_Type` class and exposed as `view_script` from the REST API endpoint for block types. Props youknowriad, desrosj, aristath. Fixes #53690. git-svn-id: https://develop.svn.wordpress.org/trunk@51501 602fd350-edb4-49c9-b593-d223f7449a82
It aligns with the changes proposed added in Gutenberg: WordPress/gutenberg#33293. The idea here is to split the growing webpack config into two parts: blocks and packages. We need to add handling for JavaScript files that are going to be used with blocks on the frontend. They didn't work quite well with the current setup for entry points created for packages. As part of the effort, it adds support for `viewScript` in `block.json` metadata file that is later translated to `$view_script` in `WP_Block_Type` class and exposed as `view_script` from the REST API endpoint for block types. Props youknowriad, desrosj, aristath. Fixes #53690. Built from https://develop.svn.wordpress.org/trunk@51501 git-svn-id: http://core.svn.wordpress.org/trunk@51112 1a063a9b-81f0-0310-95a4-ce76da25c4cd
It aligns with the changes proposed added in Gutenberg: WordPress/gutenberg#33293. The idea here is to split the growing webpack config into two parts: blocks and packages. We need to add handling for JavaScript files that are going to be used with blocks on the frontend. They didn't work quite well with the current setup for entry points created for packages. As part of the effort, it adds support for `viewScript` in `block.json` metadata file that is later translated to `$view_script` in `WP_Block_Type` class and exposed as `view_script` from the REST API endpoint for block types. Props youknowriad, desrosj, aristath. Fixes #53690. Built from https://develop.svn.wordpress.org/trunk@51501 git-svn-id: https://core.svn.wordpress.org/trunk@51112 1a063a9b-81f0-0310-95a4-ce76da25c4cd
Description
Follow-up for #33281.
This PR proposes to split webpack config into two subconfigs:
It's similar to what's proposed in WordPress core in WordPress/wordpress-develop#1412. The main benefit is that we can have better control over the output generated for JavaScript files. In particular, for the block-related files, we shouldn't enforce
wp
global to be used. It also slightly decreases the size of files:How has this been tested?
npm run dev
andnpm run build
should work as before.Types of changes
Refactoring
Checklist:
*.native.js
files for terms that need renaming or removal).