-
-
Notifications
You must be signed in to change notification settings - Fork 469
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
Add support for custom tag attribute #155
Conversation
|
@SpaceK33z can you review it? |
someone is alive here? |
addStyles.js
Outdated
@@ -26,6 +26,8 @@ module.exports = function(list, options) { | |||
} | |||
|
|||
options = options || {}; | |||
options.tagAttrs = typeof options.tagAttrs === "object"? options.tagAttrs : {}; |
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.
spacing
Done, thanx |
the spacing should be tabs instead of spaces |
Fixed the spacing |
README.md
Outdated
@@ -61,6 +61,10 @@ By default, the style-loader appends `<style>` elements to the end of the `<head | |||
|
|||
If defined, the style-loader will re-use a single `<style>` element, instead of adding/removing individual elements for each required module. **Note:** this option is on by default in IE9, which has strict limitations on the number of style tags allowed on a page. You can enable or disable it with the singleton query parameter (`?singleton` or `?-singleton`). | |||
|
|||
#### `tagAttrs` | |||
|
|||
If defined, style-loader will attach given attributes with there values on `<style>` / `<link>` 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.
there -> their
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.
Can you also add what this option expects? Is it an array or object? And what do I exactly need to define in that? A simple example would already help a lot.
All done... |
This is exactly what I needed, thanks. FYI: The docs say
|
@gruberjl, you are right, fixed it. This is exactly what i needed also, i`m waiting for the owner of the proj to approve it :\ |
Someone? |
@felixmosh - Give me a minute, I'll see if I can find someone though everyone is still pretty busy with the 2.2.0 final release of Webpack. |
addStyles.js
Outdated
linkElement.rel = "stylesheet"; | ||
options.tagAttrs.rel = "stylesheet"; | ||
|
||
attachTagAttrs(styleElement, options.tagAttrs); | ||
insertStyleElement(options, linkElement); | ||
return linkElement; | ||
} | ||
|
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.
It might not hurt to throw a quick // document this function
in there given it's an optional 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.
Sorry, i didn`t understood, what does it means "to throw a quick // document this function"
This will be very nice to have as it should allow specifying a nonce to be used with a content security policy (CSP). |
README.md
Outdated
@@ -61,7 +72,17 @@ By default, the style-loader appends `<style>` elements to the end of the `<head | |||
|
|||
If defined, the style-loader will re-use a single `<style>` element, instead of adding/removing individual elements for each required module. **Note:** this option is on by default in IE9, which has strict limitations on the number of style tags allowed on a page. You can enable or disable it with the singleton query parameter (`?singleton` or `?-singleton`). | |||
|
|||
## Recommended configuration | |||
#### `tagAttrs` |
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.
tagAttrs
=> Attrs/Attributes
addStyles.js
Outdated
@@ -26,6 +26,8 @@ module.exports = function(list, options) { | |||
} | |||
|
|||
options = options || {}; | |||
options.tagAttrs = typeof options.tagAttrs === "object" ? options.tagAttrs : {}; |
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.
tagAttrs
=> attrs/attributes
addStyles.js
Outdated
insertStyleElement(options, linkElement); | ||
return linkElement; | ||
} | ||
|
||
function attachTagAttrs(element, attrs) { | ||
for(var key in attrs) { |
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.
options.attrs.forEach((attr) => element.setAttribute(attr, attrs[attr]));
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.
options.attrs is not an array but an key-value pair (object).
So forEach won't work.
I will change it to
Object.keys(options.attrs).forEach...
And because of the fact that this code gonna run on the browser, i prefer to omit the arrow func.
Related #119 |
So I hate to tell you this but it looks like there was an issue updating this PR around Jan 9th ( oops on a rebase maybe ). Point being, the CLA assistant is currently showing 4 contributors to this PR which isn't going to work. Simplest ( and probably only ) way to fix this is to copy code changes to a new branch, Open a new PR, reference this one & then close it. We will finish this and get it merged as soon as we have a pull request that doesn't have the CLA issues. |
So should i create a PR from scratch? |
To prevent issues, it just needs to be a new branch. Everything ( all the changes from this PR ) can be committed in one hash. We will reference this PR from the new one, so none of the review comments will be lost. |
@dsebastien The way that custom tag attributes have been implemented here is not suitable for implementing CSP nonce attributes. A nonce by definition is a secure random string that can only be used once [1], and by hard coding a nonce in your webpack config goes against this. By using the same nonce over and over again, malicious entities know what the nonce will be every time which defeats the point of CSP in the first place. |
@madjam002, looks like the custom attribute feature is not suitable for that job, pls don't use it for that. |
What kind of change does this PR introduce?
feature, allows to add additional attributes on the style / link element that the loader creates
Did you add tests for your changes?
No, tests
If relevant, did you update the README?
Update README
Summary
This PR allows to add id attribute or any custom attribute, in my case i have runtime css style processor that relies on custom attribute on the style tag that it should process.
Does this PR introduce a breaking change?
no breaking changes
Other information
Fixes #147