From 0 to on-line development Enterprise E-Commerce Project _ front-end _11_webpack to Icon-font and image processing

Source: Internet
Author: User
Tags base64

In the previous article we have completed the Webpack for scripting, CSS, HTML processing.

By reading this article, you can solve the following issues:

    • Webpack How to handle pictures
    • Webpack How to handle font files

First, webpack processing picture url-loader1. Url-loader Installation

In fact, the processing of fonts and pictures, using a url-loader can be.

Install loader first

NPM Install Url-loader–save-dev

Show the installation is successful, there is no need to look for a package here, so ignore warn, that is to tell you that NPM 3 will not install the dependent package.

2.url-loader Configuration

Using Url-loader in the configuration file, add Url-loader after css-loader in module:

module: {    loaders: [        {            /\.css$/,            loader:ExtractTextPlugin.extract (" Style-loader ",            " Css-loader ")        },        {            /\. ( gif|png|jpg) \??. *$/,            loader: ' URL-loader '        }

Modify SRC-page->index->index.css casually introduce a picture.

body{    Background:url ('.. /.. /image/test-image.jpg ');}

After executing webpack we see the results of the execution

The picture is introduced, but the display is in base64 format, then we make it display the name of the picture, by configuring the parameters of the Url-loader can realize this function. Modify the configuration of the previous Url-loader

{    /\.( gif|png|jpg) \??. *$/,    -loader? limit = & name = resource/ [name]. [ext] '}

Parameter description:

limit: show the size of the file, less than this value will be packaged into the base64 you just saw the format, and larger than the value of the word will be packaged in the form of a file,

&name=resource: And put it in resouce

[name]. [Ext] : The name + extension of the file, so that the extension does not change when packaged.

Second, the webpack to the font processing

As mentioned earlier, Webpack on fonts and pictures are handled using the url-loader we just had,

In fact, the processing of fonts as long as a few font format can be. Plus Woff|svg|eot|ttf:

{    /\.( GIF|PNG|JPG|WOFF|SVG|EOT|TTF) \??. *$/,    -loader? limit = & name = resource/ [name]. [ext] '}

Iii. references

1.webpack processing of Icon-font and pictures

From 0 to on-line development Enterprise E-Commerce Project _ front-end _11_webpack to Icon-font and image processing

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.