Repository navigation
2.11.0
WebpackManifestLoader now supports ScriptModule
This release will now support Inpsyde\Asset\ScriptModule through a manifest.json file and the Inpsyde\Assets\Loader\WebpackManifestLoader. The Loader will automatically detect files ending with .mjs or .module.js and create a ScriptModule instance out of them. Additionally, we added support for @vendor/ in handles coming from manifest.json files.
Extending Assets
The second addition in this release is the support of "extending Assets", which are loaded through various resources. In most cases, when using Inpsyde\Assets\Loader\WebpackManifestLoader, we're very limited in extending the created Assets with additional data.
manifest.json
{
"script-handle": "/public/path/script.23dafsf2138d.js",
"style-handle": "style.23dafsf2138d.css"
}Before:
<?php
use Inpsyde\Assets\AssetManager;
use Inpsyde\Assets\Script;
use Inpsyde\Assets\ScriptModule;
use Inpsyde\Assets\Style;
use Inpsyde\Assets\Loader\WebpackManifestLoader;
add_action(
AssetManager::ACTION_SETUP,
function(AssetManager $assetManager) {
$loader = new WebpackManifestLoader();
/** @var \Inpsyde\Assets\Asset[] $assets */
$assets = $loader->load('manifest.json');
foreach($assets as $key => $asset) {
if($asset->handle() === 'script.js' && $asset instance of Script::class){
$asset->canEnqueue(static fn(): bool => is_user_logged_in());
$asset->isInFooter();
$assets[$key] = $asset;
continue;
}
if($asset->handle() === 'style.js' && $asset instance of Style::class){
$asset->canEnqueue(false);
$asset->withInlineStyles(['before' => ':root { --black: #000; }']);
$assets[$key] = $asset;
continue;
}
}
$assetManager->register(...$assets);
}
);After:
<?php
use Inpsyde\Assets\AssetManager;
use Inpsyde\Assets\Script;
use Inpsyde\Assets\ScriptModule;
use Inpsyde\Assets\Style;
use Inpsyde\Assets\Loader\WebpackManifestLoader;
add_action(
AssetManager::ACTION_SETUP,
function(AssetManager $assetManager) {
$assetManager->extendAsset(
Style::class,
'style.css',
[
'inline' => ['before' => ':root { --black: #000; }']
'enqueue' => false,
]
);
$assetManager->extendAsset(
Script::class,
'script.js',
[
'enqueue' => static fn(): bool => is_user_logged_in(),
'inFooter' => true,
]
);
$loader = new WebpackManifestLoader();
/** @var \Inpsyde\Assets\Asset[] $assets */
$assets = $loader->load('manifest.json');
$assetManager->register(...$assets);
}
);The AssetManager::extendAsset() method will now automatically extend a registered Asset before it is processed.
What's Changed
- New "extend asset" feature by @Chrico in #63
- Improves consistency with extendAsset() by @Chrico in #64
- WebPack Loader Script Modules Support by @widoz in #62
Full Changelog: 2.10.0...2.11.0