Home > Web Front-end > JS Tutorial > body text

Solve the problem of resource files not being found after css referenced images are packaged in vue+webpack

亚连
Release: 2018-06-01 10:13:42
Original
2889 people have browsed it

Now I will share with you an article about how vue webpack solves the problem of not being able to find resource files after css referenced images are packaged. It has a good reference value and I hope it will be helpful to everyone.

Use vue to package and reference image resources through css.

.img { 
  height: 500px; 
  width: 100%; 
  background: url("./assets/img/1.jpg") no-repeat; 
  background-size: 100%; 
 }
Copy after login

The effect of hot updating the development environment is like this

But the page after packaging is An error that the resource cannot be found is reported.

After checking the reason, style-loader could not set its own publicPath after the css introduced the image and then packaged it, so I changed the css path publicPath of ExtractTextPlugin.

if (options.extract) { 
   return ExtractTextPlugin.extract({ 
    use: loaders, 
    // css 引用图片打包问题 
    publicPath: '../../../', 
    fallback: 'vue-style-loader' 
   }) 
  } else { 
   return ['vue-style-loader'].concat(loaders) 
  }
Copy after login

After building once, no error was reported and the display was normal!

The above is what I compiled for everyone. I hope it will be helpful to everyone in the future.

Related articles:

Solve the problem of Vue modifying the array through the following table and the page not rendering

Vue.js implementation How to drag pictures randomly

Solve the problem that Vue modifies the array through the following table and the page does not render

The above is the detailed content of Solve the problem of resource files not being found after css referenced images are packaged in vue+webpack. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
web
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!