我想将我的 vue 2 项目从webpack迁移到 vite 。
并且必须使用使用
这些组件在运行时(通过VUE)丢弃错误:
未知自定义元素:< foo-component> - 您注册了
组件正确?对于递归组件,请确保提供
“名称”选项。
还有(通过 lit-element )
未能在“ Shadowroot”上设置“采用的列表”属性:
无法将值转换为“ CSSSTYLESHEET”。
据我所知,那些第三方Web组件仅在其索引文件中执行此操作( node_modules
):
import FooComponent from './FooComponent';
customElements.define('foo-component', FooComponent);
因此,(使用WebPack设置)之前,我只是导入了它们,并且所有用来工作的东西。好吧,实际上对于WebPack lit-scss-loader
也用于这些组件。
我认为Vite可能需要一些其他配置,或者在这里需要类似于“ WebPack”加载程序的东西,但不确定我必须移动什么方向。
我在做什么错?
I want to migrate my Vue 2 project from webpack to Vite.
And have to use 3rd party web components that built with lit-element.
Those components throws errors during the runtime (by vue):
Unknown custom element: < foo-component > - did you register the
component correctly? For recursive components, make sure to provide
the "name" option.
And also (by lit-element)
Failed to set the 'adoptedStyleSheets' property on 'ShadowRoot':
Failed to convert value to 'CSSStyleSheet'.
As far as I can see those 3rd party web components do only this in theirs index files (inside node_modules
):
import FooComponent from './FooComponent';
customElements.define('foo-component', FooComponent);
So before (with webpack setup) I just imported them and everything used to work. Well, actually for webpack lit-scss-loader
was used also for those components.
I assume that Vite perhaps needs some additional configuration, or maybe something similar to "webpack" loader is needed here, but not sure what direction I have to move.
What I'm doing wrong?
发布评论
评论(2)
configure
@vite/plugin/plugin-vue
点亮的元素,例如,以
my-lit
开头的元素,其注册名称:demo
Configure
@vite/plugin-vue
to ignore Lit elements, e.g., elements starting withmy-lit
in their registered name:demo
需要几个步骤。
想象一下,我有第三方网络操作人员名为“ Foo”。因此,所有这些都在
node_modules/@foo
中。我需要执行以下步骤:
告诉VITE,所有组件以“ foo-”开头是Web Components。
iscustomelement :( tag)=&gt; tag.startswith('foo-')
添加“ “插件可帮助Vite为WebComponents准备CSS。
告诉Vite如何处理WebComponents的CSS路径。
'〜@foo':fileurltopath(new url('./ node_modules/@foo',import.meta.url))
这是完整的配置:
A couple of steps are needed.
Imagine I have 3rd party webcomponents named "foo". So all of them are in
node_modules/@foo
.I need to do these steps:
Tell Vite that all components starting with "foo-" are webcomponents.
isCustomElement: (tag) => tag.startsWith('foo-')
Add the "postcssLit" plugin to help vite prepare the CSS for the webcomponents.
Tell Vite how to treat CSS paths for webcomponents.
'~@foo': fileURLToPath(new URL('./node_modules/@foo', import.meta.url))
Here is the full config: