webpackwebpack-file-loader

webpack file-loader load all files in a folder


I have a bunch of images in a folder and webpack file-loader loads only those referenced inside the html or css files. thats's fine. But I want all the images in the folder to be loaded in the final dist/images folder as well, wheter they are addressed inside html or not.

The point is I want to load them by user click one after another

Thanksssssssss


Solution

  • You can force Webpack to require every asset from a certain folder.

    Put following code inside the entry point of your application:

    // load assets
    function requireAll(r) { r.keys().forEach(r); }
    requireAll(require.context('images/', true));