How to reference different sizes in a template
See original GitHub issueResponsive-loader is generating all my images beautifully with the correct names and sizes, but I can’t figure out how to reference other sizes than the default (smallest one) in my template!
// webpack.config file
...
{
test: /\.(jpe?g|png)$/i,
loader: 'responsive-loader',
options: {
adapter: require('responsive-loader/sharp'),
sizes: [600, 1200],
placeholder: true,
placeholderSize: 50,
name: '/assets/img/[hash]-[width].[ext]'
}
},
...
And this is how I’m referencing the images in my template html
<img src="${require('./assets/img/image_0.jpg')}" alt="">
This gives me the 600px wide image and I would like to get different images based on screen size. Any pointers?
Issue Analytics
- State:
- Created 5 years ago
- Comments:6 (1 by maintainers)
Top Results From Across the Web
How does this "size of array" template function work? [duplicate]
Read declarations from inside out, right to left, parenthesis group first: It's an unnamed parameter that is a reference to an array of...
Read more >Change the size of a picture, shape, text box, or WordArt in Word
Select the picture, shape, WordArt, or other object to resize. · Go to Shape Format, Picture Tools Format, or Drawing Tools Format, in...
Read more >How to have different size of font in the Word Template
Configure the word template like below: (i mentioned font size just for your reference. Just select a field and increase the font size...
Read more >grid-template-columns - CSS: Cascading Style Sheets | MDN
The grid-template-columns CSS property defines the line names and track sizing functions of the grid columns.
Read more >docker images - Docker Documentation
The SIZE is the cumulative space taken up by the image and all its parent ... reference (pattern of an image reference) -...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I found the issue (and it cost me many hours so I hope this may help anyone in the same situation). My images were not displayed due to the preceding slash that I put in the responsive-loader configuration (see previous code example). Also I changed the way I implement the loader in the vue-cli setup. This setup has fixed my problem:
So name: ‘assets/img/[hash]-[width].[ext]’ instead of name: ‘/assets/img/[hash]-[width].[ext]’. This is not a vue-cli specific fix so I think it is useful to post back my solution.
For other templates using
html-loader
this can be accomplished by using multiplesource
elements. Here’s a pug example:Multiple
source
elements are required in this case since html-loader won’t transform a single srcset with multiple target resolutions.