简体   繁体   English

StencilJs 组件不在另一个 stenciljs 项目中呈现

[英]StencilJs component not render in another stenciljs project

I've created a stenciljs webcomponents using the starter project, and I'm trying to grab it into another stenciljs project, via package.json dependecy, which points to a git repo.我已经使用入门项目创建了一个 stenciljs webcomponents,我正试图通过package.json dependecy 将它放到另一个 stenciljs 项目中,它指向一个 git 存储库。

The webcomponent is imported in, but as soon as I try to run the component inside a tsx stenciljs project, I noticed the following: Web 组件已导入,但当我尝试在 tsx stenciljs 项目中运行该组件时,我注意到以下内容:

  • the props are not passed in, the css I can see it being applied, but the content is missing道具没有传入, css 我可以看到它正在应用,但缺少内容
  • if I add something extra on the page, like a character or something, the dev server renders the webcomponent (also tried building the project, same behavior)如果我在页面上添加一些额外的东西,比如角色或其他东西,开发服务器会呈现 web 组件(也尝试构建项目,相同的行为)
  • the webcomponent also contains some .svgs pushed into .tsx files into return statement, even after adding a character on the page, those icons still don't render webcomponent 还包含一些.svgs推入.tsx文件到 return 语句中,即使在页面上添加字符后,这些图标仍然不呈现

Not sure if Im doing something wrong here, weird enough is that as soon as I add something else on the page, besides that webcomponent, it kinda renders correctly.不确定我是否在这里做错了什么,奇怪的是,只要我在页面上添加其他内容,除了那个 web 组件,它就会正确呈现。

I'm importing the webcomponent into a component inside the stenciljs project via:我通过以下方式将 webcomponent 导入到 stenciljs 项目中的组件中:

import 'my-component-from-git' <-- points to the webcomponent folder in node_modules folder import 'my-component-from-git' <-- 指向 node_modules 文件夹中的 webcomponent 文件夹

stenciljs webcomponent config: stenciljs web组件配置:

plugins: [
    sass()
  ],
namespace: 'my-component',
outputTargets: [
  {
      type: 'dist',
      esmLoaderPath: '../loader',
    },
    {
      type: 'dist-custom-elements-bundle',
    },
    {
      type: 'docs-readme',
    },
    {
      type: 'www',
      serviceWorker: null, // disable service workers
    },
  ],

stenciljs project config: stenciljs 项目配置:

globalStyle: 'src/global/app.css',
globalScript: 'src/global/app.ts',
taskQueue: 'async',
  plugins: [
    sass()
  ],
  outputTargets: [
    {
      type: 'www',
      // comment the following line to disable service workers in production
      serviceWorker: null,
      baseUrl: './../',
    },
  ],

After some investigation, the component that I wanted to export as webcomponent, used multiple functional components to render its contents (also same for .svgs ), and after removing these, and using them in the class that exports the webcomponent, it works fine.经过一些调查,我想导出为 webcomponent 的组件使用多个functional components来呈现其内容(对于.svgs也是如此),在删除这些组件并在导出 webcomponent 的 class 中使用它们后,它工作正常。

Im not totally sure if these something wrong with this, or maybe its not supported properly, or the dist output isn't generated correctly when using functional components .我不确定这些是否有问题,或者它没有得到正确支持,或者dist output 在使用functional components时没有正确生成。

For the time being, if anyone encounters some wierd rendering issues, when trying to import stencil generated webcomponent, into another stencil project, try to modify a bit your code so it doesn't use these functional components .目前,如果有人在尝试将 stencil 生成的 webcomponent 导入另一个 stencil 项目时遇到一些奇怪的渲染问题,请尝试修改一下您的代码,使其不使用这些functional components

Maybe there is something specific about some config that is missing for the webcomponent.也许 Web 组件缺少某些配置的特定内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM