Assets are files that are not processed by Webpack. They are copied directly to the output folder. This includes images, fonts, and any other files that you want to use in your project.
To use an asset, you need to import it from JavaScript or CSS.
file: ./resources/views/layout/main.php
<?php
declare(strict_types=1);
use Yii\Assets\SweetAlert2Dev;
/**
* @var \Yiisoft\Assets\AssetManager $assetManager
*/
// Register the asset bundle with a asset manager component.
$assetManager->register(SweetAlert2Dev::class);
// Set parameters for the registered asset bundle a view component.
$this->addCssFiles($assetManager->getCssFiles());
$this->addCssStrings($assetManager->getCssStrings());
$this->addJsFiles($assetManager->getJsFiles());
$this->addJsStrings($assetManager->getJsStrings());
$this->addJsVars($assetManager->getJsVars());
Alternatively, you can register the asset bundle through the container configuration.
file: ./config/params.php
<?php
declare(strict_types=1);
use Yii\Assets\SweetAlert2Cdn;
return [
'yiisoft/assets' => [
'assetManager' => [
'register' => [
SweetAlert2Cdn::class,
],
],
],
];
You can install npm packages fxpio/foxy,
and they will be available in the node_modules
directory.