Skip to content

Allow to specify element into which to inject Style. #65

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

Closed
wants to merge 2 commits into from

Conversation

unity
Copy link

@unity unity commented May 25, 2015

We use this to allow injecting a Style tag into a different place than HEAD.

We use React+Webpack a lot to bundle reusable applications embedded in a 3rd party page.
Here are two examples of how we benefit from this PR:

@vvo
Copy link

vvo commented Sep 15, 2015

HI @unity How do you pass the corresponding element in the webpack config? Thanks

@unity
Copy link
Author

unity commented Sep 15, 2015

You pass it at runtime :

import style from './style.css'

style.use(document.getElementById('myId'));

@mrshll
Copy link

mrshll commented Oct 21, 2015

is there any chance this will be merged? Would love to use this for iframes

@ronkorving
Copy link

Currently this PR has conflicts. Rebasing would be a good start. Would like to see this merged too.

@@ -95,11 +95,11 @@ function listToStyles(list) {
return styles;
}

function createStyleElement() {
function createStyleElement(element) {
var styleElement = document.createElement("style");
Copy link
Member

Choose a reason for hiding this comment

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

styleElement => style

Copy link
Member

Choose a reason for hiding this comment

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

parentElement => element

Copy link
Member

Choose a reason for hiding this comment

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

and all following references to them please :)

@bebraw
Copy link
Contributor

bebraw commented Mar 6, 2017

Could you rebase and add tests where possible? Thanks.

getHeadElement = memoize(function () {
return document.head || document.getElementsByTagName("head")[0];
}),
getElement = function (element) {
Copy link
Member

Choose a reason for hiding this comment

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

I don't see a reason to remove memoization.

@michael-ciniawsky
Copy link
Member

Superseded by #135 Thx 😛

@Aqours
Copy link

Aqours commented Dec 4, 2019

import style from './style.css'
style.use(parent.document.getElementById('myId'));

IMO, this way is more useful than set config in style-loader. Consider to add this feature

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants