ergonode / vuems

A simple mechanism to transform a monolithic Vue application into an application based on Micro Services architecture
https://vuems.ergonode.com
Open Software License 3.0
78 stars 9 forks source link
javascript micro-services-architecture microfrontends nuxtjs vuejs

VueMS logo

Vue Micro Services

NPM NPM

📖 Read the documentation


A simple mechanism to transform a monolithic Vue application into an application based on Micro Services architecture.

Inspiration

Combination of Vue and NuxtJS frameworks gives us the opportunity to build any web application we want. Unfortunately, application built on this approach is monolithic and we cannot extend its behavior. Of course we can extend project with some elements, but these are small fragments that do not add much. In addition, NuxtJS forces developers to have a specific directory structure (page, middleware, store, etc.). This gives us a rigid application built on specific principles.

VueMS gives the possibility to divide the application into micro parts that use all Vue + NuxtJS mechanisms, but do not have their limitations. Structure of these parts is identical to the monolithic application, however each module can operate separately, communicate and interact with one another. Modules can be both small elements (single component, plugin) and complex structures (components, plugins, middleware, store, pages).

Advantages of VueMS:


Detailed Start

📦 Requirements

🚀 Power Supplies


Setup

1. Add @ergonode/vuems dependency to your project.

npm install @ergonode/vuems
# or
yarn add @ergonode/vuems

2. Add @ergonode/vuems to the buildModules section in the nuxt.config.js file.

  export default {
    ...
    buildModules: [
      ['@ergonode/vuems', { /* module options */ }]
    ],
    ...
  }
Using top level options
  export default {
    ...
    buildModules: [
      '@ergonode/vuems'
    ],
    vuems: {
      /* module options */
    },
    ...
  }

Options

modules

Object with all loaded modules.

required

Array with required module names.

modulesDir

Local modules directory name.

vendorDir

Npm modules directory name. Directory is temporary and used by symbolic link.

nodeModulesDir

Directory where installed npm modules are to be found.

vuex

If Vuex library is used.

i18n

If i18n plugin is used.

isDev

Is development mode on.

logLoadedModules

Log all loaded modules.

verbose

Log module process.

directories

Directory structure for module.

Options example

vuems: {
    required: [
        '@my/core',
    ],
    modules: {
        local: [
          '@my/core',
          '@my/authentication',
        ],
        npm: [
            '@test/users',
            '@test2/import'
        ]
    },
    isDev: process.env.NODE_ENV !== 'production',
}

Module creating

Introduction

Modules are based on mechanisms Nuxt Modules, but they have no restrictions on the structure. The module can have any structure, which means it can be a single functionality or a large and complex business logic. We divide modules at our discretion and it is also our decision what structure they will have.

Types

Modules can be divided into two types. The type determines the place from which the module is loaded.

Naming modules

Local

The names of local modules are determined based on the directory structure. The adopted and recommended directory structure is based on the concept npm scope.

modules/
|-- @test/
    |-- my-local-module/
|-- users/

Npm

The names of the npm modules are consistent with the approach of creating npm packages.

Example:

modules: {
  local: [
    '@test/my-local-module',
    'users',
  ],
  npm: [
    '@npm/npm-module',
  ],
}

Module requirements

Each module needs several things to work properly:

index.js entry file:

In the project directory we create an entry file called index.js, needed to run the module.

export async function beforeModule() {
    // run before loding module
}
export default async function () {
   // module logic
}
export async function afterModule() {
    // run after loding module
}

config directory:

Module must have a config directory with index.js file. All available configurations can be placed in this directory.

Configurations:

Example application