Using PHP Code to Generate Asset URLs in Magento 2
The short version – inject a MagentoFrameworkViewAssetRepository
, use $repository->createAsset('Vendor_Module::path/to/file.js')
to create an asset object, use the getUrl
method on that created asset object.