Webpack Processing media files (picture/video and audio)

Source: Internet
Author: User

Webpack will eventually package each module into a file, so the URL path in our style is relative to the HTML page of the portal,

This problem is solved with File-loader, File-loader can parse the project URL introduction (not limited to CSS), according to our configuration, the image is copied to the corresponding path, and according to our configuration, modify the package file reference path, so that it points to the correct file.

In addition, if there are more pictures, many HTTP requests will be sent, which will degrade the page performance. This problem can be solved by url-loader. Url-loader will encode the introduced image and generate the Dataurl. Equivalent to translating the image data into a string of characters. Then package this string of characters into a file, and eventually you will need to introduce this file to access the image. Of course, if the picture is large, the encoding consumes performance. So url-loader provides a limit parameter, and a file smaller than the limit byte is converted to Dataurl, and a copy is also used with file-loader greater than limit.

Url-loader There are two types of work : 1. If the file size is less than the limit parameter, Url-loader will convert the file to dataurl;2. The file size is greater than Limit,url-loader will call file-loader for processing, and the parameters will be passed directly to File-loader.

            {                test:/\. (PNG|JPG|GIF|SVG|EOT|TTF|WOFF|WOFF2) $/,                //loader: ' url-loader?name=images/[name].[ EXT] ',                loader: ' Url-loader ',                options: {                  limit:10,                  name: ' imgs/[name].[ EXT] '                }            },            {                test:/\. ( mp3) (\?. *) $/,                loader: ' Url-loader ',                options: {                  name: ' audios/[name].[ EXT] ',                  limit:10                }            }        

  

Webpack Processing media files (picture/video and audio)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.