Anidetrix / rollup-plugin-styles

🎨 Universal Rollup plugin for styles: PostCSS, Sass, Less, Stylus and more.
https://anidetrix.github.io/rollup-plugin-styles
MIT License
243 stars 43 forks source link

possible to add attributes to injected style tag? #119

Closed redonkulus closed 4 years ago

redonkulus commented 4 years ago

I need to pass an id attribute to the injected style tag so that I can access the CSS later on. Is it possible to add this functionality? It could be generic and support any number of attribute via some object passed into inject options...

Anidetrix commented 4 years ago

Hello @redonkulus, thank you for your time and suggestion!

Just id seems very limiting to me, considering that by default injector creates multiple style tags, which means they all will have the same id, which is generally not the best practice.

I propose the following - add selector option to injector with the following rules:

Please let me know if that will work for you.

redonkulus commented 4 years ago

That works for me as long as I can target a specific id for my usecase.

Anidetrix commented 4 years ago

Done, although I did generalize it further than I mentioned before, to simply adding attributes as object, just like you suggested. You can read the docs here. Let me know if this solves your problem!

redonkulus commented 4 years ago

@Anidetrix tried it locally and it works great! thanks for the quick turnaround, really helped me out.

Anidetrix commented 4 years ago

@redonkulus I'm glad, good luck with your work! Closing this issue then, can be reopened if needed.