feat: support of external libraries/components in dist-custom-elements
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 5/5
- Thời gian dự kiến
- Hơn một tuần
- Mức phù hợp với người mới
- 25/100
- Loại issue
- Tính năng
- Độ rõ ràng
- Khá rõ ràng
- Mức độ hoạt động
- Đình trệ
- Công nghệ
- typescript
- Lĩnh vực
- build-system
Hướng nghiên cứu
Bắt đầu với src/declarations/stencil-public-compiler.ts và các tệp được liên kết bundle-interface.ts, bundle-output.ts và dist-custom-elements-bundle/index.ts. Theo dõi cách các tùy chọn dist-custom-elements đến được Rollup và cách các collection Stencil được tải lazy được xử lý; hoàn thành có nghĩa là hỗ trợ các entry bên ngoài dạng string hoặc RegExp và giữ các component lazy được yêu cầu ở bên ngoài mà không bundling chúng.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Prerequisites
- I have read the Contributing Guidelines.
- I agree to follow the Code of Conduct.
- I have searched for existing issues that already include this feature request, without success.
Describe the Feature Request
When building components with dist-custom-elements we may need to share code with other components/apps or use external libraries. Currently every external library that is included within a component will be bundled in the compilation output.
It extends FR described in #3226 and follows the discussion in #3136.
Describe the Use Case
There are two use cases:
- Marking, that a library, that is used by a component should not be packed in the component's output bundle
- Marking, that an external lazy loaded component that is used by a component should not be packed in the component's output bundle
In the first case, lets say that we have a dependency to moment.js - right now, if you build a component and within the code of the component there are imports from moment.js, then all required code from moment.js (and its dependencies) will be put in the output bundle. That is fine and proper default behavior, but in my case moment.js is used across multiple components and within main project (which imports those components), moment.js is also directly imported so I would end up with moment.js being bundled three times. Having an "external" option in dist-custom-elements will allow to avoid that.
Second case, lets say, that we created a component, that uses @ionic/core lazy loaded component, e.g. ion-button. If you build the component, you will have in the output bundle the ion-button code but also other ionic components (whole collection is consumed). Having an "external" option would tell rollup to treat @ionic/core as external but also to treat stencil collections as external components.
Describe Preferred Solution
In dist-custom-elements we need to create new option "external":
export interface OutputTargetDistCustomElements extends OutputTargetBaseNext {
...
external?: (string | RegExp)[];
...
}
Value of the external is directly passed to rollup (array of string or RegExp) - this will fully solve the first case (importing external library). Additionally, somewhere in dist-custom-elements compilation process, Stencil must check if lazy components collection is also to be treated as external.
In my Stencil fork both of those cases are covered in dist-custom-elements-bundle output target, below you may see what changes I had to make in order to make it work:
- https://github.com/CODE-AND-MORE/stencil/blob/7c4d13be238fe76abc097c07ddc7b305bfe0383e/src/compiler/bundle/bundle-interface.ts#L13
- https://github.com/CODE-AND-MORE/stencil/blob/7c4d13be238fe76abc097c07ddc7b305bfe0383e/src/compiler/bundle/bundle-output.ts#L98
- https://github.com/CODE-AND-MORE/stencil/blob/7c4d13be238fe76abc097c07ddc7b305bfe0383e/src/compiler/output-targets/dist-custom-elements-bundle/index.ts#L58
- https://github.com/CODE-AND-MORE/stencil/blob/7c4d13be238fe76abc097c07ddc7b305bfe0383e/src/compiler/output-targets/dist-custom-elements-bundle/index.ts#L140-L145
Describe Alternatives
First case (importing external library, not lazy component) can be resolved with rollup plugin defined in stencil.config.ts:
export function externalsPlugin(externals: (string | RegExp)[]) {
return {
id: "externalsPlugin",
resolveId(id: string) {
for (const e of externals) {
if ((typeof e === "string" && id === e) || (e instanceof RegExp && e.exec(id))) {
return {id, external: true}
}
}
}
}
}
Related Code
No response
Additional Information
No response
- Ngôn ngữ chính
- TypeScript
- Star
- 13.2k
- Fork
- 865
- Merge trung bình
- 2 ngày 16 giờ
- Pull request đã merge (30 ngày)
- 29
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của stenciljs/core
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 1 ngày
-
bug(mock-doc): `Element.toggleAttribute()` is missing, so components that use it fail during SSRĐang mởtriage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Stencil FOUC styles should use @layer to avoid cascade conflicts with React 19Có thể đã có người làm @johnjenkins đã nhận 230 ngày trước. Đang mởStencil v5
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 45/100
stenciljs/core#7016 · 1 reaction ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 22/100
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của stenciljs/core
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
AykutSarac/jsoncrack.com#616 ·
-
nip27: long hashtag swallows the rest of the content, lone # gives an empty hashtagCó thể đã có người làm @bardrop đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
nbd-wtf/nostr-tools#578 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
backnotprop/plannotator#3427 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
microsoft/Power-CAT-Copilot-Studio-Kit#942 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[BUG]: Duplicate preposition in heading and unformatted feedback text on Strengthen Argument pageĐang mởbug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
AOSSIE-Org/DebateAI#801 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày