html loader模板,html-loader

html-loader 是一个用于导出 HTML 字符串的 webpack 插件,它可以处理 img 的 src 和其他自定义属性。通过配置 attrs 参数,可以指定哪些标签属性需要处理。通过设置 minimize 参数,可以启用 HTML 压缩。此外,还支持 ES6 模板字符串的插值语法和不同导出格式的配置。
摘要由CSDN通过智能技术生成

html-loader

Exports HTML as string. HTML is minimized when the compiler demands.

安装

npm i -D html-loader

用法

默认情况下,每个本地的 image.png 都需要通过 require (require('./image.png'))来进行加载。你可能需要在配置中为图片指定 loader(推荐 file-loader 或 url-loader )

你可以通过查询参数 attrs,来指定哪个标签属性组合(tag-attribute combination)应该被此 loader 处理。传递数组或以空格分隔的 : 组合的列表。(默认值:attrs=img:src)

If you use , and lots of them make use of a custom-src attribute, you don't have to specify each combination :: just specify an empty tag like attrs=:custom-src and it will match every element.

{

test: /\.(html)$/,

use: {

loader: 'html-loader',

options: {

attrs: [':data-src']

}

}

}

要完全禁用对标签属性的处理(例如,如果你在客户端处理图片加载),你可以传入 attrs=false。

示例

使用此配置:

{

module: {

rules: [

{ test: /\.jpg$/, use: [ "file-loader" ] },

{ test: /\.png$/, use: [ "url-loader?mimetype=image/png" ] }

]

},

output: {

publicPath: "http://cdn.example.com/[hash]/"

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值