question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Creating web-component with vitejs

See original GitHub issue

Is your feature request related to a problem? Please describe. Hi i try creating a web-component from the generated sfc file: i run in the following issues: App.vue is not able to have params. Component have no styles Bundler doesnt provide the outputformat

Describe the solution you’d like i would have something like in the vue-cli target webc … i must be possible to set inline styles for using the shadow-dom

Describe alternatives you’ve considered create a own small script in the main.js

import { createApp } from 'vue'
import App from './App.vue';
import './index.scss';
const components = document.getElementsByTagName('my-app');
for(let i = 0; i < components.length;i++) {
  const element = components[i];
  const style = window.getComputedStyle(element);
  const inlineStyle = document.createElement('style');
  inlineStyle.textContent = style;
  element.attachShadow({mode: 'open'});
  
  element.shadowRoot.appendChild(inlineStyle);
  createApp(App).mount(element.shadowRoot);
}

Additional context thanks for this wonderful web dev build tool we from the mercedes-benz.io seamless-web initiative really happy about it. If help is needed here we are happy to support you actively

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

6reactions
OYangXiaocommented, Feb 18, 2021

The library mode is not enough for building a web-component based project, think about this situation:

A project includes multiple custom elements, we want to dev or build the project, so we need to

  1. mark some files as web-component entry point ( which is possible by set “build.rollupOptions.input” )
  2. configure these web-components to inject css into ShadowRoot ( like the vue-loader shadowMode which is IMPOSSIBLE now because the @vitejs/plugin-vue doesn’t support it yet )

@DrMabuse23 Am I right?

0reactions
philippkuehncommented, Apr 30, 2021

We are also thinking about switching from gridsome to vite for our tiptap docs. We provide many (50+) interactive demos (JS/Vue/React) which should not affected by the styling of the doc pages and vice versa. Shadow DOM would be a great way to encapsulate these demos.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Create Web Components with Lit Element, Vite, and Tailwind
In this post you'll find a cool starter kit to develop web components with all these frontend technologies inside. How to Creare a...
Read more >
Using Native Web Components with Vite (The New ... - YouTube
How to build a landing page with Tailwind CSS, Tailwind UI, Vite.js – tutorial video. Justin Jackson. Justin Jackson.
Read more >
How to make Vue and Vite work with web components?
Tell Vite that all components starting with "foo-" are webcomponents. isCustomElement: (tag) => tag.startsWith('foo-'). Add "postcssLit" plugin ...
Read more >
Getting Started with Web Components & Lit | Part 2
Vite created an index.html which you should open and edit by double-clicking it on the left. Notice that the page already has a...
Read more >
Publish Web Components using Vite, Lit and Storybook
npm create vite@latest my-webcomponents -- --template lit-ts ... 'vite' // https://vitejs.dev/config/ export default defineConfig({ build: ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found