-
-
Notifications
You must be signed in to change notification settings - Fork 469
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Allow importing code to determine where styles are inserted #328
Comments
Having a similar issue, this would be an awesome feature! |
@bcanseco Loader files are here: https://github.com/grommett/web-components/tree/master/html-loader-css-modules/loaders Usage(webpack.config) here: |
This lets users reference their own string selector inside the insertInto function. Necessary until webpack-contrib#328 is resolved.
Sorry for big delay, PR welcome |
We have useable api, i think we need improve this, adding more option for |
For better compatibility with css modules from w3 spec (not to be confused with css-modules from import styles from './custom-square.css';
class CustomSquare extends HTMLElement {
// Specify observed attributes so that
// attributeChangedCallback will work
static get observedAttributes() {
return ['l'];
}
constructor() {
// Always call super first in constructor
super();
this.attachShadow({ mode: 'open' });
}
connectedCallback() {
const div = document.createElement('div');
this.shadowRoot.appendChild(div);
const bgPurple = new CSSStyleSheet();
bgPurple.replace(styles);
this.shadowRoot.adoptedStyleSheets = [bgPurple];
}
}
customElements.define('custom-square', CustomSquare); |
This looks like an elegant approach, however |
@mike-shtil it is only return css nothing more, for better w3c compatibility with css modules spec (do not confuse with css modules from css-loader) |
Allow to pass additional parameter to `style.use(anything)` which will be passed to `insert` function. This allows to insert each tag in different places and especially useful for Shadow DOM Resolves webpack-contrib#328
Allow to pass additional parameter to `style.use(anything)` which will be passed to `insert` function. This allows to insert each tag in different places and especially useful for Shadow DOM Resolves webpack-contrib#328
There are two solution for shadow DOM:
Original style-loader |
This is a feature request.
Problem
As far as I can tell, the style loader only allows for styles to be inserted into one location, either the
<head>
or where specified in theinserInto
string or function.This approach does not work with composed/nested custom elements, as each can have their own shadow dom. If, for example,
insertInto
specifies the root custom element the styles are not picked up in children shadow doms.Feature Request
Allow importing code to determine where styles are inserted.
Possible Solution
option
for local insertion. Let's call itlocalInsert
, which defaults tofalse
so that code executes as it currently does.localInsert
istrue
, theupdate
function is not invoked and we attach a method (localInsertTo
?) toexports
, which allows for the importing file(s) to determine where the styles are inserted.Example
In the example below each custom element will have their imported styles inserted into their respective shadow doms by calling the
localInsertTo
.Webpack
Parent
Child
The text was updated successfully, but these errors were encountered: