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

cheers-mp-plugin-router

v1.9.0

Published

读取 cheers-mp-router 路由库的路由配置,自动生成对应的小程序页面path数组并设置到app.json中

Downloads

13

Readme

cheers-mp-plugin-router

babal AST 解析路由配置,提取 path 到 app.json,搭配cheers-mp-router使用

使用

cheers-mp 脚手架中安装即启用

npm i cheers-mp-plugin-router -D

示例

假设路由配置文件所在文件路径是: src/service/router.ts router.ts 文件中有如下代码定义:

import Router, { RouteConfig } from "cheers-mp-router";

const routeConfigList: RouteConfig[] = [
  // 主包路由
  { name: "entry", path: "pages/entry/index" },
  { name: "store-home", path: "pages/tabbar/store-home/index", isTab: true },
  // 子包 packageA
  { name: "test", path: "packageA/pages/test/index" },
  { name: "test2", path: "packageA/pages/test2/index" },
  // 独立子包 ipackageB
  { name: "test3", path: "ipackageB/pages/test3/index" },
];

const router = new Router({ routes: routeConfigList });
// router.beforeEach((to, from, next) => {
//     // console.log("当前路由", from);
//     // console.log("即将前往的路由", to);
//     // console.log("beforeEach1");
//     // setTimeout(() => {
//     //   if (to.name === "product-details") {
//     //     console.log("拦截前往商品详情的请求,转到搜索页面");
//     //     next({
//     //       name: "test"
//     //     });
//     //   } else {
//     //     console.log("放行");
//     //     next();
//     //   }
//     // }, 1500);
//     next();
// });

export default router;

那么我们可以在cheers-config.js配置:

modeule.export = {
  pluginOptions: {
    //  路由配置文件所在的路径
    router: "src/service/router.ts",
  },
};

最终本插件会解析出来router.ts文件中的 path 配置为:

{
  "pages": ["pages/entry/index", "pages/tabbar/store-home/index"],
  "subpackages": [
    {
      "root": "packageA",
      "pages": ["pages/test/index", "pages/test2/index"],
      "independent": false
    },
    {
      "root": "ipackageB",
      "pages": ["pages/test3/index"],
      "independent": true
    }
  ]
}

插件会将此配置更新到src/app.json文件中.

按照约定大于配置的原则:

  • 如果path路径名字以package 开头,则此目录视为子包,例如:{ name: "test", path: "packageA/pages/test/index" }
  • 如果path路径名字以ipackage 开头,则此目录视为独立子包,例如: { name: "test3", path: "ipackageB/pages/test3/index" }
  • 其他路由视为主包,例如:{ name: "entry", path: "pages/entry/index" }