I have a bunch of images that are not referenced in any css files, hence don't go through the optimization pipeline. Is there a way to trigger image optimization on them (svgo, mozjpeg etc.)?
---img
------image1.jpeg // referenced in css
------image2.svg // referenced in css
------image3.png // not referenced in css
---scss
------app.scss
---js
------app.js
dist
---img
------image1.jpeg
------image2.svg
app.css
app.js
Also have this question.
Use relative paths for your images, then the respective loaders will take care of them.
@panda-madness I do this by running a custom function.
You can import images not referenced in css like this:
In your resources/assets/js/app.js:
// import all the images in [resources/assets/images], including subdirectories
require.context('../../images', true, /\.(png|jpe?g|gif)$/);
Now webpack will process all images through file-loeader and img-loader.
Note: I'm not including
svgin the regex because currently laravel mix stores them in thefontsdirectory.
Most helpful comment
You can import images not referenced in css like this:
In your resources/assets/js/app.js:
Now webpack will process all images through
file-loeaderandimg-loader.