ember-cli-resolve-asset
Imperatively resolves assets fingerprinted by
broccoli-asset-rev
, which allows you to even resolve
interpolated paths.
Installation
ember install ember-cli-resolve-asset
If you want to use this in one of your addons, the consuming host application
will also need to install ember-cli-resolve-asset
. If this not a case, a
helpful build error will be shown.
Setup
The following configuration in your ember-cli-build.js
is required for this
addon to work correctly.
const app = defaults fingerprint: enabled: true // If false, this addon is disabled also. generateAssetMap: true // Required. fingerprintAssetMap: true // Recommended to prevent caching issues. 'ember-fetch': preferNative: true // Recommended to enable faster preloading for browsers that support it. ;
Usage
Utils
resolveAsset
async resolveAsset(path: string, withoutPrepend = false): Promise<string>
Asynchronously resolves the given path
from the asset map.
If the asset map is not loaded yet, this function will wait for it.
If loading the asset map fails, the returned Promise
will reject.
If the path is not listed in the asset map, the returned Promise
will reject.
;;;;
resolveAssetSync
resolveAssetSync(path: string, withoutPrepend = false): string
Synchronous version of resolveAsset
.
Synchronously resolves the given path
from the asset map.
If the asset map is not loaded yet, this function will throw. If the path is not listed in the asset map, this function will throw.
Usage of this function is discouraged in favor of resolveAsset
. Only use this
function, if using the async version is not feasible and if you can guarantee,
that load
ran to completion beforehand.
;;;;
load
async load(): Promise<void>
This function returns a Promise
that resolves once the asset map was loaded
successfully. Repeatedly calling this function returns the same Promise
. After
this Promise
has resolved, you can use
resolveAssetSync
.
This function is called automatically by an initializer, to start the loading of the asset map as soon as possible. This means there is no direct need for you to call this function yourself, unless you want to await the asset map explicitly.
Related Projects
broccoli-asset-rev
: The ember-cli addon that performs the fingerprinting and generates the asset map.ember-fetch
: Used by this addon to asynchronously load the asset map.ember-cli-ifa
: The original inspiration for this addon. I was dissatisfied with the technical implementation, the bugs it caused and current state of maintenance, which is why I created this addon instead.