[英]Font urls path is wrong and includes css path after WebPack Build
[英]Webpack css change image path after build
在開發中,我具有以下結構:
- dist - contain the css bundle
- sass - style.scss
- js
- img
- index.html
在生產中,我具有以下結構:
- img
- some-hash.js
- some-hase.css
- index.html
因此,在開發中,我的圖片網址應與img文件夾相對,如下所示:
background: url('../img/logo.jpg');
但是在生產中應該是這樣的:
background: url('img/logo.jpg');
我們如何使用webpack或一般方式解決此問題?
您需要在webpack配置中包含publicPath。
module.exports = { entry: './main.js', output: { path: './build', // This is where images AND js will go publicPath: 'http://mycdn.com/', // This is used to generate URLs to eg images or publicPath: '/' filename: 'bundle.js' }, module: { loaders: [ { test: /\\.less$/, loader: 'style-loader!css-loader!less-loader' }, // use ! to chain loaders { test: /\\.css$/, loader: 'style-loader!css-loader' }, { test: /\\.(png|jpg)$/, loader: 'url-loader?limit=8192' } // inline base64 URLs for <=8k images, direct URLs for the rest ] } };
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.