0.0.3 • Published 1 year ago

@digital-enabler/demf-database-manager-details v0.0.3

Weekly downloads
-
License
-
Repository
-
Last release
1 year ago

VUE JS Template Project with Vue/CLI v.4.5.15

REPO-TYPE

This template project is a start base that help you to create a Microfrontend project with the use of the Single-spa plug-in. Use this template and follow this guide.

Pre-requisites

Before you continue you need to

  • have NPM installed
  • have NodeJS installed
  • have VueJS and Vue-CLI installed
  • have a GitHub account
  • use VisualStudio Code or IntelliJ Idea as your development IDE

Creating an MF from VueJS template project

  1. Use the vuejs-microfrontend-template project by clicking on button Use this template from GitHub and in the next page write a project name with this pattern demf-[tool_name], write also a breaf description and select private type.

  2. Now the new project root-config is created on GitHub, clone it on your local environment and make a branch from main to start to work on it.

  3. In your local IDE, open the app/package.json file and rename the project using the pattern name @digital-enabler/demf-[tool_name]

  4. Open a Terminal window in the project folder and go inside the app folder, then launch the command: npm install

NOTE: When install finished, do not care about the warnings on the versions and vulnerability problems reported, and DO NOT launch the npm audit fix or npm audit fix –force commands

  1. At this point you can start customizing your project in VueJS, installing any additional libraries you need.

  2. Once you have completed and verified that all the desired libraries have been correctly configured, you can proceed with its transformation into Microfrontend through the use of the Single-spa plug-in.

vue add single-spa

The installation, in addition to installing the plugin, will involve modifying the package.json file and the main.js file to make them compliant with use within a microfrontend.

Alternatively to the command indicated you can use the VueUI browser interface to easily install the plugin: with the server turned off and the project not started, open the plugin section of the UI and look for the plugin vue-cli-plugin-single-spa, select it and proceed with the installation, following the instructions on the screen.

ATTENTION: it is possible that during the installation of the plugin through the VueUI not all the imports of your original main.js, in particular of the i18n plugin, are reported. If this happens, just re-enter the missing imports, for example: import i18n from "./i18n";
Then invoke it as for the other imports listed by copying the i18n key into the appOptions object.

  1. We can now verify the correct installation of the plugin by delivering the microfrontend through the command:
npm run serve

or by starting the Serve task from VueUI.

  1. When the server is started, your microfrontend will be available at the URL http://localhost:8080. The page shown will contain the title "Your Microfrontend is not here" along with some instructions.

Now your new Microfrontend is ready to be customized and mounted on a root-config project. See here for more information on how to mount your microfrontend on a root-config.

Using Props

You can use props shared by a root-config project, to be used within the MF in a variety of ways, such as additional external information, so that they are already present at the time the MF is mounted.

Props are data that can be used to initialize and configure the MF from its mount. Generally, props are provided by the root-config and then declared in the route tag that defines the layout and visibility of the MF within the application. See here for more information on how to mount your microfrontend on a root-config.

To use the props in the MF it is necessary to define them within the main.js file in the appropriate props section, as well as in the example:

    ...
    render(h) {
        return h(App, {
          props: {
            // single-spa props are available on the "this" object. Forward them to your component as needed.
            // https://single-spa.js.org/docs/building-applications#lifecycle-props
            // if you uncomment these, remember to add matching prop definitions for them in your App.vue file.

            mashupsListConfig: this.mashupsListConfig,
            palette: this.palette,
            realm: this.realm,
          },
        });
      },
      router,
      store,
      vuetify,
      i18n,
    };
    ...

The code shows the declaration of the three props: mashupsListConfig, realm and palette. These three props must be forwarded in the MF code by adding the corresponding prop definitions within the App.vue file, as you usually declare a prop in a VueJS component.

Specifically mashupsListConfig is an example of a way you can take to get an external configuration json file for use within your application, generally this is called realm-mf_name-config.json and is located in a storage space separate. The root-config application is programmed to load several configuration files from a specific storage.

Creating the realm-mf_name-config.json

There is a way you can take to get an external configuration json file for use within your application and it is throgh the root-config application that is the main access point for every MF, see here for more information.

Generally this file is named realm-mf_name-config.json and is located in a specific storage space separate. The root-config application can be configured and is programmed to load several configuration files for every MF from the specific storage you set.

In this json file you can set all those static information necessary to your application working, an example could be:

{
   "mf": "Sidebar",
   "api": "//localhost:8083/api",
   "storageImgs": "https://storage.digital-enabler.eng.it/imgs",
   "links": [
      {
         "title": "labels.mashups",
         "icon": "mdi-file-tree",
         "link": "/"
      },
      ...

In this example you can see various information for your application

  • the "mf" key is the name of the microfrontend you need to use to register the configuration file in root-config here.

This is a required key to use this file.

  • "api" is the URL if your MF uses external API.
  • "storageImgs" is the URL of an external image memory where you can put all your images.
  • the "links" in this case are an array of objects describing different links to be used in the application

and so on...

Except the first "mf" key which is mandatory, other information you put in the json file should be all static info you to use inside your application.

When you have finished writing all the necessary information into this file, you need to publish it to a remote repository and register it following the instructions here, so that it can be used via the root-config application.

Building Policy and Methodology

In order to get a build of the microfrontend project as light as possible and with clean and customizable code, in an easy way, even without having to recompile the MF, you need:

  • remove any file that is not essential for building the project or that can, in any case, be regenerated during the build itself

  • use external storage (e.g. AWS S3, DE MinIO, Github, etc.) for all those static elements such as images and json files

Lints and fixes files

To find and fix problems in your JavaScript code you can use the Lint task inside the VueUI or the equal command line:

npm run lint

It is suggested to use this task just before every commit/push to git.

Build and Deployment

Once you pushed all your code and merged it with the main branch, the Pipeline system will deploy the new microfrontend on the NPM cloud under the Digital-Enabler organization. NPM will store your public compiled code and here you can controll all versions of your MF.

If you go to the free CDN JSDeliver and try to search @digital-enabler you will obtain the list of microfrontend for Digital Enabler with also the one you have deployed. Open the detail of one project, and you can see every files contained on it. Find the file named app.js and click the icon on the right side of the line. It will open a menu, select the Copy URL to copy the URL of this file to clipboard.

You will obtain a URL like this one:

https://cdn.jsdelivr.net/npm/@digital-enabler/mashups-list@0.0.6/app.js

It usually have the pattern:

https://cdn.jsdelivr.net/npm/@digital-enabler/[MF-project-name]@[MF-version]/app.js

This is the URL you have to use inside a root-config if you want to mount a MF from external source. You can notice the version, so if you want to use a different version you simply can change it.

Known Issues

For the following dependencies it is necessary to use the versions indicated that are currently the ONLY ones supported by the single-spa plugin used

PluginVersion
Vue-router^3.2.0
Vuex^3.4.0

This template includes listed dependecies:

"@mdi/font": "5.9.55",
"axios": "^0.26.0",
"core-js": "^3.6.5",
"roboto-fontface": "*",
"vue": "^2.6.11",
"vue-i18n": "^8.26.3",
"vue-router": "^3.2.0",
"vuetify": "^2.6.0",
"vuex": "^3.4.0"