Webpack, CSS Packaging background map, path error

Source: Internet
Author: User

Css-loader:

 //  packaging style in background map   {test: /\. (png|jpg) $/  " url-loader?limit=8192&name=images/[hash:8". [Name]. [Ext]                  " // limit parameter, which means that if less than approximately 4k will automatically compress you into a base64 encoded picture, otherwise copy the file to the production directory  // name followed by a packaged path;  // loader after the Limit field represents the picture packaging restrictions, this limit does not mean that more than can not be packaged, but that when the picture size is less than the limit will automatically turn to Base64 code reference //             },

When less than 8192, packaging into Base64, then, greater than the treatment;

Scenario: My background in main.css:

. PAGE4-BG {  background:URL (".. /images/page4-bg.jpg ") No-repeat center;   background-size:cover;}

Result: The picture is under the Dist/images/folder when packaged, but the console is:

The picture was not found, so I went to view the path:

Looks like the picture is loaded in, as if there is no problem, and then the image address of the mouse right-click---Open in the new tab, the result

and the directory address of my file picture is

This way, removing the CSS from the path will show the image.

Solution:

            //package style in the background map{test:/\. (png|jpg) $/, Loader:[Url-loader?limit=8192&name=images/[hash:8]. [Name]. [Ext] ", options:{Publicpath:'./images '                }                //The limit parameter, which means that if less than about 4k will automatically compress you into a base64 encoded picture, otherwise copy the file to the production directory                //name is followed by the packaged path;                //the Limit field behind the loader represents the picture packing limit, which does not mean that it cannot be packaged, but that it automatically turns into a base64 code reference when the image size is less than the limit .                //images larger than 8192 bytes in the above example are packaged properly, and images smaller than 8192 bytes are referenced in base64 manner. },

Add Publicpath.

The question bothered me one day and finally found the way in the afternoon of the next day.

Webpack, CSS Packaging background map, path error

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.