[英]Webpack2 - How to require an image from HTML
Webpack claims to manage module dependencies including image files. Webpack声称可以管理模块依赖性,包括图像文件。 I understand that the following webpack config allows me to require
jpg
files from JS/CSS: 我了解以下webpack配置允许我要求JS / CSS中的
jpg
文件:
module.exports = {
module: {
rules: [
{
test: /\.jpg$/,
use: [ 'file-loader' ]
}
]
}
}
using url(/image.png)
or require('./image.png')
, but how would I include an image from an HTML file? 使用
url(/image.png)
或require('./image.png')
,但是如何包含HTML文件中的图像?
<img src="/image.png">
I know I can use copy-webpack-plugin to copy over static files into the output
directory, but I'm wondering if there is a way to require images directly from HTML. 我知道我可以使用copy-webpack-plugin将静态文件复制到
output
目录中,但是我想知道是否有一种方法可以直接从HTML要求图像。
'html-loader' will do this for you by default, however if you are reading this behavior from your main index.html page, you will need to make webpack treat it as module also. 默认情况下,“ html-loader”将为您执行此操作,但是,如果您从index.html主页面读取此行为,则需要使webpack也将其视为模块。 Luckily html-webpack-plugin can do this for you in conjunction with html-loader: html-webpack-plugin .
幸运的是,html-webpack-plugin可以与html-loader: html-webpack-plugin一起为您完成此操作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.