角元素|为每个组件创建单独的构建

发布于 2025-01-19 17:29:29 字数 828 浏览 4 评论 0原文

我有一个常规的 Angular 项目,我想将其转换为 Angular elements 项目。

我的主要目标是为每个组件/元素提供单独的构建文件。

  • login/main.js
  • header/main.js
  • footer/main.js ....

此时此刻,按照 Angular 文档,我已经实现了这一点,但是当我构建项目时,我得到了一个需要在托管项目中导入的 main.js 文件。

第一个问题。由于我将在 Angular 项目中添加大量元素,如果我遵循这种方法,这将是低效的,因为每次我使用 Angular 元素时,整个 main.js 文件(包含所有元素) )将被加载。这个假设正确吗?

因此,为了避免这种情况,我需要以可以分离 Angular 元素的方式构建项目。 我一直在关注这篇文章 但到目前为止还没有运气。我的元素不会渲染到托管项目中。

问题:

  • 如何将单独的 Angular 元素构建到不同的文件夹或文件中?
  • 如果所有元素都在一个文件中,这是否意味着每次调用一个元素时,都会加载整个文件?
  • 有没有不同的方法来实现这一目标?

如果有人经历过这个问题并能给我一些指导,我将不胜感激。

I have a regular Angular project and I want to convert it in an Angular elements project.

My main goal is to have separated build files for each component/element.

  • login/main.js
  • header/main.js
  • footer/main.js
    ....

At this moment and following the Angular documentation I have achieved this but when I build my project I get a single main.js file that I need to import in the hosting project.

1st question. As I will be adding lots of elements into the Angular project, if I follow this approach, this will be inefficient as every time that I use an Angular element the entire main.js file (containing all the elements) will be loaded. Is this assumption correct?

So, to avoid that I need to build the project in a way that I can have separated Angular elements.
I've been following this article but no luck so far. My element doesn't render into the hosting project.

Questions:

  • How to build separated Angular elements into different folders or files?
  • If all the elements are inside one single file, does this mean that every time a element is called, the entire file will be loaded?
  • Is there a different way to achieve this?

If someone has experienced this issue and can give me some directions I would appreciate.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文