Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,51 @@ module.exports = {
};
```

If the tag name is not specified or assigned to the wild card `'*'` it will process all the tags.

> You can use your custom filter to specify html elements to be processed.

For example:

**webpack.config.js**

```js
module.exports = {
module: {
rules: [
{
test: /\.html$/i,
loader: 'html-loader',
options: {
attributes: {
list: [
{
// Tag name
tag: '*', // or tag: ''
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to support tag: '*', if you don't provide tag try to use on all attributes, i.e tag can be string or undefined (not specify)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will work now when the string is empty or it's undefined

// Attribute name
attribute: 'src',
// Type of processing, can be `src` or `scrset`
type: 'src',
// Allow to filter some attributes (optional)
filter: (tag, attribute, attributes, resourcePath) => {
// The `tag` argument contains a name of the HTML tag.
// The `attribute` argument contains a name of the HTML attribute.
// The `attributes` argument contains all attributes of the tag.
// The `resourcePath` argument contains a path to the loaded HTML file.

// choose all HTML tags except img tag
return tag.toLowerCase() !== 'img';
},
},
],
},
},
},
],
},
};
```

#### `urlFilter`

Type: `Function`
Expand Down
5 changes: 2 additions & 3 deletions src/options.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
"type": "object",
"properties": {
"tag": {
"type": "string",
"minLength": 1
"type": "string"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to return it to minLength to 1

},
"attribute": {
"type": "string",
Expand All @@ -19,7 +18,7 @@
"instanceof": "Function"
}
},
"required": ["tag", "attribute", "type"],
"required": ["attribute", "type"],
"additionalProperties": false
},
"AttributeList": {
Expand Down
9 changes: 8 additions & 1 deletion src/plugins/source-plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,14 @@ export default (options) =>
const getAttribute = (tag, attribute, attributes, resourcePath) => {
return attributeList.find(
(element) =>
element.tag.toLowerCase() === tag.toLowerCase() &&
// eslint-disable-next-line no-undefined
((element.tag !== undefined &&
element.tag.toLowerCase() === tag.toLowerCase()) ||
// eslint-disable-next-line no-undefined
element.tag === undefined ||
// eslint-disable-next-line no-undefined
(element.tag !== undefined && !element.tag.length) ||
element.tag === '*') &&
element.attribute.toLowerCase() === attribute.toLowerCase() &&
(element.filter
? element.filter(tag, attribute, attributes, resourcePath)
Expand Down
Loading