Skip to content

Commit

Permalink
Enqueue additional assets via block.json
Browse files Browse the repository at this point in the history
These can't be enqueued via `asset.php`, and `block.json` is a more expected way to enqueue them in a block than `wp_enqueue_*()`.`
  • Loading branch information
iandunn committed Jan 4, 2023
1 parent 4e52686 commit d8e6a9a
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
3 changes: 0 additions & 3 deletions settings/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,6 @@ function render_custom_ui() : void {
return;
}

wp_enqueue_style( 'wp-components' );
wp_enqueue_script( 'zxcvbn-async' ); // Can't be enqueued via asset.php because it doesn't have a `wp-` prefix.

$user_id = bbp_get_displayed_user_id();
$json_attrs = json_encode( [ 'userId' => $user_id ] );

Expand Down
4 changes: 2 additions & 2 deletions settings/src/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"textdomain": "wporg",
"editorScript": "file:./index.js",
"editorStyle": "file:./index.css",
"script": "file:./script.js",
"style": "file:./style-index.css",
"script": [ "file:./script.js", "zxcvbn-async" ],
"style": [ "file:./style-index.css", "wp-components" ],
"render": "file:./render.php"
}
5 changes: 4 additions & 1 deletion settings/src/components/password.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
/**
* External dependencies
*
* window.zxcvbn is also used, but can't be enqueued via an `import` because the handle doesn't have a 'wp-'
* prefix. Instead, it's enqueued via `block.json`. It also can't be declared/destructured here because it's
* loaded asyncronously.
*/
import { pick } from 'lodash';
// window.zxcvbn is also used, but can't be declared here because it's loaded asyncronously.

/**
* WordPress dependencies
Expand Down

0 comments on commit d8e6a9a

Please sign in to comment.