Load video mp4 webpack loader

Palaniichuk Dmytro picture Palaniichuk Dmytro · Apr 20, 2018 · Viewed 10.3k times · Source

How to use loader for mp4 video format with webpcak 4, I try like this:

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

and import like this

import pressButtonAnimated from './images/pressButtonAnimated.mp4'

But it does not work for me, and I get an error You may need an appropriate loader to handle this file type.

But this one is work for me, but I don wanna add in each file

import pressButtonAnimated from '-!file-loader!./images/pressButtonAnimated.mp4'

Answer

Daniel picture Daniel · Apr 20, 2018

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/