-
Notifications
You must be signed in to change notification settings - Fork 4
Open
Labels
documentationContains notes which should be added to public-facing documentationContains notes which should be added to public-facing documentation
Description
When switching from using wp_enqueue_script()
and co to using this package's autoenqueue()
, the difference in the function interfaces is a little jarring. I'd like to recommend the addition of two helper functions which:
- Use signatures a little more familiar to WordPress developers in order to make the transition easier
- Remove the need to specify an asset manifest path which is IMO an implementation detail
- Get around Support CSS-only entrypoints. #1 by silently rewriting a
.css
path to.js
(which is working for theme stylesheets on the SW project)
function register_asset( string $handle, string $file, array $options = [] ) :? array {
$file = str_replace( '.css', '.js', $file );
$manifest = dirname( $file ) . '/build/asset-manifest.json';
$options['handle'] = $handle;
return autoregister( $manifest, basename( $file ), $options );
}
function enqueue_asset( string $handle, string $file, array $options = [] ) : void {
$file = str_replace( '.css', '.js', $file );
$manifest = dirname( $file ) . '/build/asset-manifest.json';
$options['handle'] = $handle;
autoenqueue( $manifest, basename( $file ), $options );
}
Usage looks like:
enqueue_asset(
'theme-style',
get_stylesheet_directory(). '/style.css',
[
'styles' => [ 'dashicons' ],
]
);
Thoughts? I can work on a PR if we agree these would be useful additions.
svandragt
Metadata
Metadata
Assignees
Labels
documentationContains notes which should be added to public-facing documentationContains notes which should be added to public-facing documentation