npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

lofter-admin-cli

v1.0.6

Published

js sandbox on browser

Downloads

42

Readme

lofter-admin-cli

这个是为微前端发布cli, 可以帮助你直接发布到应用平台

最新版本

release/v1.0.2

安装

  1. package.json里添加依赖
"lofter-admin-cli": "1.0.2"
  1. 运行 npm install 完成安装

更新版本

  1. 修改 package.json 依赖为指定版本分支
"lofter-admin-cli": "1.0.2"
  1. 运行 npm install 完成更新

命令说明

lofter-admin-cli config

用于配置全局的用户信息

lofter-admin-cli config --set secret=xxx

lofter-admin-cli upload

用于上传新版本

lofter-admin-cli upload --config lofter-app.js

配置文件说明

module.exports = {
  /**
   * @param {number} appId - 必填
   * 子应用注册后分配的应用Id
   */
  appId: 123,

  /**
   * @param {string} secret - 可选
   * 登录应用平台后在个人页查看到的上传密钥
   * 也可以通过 lofter-admin-cli config --set secret=xxx设置到本地
   */
  secret: 'xxxxxxx',

  /**
   * @param {string} remote - 可选,一般无需添加
   * 指定上传的应用平台地址
   */
  remote: ''

  /**
   * @param {string} rootDir - 必填
   * 需上传文件根目录
   */
  rootDir: 'dist',

  /**
   * @param {string} html - 可选
   * 重要:html 和 entry 至少使用一个,否则无法正确启动该应用
   * 指定加载的html文件地址,路径相对于rootDir
   * 使用 html 模式支持webpack分包,此时 publicPath 设置为 '/' 即可
   */
  html: 'index.html',

  /**
   * @param {string[]} entry - 可选
   * 重要:html 和 entry 至少使用一个,否则无法正确启动该应用
   * 额外的入口文件,相对于rootDir, 支持 * 通配符
   * 会自动挂载到html中
   * 配置html后,一般无需再次配置 entry
   */
  entry: ['umi.css', 'umi.js'],

  /**
   * @param {string[]} excludes - 可选
   * 不需要上传的文件,相对于rootDir,可以用于减少上传的文件数量,加快上传
   */
  excludes: ['xxx.yyy'],

  /**
   * @param {string[]} includes - 可选
   * 指定需要上传的文件,相对于rootDir
   */
  includes: [],

  /**
   * @param {Object} requestRewrite - 可选
  *  客户端请求重写配置,key value形式
  *  请求url如果匹配由key生成的正则,会用value进行replace
  *  此处统一配置,可以免于修改每处请求的url
  */
  requestRewrite: {}
}

转发规则运行原理

requestRewrite工作代码

const rewriteReg = new RegExp(rewriteKey);
if (rewriteReg.test(url)) {
  newUrl = url.replace(rewriteReg, requestRewrite[rewriteKey]);
  return true;
}

整体工作原理

  1. 正常情况下,如果不配置requestRewrite,应用A配置的路由为/yyy, 发出的请求/xxx,沙箱提供的request方法都会修改url为/api/yyy/xxx,目的是把所有请求都发送到主应用的node层来处理,并且附带应用A的应用路由
  2. 此时如果在应用平台配置了转发规则,/yyy转发到1.1.1.1,则最终node层会把该应用A的所有请求都转发到1.1.1.1
  3. 如果应用B配置了requestRewrite,沙箱提供的request方法会根据配置的rewrite规则修改,而不再根据规则1修改,比如'^/aaa': '/api/bbb/aaa'规则会把所有/aaa开头的请求重写为/api/bbb/aaa
  4. 如果在这个基础上,在应用平台配置了转发规则,/bbb转发到2.2.2.2,那么最终应用B下所有/aaa开头的请求,都会转发到2.2.2.2这个地址

要点总结

  1. 只有最终发送出去以/api开头的请求,才能被node层代理到,执行应用平台的转发规则
  2. 如果不配置requestRewrite或者请求url没有命中requestRewrite中的规则,请求会被微前端沙箱自动加上/api/{应用路由}
  3. 如果请求url被配置的requestRewrite规则命中,则会以该规则为准,微前端沙箱不再进行二次处理
  4. 规则的value最好以/api开头,以获得node层转发和转发规则处理的能力,并且会在请求的header中附带用户的openId登录信息