Package Exports
- ember-cli-resolve-asset
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (ember-cli-resolve-asset) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
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-assetSetup
The following configuration in your ember-cli-build.js is required for this
addon to work correctly.
const app = new EmberAddon(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
Example
import Route from '@ember/routing/route';
import { inject as service } from '@ember-decorators/service';
import fetch from 'fetch';
import resolveAsset from 'ember-cli-resolve-asset';
export default class ApplicationRoute extends Route {
@service intl;
@service language;
async beforeModel() {
const preferredLanguage = this.language.getPreferredLanguage();
const translationsPath = await resolveAsset(
`translations/${preferredLanguage}.json`
);
const translations = await fetch(translationsPath);
this.intl.addTranslations(preferredLanguage, await translations.json());
this.intl.setLocale(preferredLanguage);
}
}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.