Adds assets from a Vite manifest to the Wordpress head
composer require idleberg/wordpress-vite-assets
To get you going, first instantiate the class exposed by this library
Usage: new WordpressViteAssets(string $manifestPath, string $baseUri, string $algorithm = "sha256")
Example
// functions.php
use Idleberg\WordpressViteAssets\WordpressViteAssets;
$baseUrl = get_stylesheet_directory();
$manifest = "path/to/manifest.json";
$entryPoint = "index.ts";
$viteAssets = new WordpressViteAssets($manifest, $baseUrl);
$viteAssets->addAction($entryPoint);
Usage: addAction(array|string $entrypoints, array|int $priority = 0)
Writes tags for entries specified in the manifest to the page header
- script entrypoint
- preloads for imported scripts
- style tags
The priority argument allows granular control when provided as an array
Example
$priorities = [
"scripts" => 10,
"preloads" => 0,
"styles" => 20
];
$viteAssets->addAction($entrypoints, $priorities);
Usage: getScriptTag(string $entrypoint, bool $options)
Returns the script tag for an entry in the manifest
Usage: getStyleTags(string $entrypoint)
Returns the style tags for an entry in the manifest
Usage: getPreloadTags(string $entrypoint)
Returns the preload tags for an entry in the manifest
Toggles crossorigin
attribute on script and style tags. Can be boolean
, "anonymous"
or "use-credentials"
Toggles integrity
attribute on script and style tags
This work is licensed under The MIT License