
Security News
Axios Supply Chain Attack Reaches OpenAI macOS Signing Pipeline, Forces Certificate Rotation
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.
html-withhook-loader
Advanced tools
Enhanced HTML loader with Hooks support for webpack.
npm install --save-dev html-withhook-loader
module.exports = {
module: {
rules: [
{
test: /\.html$/i,
loader: "html-withhook-loader",
},
],
},
};
sources.tags类型:
type TagHandler = (
params: {
value: string;
startOffset: number;
endOffset: number;
resourcePath: string;
},
sources: Array<Source>,
) => boolean | void;
type tags = {
[tagName: string]: TagHandler;
};
允许为特定标签注册处理器:
module.exports = {
module: {
rules: [
{
test: /\.html$/i,
loader: "html-withhook-loader",
options: {
sources: {
tags: {
// 处理 img 标签
img: (params, sources) => {
sources.push({
name: "data-src",
value: params.value,
isValueQuoted: false,
startOffset: params.startOffset,
endOffset: params.endOffset,
});
return true; // 返回 true 表示处理完成,阻断后续处理
},
},
},
},
},
],
},
};
sources.attributes类型:
type AttributeHandler = (
params: {
tagName: string;
value: string;
startOffset: number;
endOffset: number;
resourcePath: string;
},
sources: Array<Source>,
) => boolean | void;
type attributes = {
[attributeName: string]: AttributeHandler;
};
允许为特定属性注册处理器:
module.exports = {
module: {
rules: [
{
test: /\.html$/i,
loader: "html-withhook-loader",
options: {
sources: {
attributes: {
// 处理 src 属性
src: (params, sources) => {
if (params.tagName === "img") {
sources.push({
name: "data-src",
value: params.value,
isValueQuoted: true,
startOffset: params.startOffset,
endOffset: params.endOffset,
});
return true; //返回 true 表示处理完成,阻断后续处理
}
},
},
},
},
},
],
},
};
module.exports = {
module: {
rules: [
{
test: /\.html$/i,
loader: "html-withhook-loader",
options: {
sources: {
tags: {
img: (params, sources) => {
// 将 src 转换为 data-src
sources.push({
name: "data-src",
value: params.value,
isValueQuoted: true,
startOffset: params.startOffset,
endOffset: params.endOffset,
});
return true;
},
},
},
},
},
],
},
};
module.exports = {
module: {
rules: [
{
test: /\.html$/i,
loader: "html-withhook-loader",
options: {
sources: {
attributes: {
"custom-src": (params, sources) => {
sources.push({
name: "src",
value: `/assets/${params.value}`,
isValueQuoted: true,
startOffset: params.startOffset,
endOffset: params.endOffset,
});
return true;
},
},
},
},
},
],
},
};
Hook 执行过程中的错误会被收集并通过 webpack 的错误系统报告。每个错误都包含:
html-withhook-loader 完全兼容原版 html-loader 的所有功能,包括:
详细说明请参考原版 html-loader 文档。
MIT
FAQs
Enhanced html-withhook-loader with tag/attribute hooks support
The npm package html-withhook-loader receives a total of 1 weekly downloads. As such, html-withhook-loader popularity was classified as not popular.
We found that html-withhook-loader demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.

Security News
Open source is under attack because of how much value it creates. It has been the foundation of every major software innovation for the last three decades. This is not the time to walk away from it.

Security News
Socket CEO Feross Aboukhadijeh breaks down how North Korea hijacked Axios and what it means for the future of software supply chain security.