Lone component and Microfrontend
Overview
The Lone Component, also known as CDN-based project, allows embedding Still.js components into other web applications without relying on the Still Application container. When done via CDN it must follow a minimal project structure having the app/
folder for components and the route.map.js
file for routing configuration.
Although in many cases it might be used through the CDN, it's still recommended to use still-cli for basics setup and component creation since this is an automatical way to create components and handle the routing.
Microfrontend
Lone component also provides with the capabilities to build a whole Frontend tied to an entrypoint component thereby making it possible to scale it to Microfrontend.
1. Basic Lone component application tutorial
- Simple project folder structure
The bellow folder structure is only an example which can also be taken as suggestion, anyway the most important files are the app/
folder and route.map.js
file.
project-name #My project root folder
|___ microfrontend/ #This is a folder where all microfrontends will be placed
| |__ still/ #This folder contanins the microfrontends implementations in Still.js
| | |__ app/ #App folder where component will be placed
| | | |__ components/ #Folder which holds the comopnents
| | | | |__ dummy/ #Folder which holds the comopnents
| | | | | |__ DummyComponent.js #Created in the point 1.4
| | | | |__ another/ #Will house components concerning to the user
| | |__ config/ #App folder where component will be placed
| | | |__ route.map.js #still-cli will add the route automatically when creating a component
| |
#Bellow are the files of my project placed in the project root folder
|__ index.html
|__ my-project-folder/
|__ ... #Additional files from my project
Code editor/IDE view:
1.1 Setup - Generating base files (app/, route.map.js) for Lone components to work
From inside the folder where we want to have our Lone components, using the still-cli we have to run the following:
1.2 Adding the CDN and embeding the component to the HTML file
index.html file is being used in this case, but it can just be done in any type of file that will render something to the browser.
Our application file is required to set the STILL_HOME
variable which needs to point to the root folder where the still project is located, as this is how the framework knows how to bring components to our application.
1.3 Running my Application
In order for the components to load properly the Application needs to be served from a web server, it can be NGINX or Apache for example, in this case, we'll use live-server. Using live-server we need to do it from the root folder:
Expand to show Lone component running success
1.4 Creating the Lone component Whithin CDN base project
Let's create our Lone component based on the folder structure presented previously (point 1.1), from the root folder where still is located and use abbreviated still-cli command option.
When creating a Lone component in the CDN context, we need to pass the --lone
at the end, as this is how still understands that the whole structure and files are not present locally.
Once generated, the component should have the scaffolding code as follows:
In this case the ViewComponent
super class is not imported dispite being extended, this is because CDN provides it since it is not present locally.
2. Lone component by having whole framework Structure locally
Context
Lone component can also be created in the scenario where I have create a regular Still.js project, however for a specific situation I need a component which can be embeded to my other type (not Still.js) of Application.
User case
This could be a good use case where I have more than one application or where some of the resources would be shared between my Lone component and another Still.js Application I have.
2.1 Folder Structure
The big different between this approach vs using CDN approach is that we have the whole Still.js folder structure and files locally, but how HTML/main application file(s) will always stay outside since Still.js components will only be embeded but not dictate the application flow itself.
The HTML/Application file in this case will point to the local files instead of the CDN ones, follow the code sample:
1.3 Adding the CDN and embeding the component to the HTML file
Component creation consideration
Unlike the CDN scenario, we don't have to use the --lone
option when creating Lone component having the whole Still.js folder structure and files.
Once the Still.js setup is done for our application, we then need to run it, in this case the process will be the same as point 1.5.
Microfrontend considerations
Although Lone Components don't run within the Still.js Application container, they still support all core framework features — like reactivity, services, routing, authorization, etc. — making them suitable for a Microfrontend architecture.