Final Class Yiisoft\Assets\Exporter\WebpackAssetExporter
| Inheritance | Yiisoft\Assets\Exporter\WebpackAssetExporter |
|---|---|
| Implements | Yiisoft\Assets\AssetExporterInterface |
Exports the file paths of asset bundles {@see AssetBundle::$export}, converting them to import '/path/to/file';
expressions and placing them in the specified JavaScript file for later loading into Webpack.
Public Methods
| Method | Description | Defined By |
|---|---|---|
| __construct() | Yiisoft\Assets\Exporter\WebpackAssetExporter | |
| export() | Exports asset bundle file paths {@see AssetBundle::$export}. | Yiisoft\Assets\Exporter\WebpackAssetExporter |
Method Details
| public mixed __construct ( string $targetFile ) | ||
| $targetFile | string |
The full path to the target JavaScript file. |
public function __construct(
private readonly string $targetFile,
) {
}
Exports asset bundle file paths {@see AssetBundle::$export}.
All dependencies must be created, and path aliases for {@see \Yiisoft\Assets\AssetBundle} properties are resolved {@see \Yiisoft\Assets\AssetUtil::resolvePathAliases()}. When using {@see \Yiisoft\Assets\AssetManager::export()}, all dependencies and path aliases will be automatically resolved.
| public void export ( array $assetBundles ) | ||
| $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);
}
Signup or Login in order to comment.