feat: support of external libraries/components in dist-custom-elements
Los mantenedores suelen responder en 1 día
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 5/5
- Tiempo estimado
- Más de una semana
- Aptitud para principiantes
- 25/100
- Tipo de issue
- Nueva funcionalidad
- Claridad
- Bastante claro
- Estado de actividad
- Estancado
- Stack tecnológico
- typescript
- Área
- build-system
Línea de trabajo
Comienza con src/declarations/stencil-public-compiler.ts y los archivos vinculados bundle-interface.ts, bundle-output.ts y dist-custom-elements-bundle/index.ts. Traza cómo las opciones de dist-custom-elements llegan a Rollup y cómo se gestionan las colecciones de Stencil cargadas de forma diferida; se considera terminado cuando se admitan entradas externas de tipo string o RegExp y los componentes lazy solicitados permanezcan externos sin incluirlos en el bundle.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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
- Lenguaje dominante
- TypeScript
- Estrellas
- 13.2k
- Forks
- 865
- Merge medio
- 2 d 16 h
- PR fusionados (30 d)
- 29
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de stenciljs/core
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
Los mantenedores suelen responder en 1 día
-
bug(mock-doc): `Element.toggleAttribute()` is missing, so components that use it fail during SSRAbiertotriage
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
Los mantenedores suelen responder en 1 día
-
Stencil FOUC styles should use @layer to avoid cascade conflicts with React 19Posiblemente ocupada @johnjenkins la tomó hace 230 días. AbiertoStencil v5
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
Los mantenedores suelen responder en 1 día
-
Dificultad 3/5 1-2 días Aptitud para principiantes 45/100
stenciljs/core#7016 · 1 reacción ·
Los mantenedores suelen responder en 1 día
-
Dificultad 4/5 3-5 días Aptitud para principiantes 22/100
Los mantenedores suelen responder en 1 día
Todos los issues de stenciljs/core
Issues similares
-
[BUG]: Duplicate preposition in heading and unformatted feedback text on Strengthen Argument pageAbiertobug
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
AOSSIE-Org/DebateAI#801 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
Los mantenedores suelen responder en 1 día
-
ci: repo has no GitHub Actions workflow, so pushes and pull requests are never built or testedAbiertoagents area: runtime automation chore cli consistency dependencies developer-experience difficulty: easy documentation enhancement good first issue help wanted hygiene json-output priority: P3 starters tests
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
-
Add: BOM CineAbiertoapproved check:passed streams:add
Dificultad 1/5 Menos de una hora Aptitud para principiantes 72/100
Los mantenedores suelen responder en 1 día
-
area:claude-code-web bug has repro platform:linux platform:web
Dificultad 1/5 Menos de una hora Aptitud para principiantes 66/100
anthropics/claude-code#110168 ·