Is your enhancement related to a problem? Please describe.
It's always a struggle manual having to manage the different dependencies a js file needs. (eg. wp-components, wp-hooks etc.) Just having them auto generate the same way the @wordpress/scripts package does it would be very cool. Also the generated version would improve the workflow a bunch not having to clear cashes all the time.
Describe the solution you'd like
Implementing something like the @wordpress/scripts package would be really cool.
Using the impost syntax
import { Button } from '@wordpress/scripts that then automatically generated a PHP file that has the array for all the dependencies in it.
The generated PHP file would live inside the build folder and would look something like this
return array(
'dependencies' => array(
'wp-block-editor',
'wp-blocks',
'wp-components',
'wp-element',
'wp-polyfill'
),
'version' => 'f76a969d50f965d0c766b177874f89cc'
);
This would then allow us to do the following when actually enqueueing:
$dir = dirname( __FILE__ );
$script_asset_path = "$dir/build/index.asset.php";
$script_asset = include $script_asset_path;
wp_register_script(
'handle_name',
plugins_url( '/build/index.js', __FILE__ ),
$script_asset['dependencies'],
$script_asset['version'],
false
);