-
Notifications
You must be signed in to change notification settings - Fork 185
added shadowRoot for vue-style-loader #238
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
added shadowRoot for vue-style-loader #238
Conversation
Hi @karol-f I think I've rushed wil pull-request, we could do this in: beforeCreateVueInstance(root){
const rootNode = root.el.getRootNode();
if(rootNode instanceof ShadowRoot){
root.shadowRoot = rootNode
}else{
root.shadowRoot = document.head;
}
return root;
} I use |
@FROXZ do you have an example project demonstrating how the fix works? I'm trying to extrapolate how to use it for VueCLI 3 users, but webpack refuses to attach the styles to the shadowDOM. It seems that the shadowDOM does not exist yet when webpack tries to inject the styles |
Hi @bryanvaz , I use Also becuase css-loader 4+ uses esModule loader and is not yet implemented in As you can see there are a lot "but". But here is working code sample:
// src/index.js
import Vue from "vue";
import vueCustomElement from "vue-custom-element";
import myComponent from "./components/myComponent";
Vue.customElement('my-component', myComponent, {
shadow: true,
beforeCreateVueInstance(root){
const rootNode = root.el.getRootNode();
if(rootNode instanceof ShadowRoot){
root.shadowRoot = rootNode
}else{
root.shadowRoot = document.head;
}
return root;
}
}); Full list of "devDependencies": {
"postcss": "^8.2.2",
"vue-loader": "^15.9.6",
"vue-template-compiler": "^2.6.12",
"css-loader": "^3.6.0",
"laravel-mix": "https://github.com/Froxz/laravel-mix.git#custom-latest",
"sass": "^1.32.0",
"sass-loader": "^10.1.0",
"vue": "^2.6.12",
"vue-custom-element": "^3.2.14"
}
const mix = require('laravel-mix');
mix.js('src/index.js', 'dist/webcomponents.js').vue({
version: 2,
options: {
shadowMode: true
}
}); let me know if you need anything else. Full example repo: https://github.com/Froxz/webcomponents P.S. I think if you use Vue CLI it will not work espicially if you |
Hi @FROXZ, Ok I think I get it now, your PR isn't necessarily required if you use the Oh |
Hi @bryanvaz yeap closing the PR, as using |
Should probably create a separate PR to add this to the docs, since running in shadow mode requires users to pass specific code into the I'm planning on updating the docs myself since there's no clear instructions on how to properly contain a component in the shadow DOM, but I still can't find out why Vue CLI is refusing to inject the styles (both in HMR, straight prod builds, and umd/cjs builds). Theoretically all the correct pieces are there:
I've set aside today to try to debug this. For some reason the final injection call for styles in If I can't figure it out, @FROXZ can you take a look later this week? I saw you had some open PRs on the same topic in Cheers, |
Hi @bryanvaz Can you make a repo with full example, I will take a look. |
@FROXZ, I managed to get it working this afternoon. Haven't tested it with Vue 3 or Right now I'm fighting with vuetify to create an example, however I think the library might be too far gone. Do you have any Material UI or visual primitive libraries which might make a good example of how the shadow DOM isolates visual styles? Example: https://github.com/bryanvaz/vue-custom-element-shadow-examples |
With your example you have saved my life, you should make the pull request of the changes so that laravel-mix takes them into account. Thanks a thousand thanks |
Hi,
vue-style-loader
can inject css into shadowDom, what is missing fromvue-custom-element
is reference to this shadowDom.this PR fixes it.
Usage:
Fixes: #214 #191 #156