Asset reference in javascript

The Ember CLI manual describes how assets can be referenced in templates and CSS, but what is the correct way to reference an asset (say, an image) from my javascript code?

In particular, I am concerned that the asset path was correctly fingerprinted when creating assets for production. It seems that ember-cli uses broccoli-asset-rev for this, but according to it, the <script> tags in HTML and url() in CSS will be printed. Is there a way (possibly through another broccoli plugin) to get asset paths in fingerprinted .js files?

+5
source share
2 answers

I found a problem. This works out of the box, as expected - it turned out that my asset (image) was not in the right place, so the appearance of its path in JS files was never replaced by a version with fingerprints.

+1
source

I placed the image under car.jpeg under public/assets/images and then was able to reference it in my application.js route file as assets/images/car.jpeg

enter image description here

Works great

enter image description here

UPDATE

One photo is worth a thousand words ... :)

enter image description here

+3
source

Source: https://habr.com/ru/post/1213505/


All Articles