It tries to match images with the srcset-loader if it can find any sizes/placeholder options; or use directly the file-loader if no parameter has been found.
Although this setup works well with static requirement paths, I can't make it work with dynamic paths, while the standalonefile-loader works fine in the same conditions:
require('./assets/image.jpeg'); // works (returns image url)
require('./assets/image.jpeg?sizes=default+10w'); // works (return Object with srcset properties...)
const filename = 'image.jpeg';
require(`./assets/${filename}`); // works (as before, returns image url)
require(`./assets/${filename}?sizes=default+10w`); // does not work ?! (Error: Cannot find module at webpackMissingModule...)
I can't manage to make
srcset-loader
work when I have both dynamic paths and loader options.Here is the
webpack.config.js
section corresponding to the image rules:It tries to match images with the
srcset-loader
if it can find anysizes/placeholder
options; or use directly thefile-loader
if no parameter has been found.Although this setup works well with static requirement paths, I can't make it work with dynamic paths, while the standalone
file-loader
works fine in the same conditions: