@xena-npmjs-public/xena-webcomponents
v1.0.86
Published
Xena Web Components
Readme
Xena WebComponents
This project is part of the new strategy for further development of the current Xena UI.
It is a wrapper project for exposing lazyloaded modules as webcomponents for use in Xena. It allows for developing parts of the Xena UI in Angular and use them in the existing Xena UI as webcomponents with the smallest possible bundle size possible for each view. This is done by making sure that we:
- only load the parts needed for the specific view in Xena and only WHEN needed.
- load the Angular codebase only once.
- combine all modules in one build to ensure we benefit the most from tree-shaking.
It is strongly encouraged to use(and enhance) the Xena Design System for dumb components (button, dropdowns, inputs etc.) - both in Angular components and in the existing Xena UI. This will further shrink the overall bundle size of the page as the same dumb-components can be reused and hence loaded only once.
The following diagram shows how it comes together:

How to add new components
When you need to create a new component, you need to figure out where to put it. The following questions can help you decide that:
- If it is a smart component, then it should be added as a new module in the Xena.WebComponents repository.
- If it is a dumb component then it should be created as a Stenciljs Component in Xena.DesignSystem repository. Then that component will be usable in both Xena Core UI as well as in Angular components.
Creating a new Module for use in Xena.WebComponents
Adding a new module to the Xena.WebComponents repository is quite simple. You go to the folder containing the Xena.WebComponents project and type this:
ng g m my-component-nameAfterwards you can easily create a new component under that module like this:
ng g c my-component-name/my-component-nameDefine the Component to expose as a WebComponent
In your module you can define one (and only one) component to expose as a webcomponent. You do that by defining a conventional property called customElementComponent.
export class MyComponentModule {
customElementComponent: Type<any> = MyComponent;
}Setup selector in Xena.WebComponents AppModule
Final step is to add the selector for your component in the main module of Xena.WebComponents. You do that by expanding the lazyConfig in app.module. You can do it like this:
const lazyConfig:: LazyComponentRegistry = {
definitions: [
createDef('sign', () => import('./sign/sign.module').then(m => m.SignModule)),
createDef('my-component', () => import('./my-module/my-module.module').then(m => m.MyModule))
],
....
}Remark: Your selector will always be prefixed with xwc- as defined in the lazyConfig.
Development server
Run npm start for a dev server. Navigate to http://localhost:4200/. The app will automatically reload if you change any of the source files.
Hosting build locally (fx. for test in Xena locally)
Run npm run host to build a development release and host it locally on http://localhost:8081.
Change value of XenaWebComponentsUrl in src/Xena.Web/Web.config to http://127.0.0.1:8081/{lang}/xena-webcomponents.js
<add key="XenaWebComponentsUrl" value="http://127.0.0.1:8081/{lang}/xena-webcomponents.js" />Remark: Don't commit these changes
Running unit tests
Run ng test to execute the unit tests.
Watch test
Run ng test --watch to watch tests. Will run when files change.
se teset on web http://localhost:9876/
Code coverage
Run ng test --code-coverage to run tests with coverage. This will also generate the Code Coverage report coverage/index.html.
(your path) ~/Xena.WebComponents/coverage/webstall/index.html
More options
See advanced options here: https://angular.io/cli/test
Deploying new version to Xena
- Create a new release of Xena.WebComponents by merging into master branch.
- In the Xena repository update the value of
XenaWebComponentsUrlinsrc/Xena.Web/Web.configto point to the newest version like:
<add key="XenaWebComponentsUrl" value="https://cdn.jsdelivr.net/npm/@xena-npmjs-public/[email protected]/dist/prod/{lang}/xena-webcomponents.js" />Online Demo
Known issues
No known issues at this time.
