webpack_html-loader報錯:'Error: Automatic publicPath is not supported in this browser'


錯誤詳情

在html文件中添加<img>標簽,並寫入src屬性后打包報錯

ERROR in Error: C:\Users\12203\Desktop\webpack-practice\05_打包圖
片資源\src\index .html:97
/******/ if (!scriptUrl) throw new Error("Automatic publicPath is not supported in this browser");
^
Error: Automatic publicPath is not supported in this browser

解決方法

webpack.config.jsoutput寫入屬性publicPath:'./'即可。

一個錯誤的嘗試方法

我試圖將<img>的src屬性的./刪去,但依然報錯。嚴格寫入publicPath即可。

打包后的文件目錄

│  webpack.config.js
│  
├─dist
│  │  bundle.js
│  │  index.html
│  │  
│  └─img
│          2e0f10b356.jpg
│          3fb3b9239a.jpg
│          7cbde3b492.jpg
│          88e40a8cf6.jpeg
│          
└─src
    │  index.html
    │  index.less
    │  main.js
    │  
    ├─img
    │      19300260829801133655476327752_950.jpg
    │      20150228172529_yZALv.jpg
    │      20160607122101_At5zX.jpeg
    │      
    └─img2
        └─images
                12942076507360.jpg

參考鏈接

webpack:url-loader 圖片路徑問題
url-loader處理css中的圖片資源遇到的問題


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM