I am using Sage 9, I want to put some image links to the JS file, but not sure how to link the assets to “dist” folder.
Because when we run production that all the assets would has the version numbers, I can’t link them normally to the JS.
PHP files I use "@asset('images/example.jpg')" has no problem at all, so someone can explain how to link assets to JS File dynamically?
thanks, but every time run production it gave different version name and I don’t think the JS catch the version name. “location-pin-fallback_1715c510.png” for example.
No, not the config.json.
If you have assets/images/example.png, from your js you can require('../images/example.png'), obviously the path depends on where your js is located, relatively to your scripts folder. webpack will grab the file and pass it on to the file-loader which will automatically return the hashed version of the file.
I don’t quite follow the instructions here. I have a GMaps Marker defined as follows:
var image = {
url: '/wp-content/themes/inspirebcn/dist/images/marker.svg',
size: new google.maps.Size(70, 70),
origin: new google.maps.Point(0, 0),
anchor: new google.maps.Point(70, 70),
};
And in production it’s not linked at all.
So, where should I use the require or import solution?
EDIT: Solved using the following:
import * as markerimage from '../images/marker.svg'; //Top-level of the document
...
var image = {
url: markerimage,
size: new google.maps.Size(70, 70),
origin: new google.maps.Point(0, 0),
anchor: new google.maps.Point(70, 70),
};
Is the “import” way the recommended solution? @ben Shouldn’t this instruction appear in the Book?
Hey, I’ve tried this and it compiles ok but I am getting a 404 for the images in the browser (as they have a URL with ‘assets/images’ as opposed to ‘/dist/images’. The importAll method is attempting to preload them…