-
featured-video-toggle.src.js
is the custom component (namedFeaturedVideoToggle
) created similar to the originalPostFeaturedImage
component. -
index.src.js
is the file which "imports" the customFeaturedVideoToggle
component. -
index.build.js
is the build version of the files #1 and #2 above. It was generated bywp-scripts
after running thenpm run build
command. -
index.asset.php
is also generated by thewp-scripts
(version 5+ only).
And note that, in my plugin or actual code, I don't have the .src
or .build
in the file name. My plugin structure:
my-plugin/
build/
index.js
index.asset.php
src/
index.js
featured-video-toggle.js
index.php
And in index.php
, here's how I enqueue the my-plugin/build/index.js
file:
add_action( 'enqueue_block_assets', function () {
$asset_file = include( plugin_dir_path( __FILE__ ) . 'build/index.asset.php' );
wp_enqueue_script( 'my-guten', plugin_dir_url( __FILE__ ) . 'build/index.js',
$asset_file['dependencies'], $asset_file['version'] );
} );
And that's how it should be done — don't enqueue the source files — they may be small-sized, but browsers don't understand the JSX syntax without a compiler, and the thing is, compilers are "heavy" and can make your site slow.
Anyway, I hope the code/source helps. Cheers!