How to load image files with webpack file-loader

后端 未结 6 1924
[愿得一人]
[愿得一人] 2020-11-27 09:13

I am using webpack to manage a reactjs project. I want to load images in javascript by webpack file-loader. Below is the

6条回答
  •  遥遥无期
    2020-11-27 10:03

    Alternatively you can write the same like

    {
        test: /\.(svg|png|jpg|jpeg|gif)$/,
        include: 'path of input image directory',
        use: {
            loader: 'file-loader',
            options: {
                name: '[path][name].[ext]',
                outputPath: 'path of output image directory'
            }
        }
    }
    

    and then use simple import

    import varName from 'relative path';

    and in jsx write like

    .... are for other image attributes

提交回复
热议问题