1.0.0-alpha.3 • Published 4 years ago

plugxable v1.0.0-alpha.3

Weekly downloads
1
License
MIT
Repository
-
Last release
4 years ago

Plugxable

Js framework for pluggable application development.

目的是将前端系统进行插件化解藕和跨系统的插件化复用,实现业务级模块的热插拔,可配置,一次开发,多次使用。

Usage

Develop a plugin

import { Plugin } from "plugxable"
import { LoginComponent, RegisterComponent, ForgotPasswdComponent } from "./component"
import VueEngine from '@plugxable/engine-vue'

export default class UserPlugin extends Plugin {
  apply(api) {
    api.page('login', '/login', LoginComponent)
    api.page('register', '/register', RegisterComponent)
    api.page('forgot', '/forgot', ForgotPasswdComponent)

    // 将插件配置注入到页面组件中
    super.apply(api)
    // 提供退出登录服务
    api.provide({
      'user:logout': (...arg) => {
        // ...
      },
    })
    // 注入其他插件提供的服务到插件页面实例中
    api.inject({
      success: 'common:success',
      info: 'common:info',
      warn: 'common:warn',
      error: 'common:error',
      logout: 'user:logout',
      // ...
    })
  }
}

Run a plugxable app

import plugxable from "plugxable"
import UserPlugin from "./UserPlugin"

const userPluginOptions = {
  pages: {
    // 公共配置
    _: {
      brand: 'xxx',
      logo: 'https?://cdn.xxx.com/xxx.png'
      // ...
    },
    // 登录页面配置
    login: {
      text: 'xxx',
      loginIcon: 'https?://cdn.xxx.com/xxx.png'
      // ...
    },
    // 注册页面配置
    register: {
      registerIcon: 'https?://cdn.xxx.com/icons/register.png',
      registerText: '注册'
      // ...
    }
    // ...
  },
  services: {
    login: 'https?://api.xxx.com/login',
    logout: 'https?://api.xxx.com/logout',
    register: 'https?://api.xxx.com/register',
    forgot: 'https?://api.xxx.com/forgot'
  }
}

const app = plugxable({
  engine: VueEngine,
  plugins: {
    user: new UserPlugin(userPluginOptions),
    // ... other plugin
  }
})

app.run()

Status: Dev

TODOs

  • rollup build script
  • test in browser