WEBPACK+VUECLI Package Build resource relative reference path with correct reference to background picture

Source: Internet
Author: User

Resource relative Reference Path problem description

In general, by webpack+vuecli the default packaging of CSS, JS and other resources, the path is absolute.

However, when deploying to a project with a folder, this absolute path is problematic because the configured static folder is treated as a root path, so to resolve this problem, you have to refer to the relative path.

Solutions

Open itwebpack.prod.conf.js

Find output : add publicPath: ‘./‘ , can,.

Then the reference path to the resource is correct.

Of course, in the Config folder under the assetsPublicPath: ‘./‘ index.js can also be modified to achieve a relative reference to the resource.

Reference issues for background pictures

Although the above solves the resource path reference problem, but the resources inside the background picture, does not like the load resource in the ./static/js/app.js index.html, through the reference can load normally, the picture resource is loaded through the CSS, if the  background: url("../../assets/images/logo-index.png") no-repeat; relative packing becomes the url(static/img/logo-index.2f00bf2.png) no-repeat so we want to keep the normal path of the CSS reference picture, namely:

URL (.. /.. /static/img/logo-index.2f00bf2.png) no-repeat

Then you need to modify the Utils.js code under the build folder:

Add a line of code so that both the font and the picture reference problem can be resolved.

WEBPACK+VUECLI Package Build resource relative reference path with correct reference to background picture

Related Article

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.