Load video mp4 webpack loader

The way how you declare your loader is not right. You are mixing two ways to define loaders.

 {
        test: /\.mp4$/,
        use: 'file-loader?name=videos/[name].[ext]',
 },

Could you try this please.

Link: https://webpack.js.org/concepts/loaders/


with Webpack5, the attributes property has been replaced with sources

We can use file-loader like this so we can give it the option name and path.

{
    test: /\.mp4$/,
    use: [
        {
            loader: "file-loader",
            options: {
                name: "[name].[ext]",
                outputPath: "video"
            }
        }
    ]
}

also for some reason if you write a video tag in your html

<video class="">
    <source src="video/video.mp4" type="video/mp4">
</video>

It doesn't load in webpack but we can use html-loader as follow

{
    test: /\.html$/,
    exclude: /node_modules/,
    use: [
        {
            loader: "html-loader",
            options: {
                sources: {
                    list: [
                        {
                            tag: "source",
                            attribute: "src",
                            type: "src"
                        }
                    ]
                }
            }
        }
    ]
}

also we can use url-loader but it only load the images and videos added through css.

PS: if you found a solution for html tags with src attribute to use it with file-loader it would be great.