-
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
Script Modules: Centralize (re)registration #65460
Changes from all commits
487a982
11c63fe
44dd78f
508cbba
00a196b
a148c74
5015d56
b0b3e72
370f2e6
1bad15c
cb3a31b
476183a
3f457a5
6759367
ff352fc
23bff87
b8e11bc
8386d14
44da0b0
e99b96e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
https://github.com/WordPress/wordpress-develop/pull/7360 | ||
|
||
* https://github.com/WordPress/gutenberg/pull/65460 |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,18 +19,7 @@ | |
function render_block_core_file( $attributes, $content ) { | ||
// If it's interactive, enqueue the script module and add the directives. | ||
if ( ! empty( $attributes['displayPreview'] ) ) { | ||
$suffix = wp_scripts_get_suffix(); | ||
if ( defined( 'IS_GUTENBERG_PLUGIN' ) && IS_GUTENBERG_PLUGIN ) { | ||
$module_url = gutenberg_url( '/build-module/block-library/file/view.min.js' ); | ||
} | ||
|
||
wp_register_script_module( | ||
'@wordpress/block-library/file', | ||
isset( $module_url ) ? $module_url : includes_url( "blocks/file/view{$suffix}.js" ), | ||
array( '@wordpress/interactivity' ), | ||
defined( 'GUTENBERG_VERSION' ) ? GUTENBERG_VERSION : get_bloginfo( 'version' ) | ||
); | ||
wp_enqueue_script_module( '@wordpress/block-library/file' ); | ||
wp_enqueue_script_module( '@wordpress/block-library/file/view' ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Brilliant! |
||
|
||
$processor = new WP_HTML_Tag_Processor( $content ); | ||
$processor->next_tag(); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -89,11 +89,11 @@ module.exports = { | |
}, | ||
output: { | ||
devtoolNamespace: 'wp', | ||
filename: './build-module/[name].min.js', | ||
filename: '[name].min.js', | ||
library: { | ||
type: 'module', | ||
}, | ||
path: join( __dirname, '..', '..' ), | ||
path: join( __dirname, '..', '..', 'build-module' ), | ||
environment: { module: true }, | ||
module: true, | ||
chunkFormat: 'module', | ||
|
@@ -102,7 +102,13 @@ module.exports = { | |
resolve: { | ||
extensions: [ '.js', '.ts', '.tsx' ], | ||
}, | ||
plugins: [ ...plugins, new DependencyExtractionWebpackPlugin() ], | ||
plugins: [ | ||
...plugins, | ||
new DependencyExtractionWebpackPlugin( { | ||
combineAssets: true, | ||
combinedOutputFile: `./assets.php`, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Huge perf win! It will pay off over time. 👏 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was trying to remember why there are two versions in WP core: All good here. I figured out that in WP core, there are two parallel build processes - one for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
} ), | ||
], | ||
watchOptions: { | ||
ignored: [ '**/node_modules' ], | ||
aggregateTimeout: 500, | ||
|
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 is a slight change that needs to get incorporated here. There should be a different file served depending on
SCRIPT_DEBUG
:true
:.js
false
:.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.
I'm not that sure anymore after looking at how scripts for packages are handled:
gutenberg/lib/client-assets.php
Lines 190 to 238 in 5e37a13
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.
👍 Done.
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 didn't have the latest version of the branch 🙈
This is what I see now with
npm run dev
:I still do not think I understand it fully.
.min.js
is always produced when you usenpm run dev
andnpm run build
.mode === 'production' && new ReadableJsAssetsWebpackPlugin(),
means that.js
gets only generated for production builds -npm run build
. From the docs of the webpack plugin:I'm still puzzled why there is no
SCRIPT_DEBUG
involved like in WP core.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 we can remove 44da0b0 for now and ship it all as is.
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 folder after
npm run build
:Notice
.js
and.min.js
files get created. Fornpm run dev
I see only.min.js
files 🤷🏻 In effect, it behaves like in debug mode. However, once the plugin gets released, there is no longer a way to use the debug version. In fact, it probably doesn't make too much sense, because.js
file is built with production mode.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, it's confusing. When doing a development build,
.min.js
files are produced but they're not minified. The SCRIPT_DEBUG doesn't change the files Gutenberg uses.I've reverted the
.min.js
/.js
changes.