-
-
Notifications
You must be signed in to change notification settings - Fork 204
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add support for empty tags in tag:attribute
matching
#129
feat: add support for empty tags in tag:attribute
matching
#129
Conversation
Codecov Report
@@ Coverage Diff @@
## master #129 +/- ##
=========================================
+ Coverage 96.8% 96.9% +0.09%
=========================================
Files 2 2
Lines 94 97 +3
Branches 18 18
=========================================
+ Hits 91 94 +3
Misses 3 3
Continue to review full report at Codecov.
|
tag:attribute
matching
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a test aswell 😛
@@ -27,6 +27,8 @@ By default every local `<img src="image.png">` is required (`require('./image.pn | |||
|
|||
You can specify which tag-attribute combination should be processed by this loader via the query parameter `attrs`. Pass an array or a space-separated list of `<tag>:<attribute>` combinations. (Default: `attrs=img:src`) | |||
|
|||
If you use `<custom-elements>`, and lots of them make use of a `custom-src` attribute, you don't have to specify each combination `<tag>:<attribute>`: just specify an empty tag like `attrs=:custom-src` and it will match every element. | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
webpack.config.js
{
loader: 'html-loader',
options: {
/* Example Config for this here... :) */
}
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@michael-ciniawsky Test added! You think we should add this config example right here? Or maybe what I added in the README should be better explained? It would be just having attrs=:whatever-attribute
as stated above...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the data-src
example would be clear enough, also it's already present in the "examples" section.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nuragic Please nevertheless add the comment above as an example under the explanation, just copy & paste it + the correct options please :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@michael-ciniawsky Is that ok?
Sure, will do! Thanks for the review |
4a3497d
to
11dcdd5
Compare
README.md
Outdated
If you use `<custom-elements>`, and lots of them make use of a `custom-src` attribute, you don't have to specify each combination `<tag>:<attribute>`: just specify an empty tag like `attrs=:custom-src` and it will match every element. | ||
|
||
```js | ||
// Example |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-// Example
-{
- test: /\.(html)$/,
- use: ['html-loader?attrs[]=:data-src,
-},
-
-// or alternatevely
webpack >= v2.0.0
Options Syntax only please 😛
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
heheh cool, removed.
@@ -27,6 +27,27 @@ By default every local `<img src="image.png">` is required (`require('./image.pn | |||
|
|||
You can specify which tag-attribute combination should be processed by this loader via the query parameter `attrs`. Pass an array or a space-separated list of `<tag>:<attribute>` combinations. (Default: `attrs=img:src`) | |||
|
|||
If you use `<custom-elements>`, and lots of them make use of a `custom-src` attribute, you don't have to specify each combination `<tag>:<attribute>`: just specify an empty tag like `attrs=:custom-src` and it will match every element. | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
**webpack.config.js** (L31)
Also add tests + update README to document the new feature.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nuragic thx
Thank you! 🙌 |
Nice! I was just looking for this, but scratched my head for a good 30 minutes before I realized this was not in the npm release as of now (I was reading README on github) :) I tested it out and the only problem I found was this matches with I worked around this by changing the second attribute to |
@andersevenrud Hi! Many thanks for trying it out.
I'm not sure if it's a bug or the expected behavior so, please could you paste here 1) your loader config and 2) the part of your HTML involved? Regarding the Thanks! |
@nuragic Here's an example extracted from my code:
As you can see it tries to parse both my attributes, because |
Ah! I see... I'm going to fix it and open a new PR later today. Thanks for reporting! 👍 |
When #133 lands I will try to get someone to publish a new release as soon as possible :) |
Fix a bug introduced with webpack-contrib#129.
Fix a bug introduced with #129.
Hi!
I'd like to propose a little change that would make possible to match every element that use a specific attribute, without bloating the config file... I work in a project that use
<custom-tags>
so currently each time we add a new element that want to load an image, we are forced to update the config file... this change would avoid that.Tests are passing and it's not a breaking change, AFAIK.
Any feedback is welcomed.
Many thanks! ❤️