0 follower

Final Class Yiisoft\Assets\Exporter\WebpackAssetExporter

InheritanceYiisoft\Assets\Exporter\WebpackAssetExporter
ImplementsYiisoft\Assets\AssetExporterInterface

Exports the file paths of asset bundles Yiisoft\Assets\AssetBundle::$export, converting them to import '/path/to/file'; expressions and placing them in the specified JavaScript file for later loading into Webpack.

Method Details

Hide inherited methods

__construct() public method

public __construct( string $targetFile ): mixed
$targetFile string

The full path to the target JavaScript file.

                public function __construct(
    private readonly string $targetFile,
) {}

            
export() public method

Exports asset bundle file paths Yiisoft\Assets\AssetBundle::$export.

All dependencies must be created, and path aliases for Yiisoft\Assets\AssetBundle properties are resolved Yiisoft\Assets\AssetUtil::resolvePathAliases(). When using Yiisoft\Assets\AssetManager::export(), all dependencies and path aliases will be automatically resolved.

public export( array $assetBundles ): void
$assetBundles array

The asset bundle instances.

throws RuntimeException

If an error occurred while writing to the JavaScript file.

                public function export(array $assetBundles): void
{
    $imports = '';
    foreach (AssetUtil::extractFilePathsForExport($assetBundles) as $file) {
        $imports .= "import '{$file}';\n";
    }
    AssetUtil::exportToFile($this->targetFile, $imports);
}