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

ux-autoroute-plugin

v3.0.5

Published

自动路由

Downloads

19

Readme

ux-autoroute-plugin

webpack 自动路由插件,该插件用于生成路由映射表文件,配套解析组件ux-autoroute

    // paths.appSrc 为src目录
    new UxAutoRouterPlugin({
        pagePath: path.join(paths.appSrc, 'pages'),
        output: path.join(paths.appSrc, 'config'),
        filename:'routerConfig.ts'
    })

在 src 下读取 pages 文件夹,在 config 文件夹下,生成文件 routerConfig.ts:

//因为import是静态静态引入,所以无法使用变量将component传入做动态路由,只能在此处把整个方法作为动态传递;
import loadable from '@loadable/component'; 
//会根据当前的文件夹所在路径(node_modules/ux-autoroute-plugin)与pagePath生成相对路;
import Page from './pages/index';  

const router = [
    {
        noLazy: true,
        child: [
            {
                default: true,
                child: [],
                componentPath: loadable(
                    function (){
                        return import('../../../src/pages/login//login/index.tsx')
                    }
                ),   //会根据output与pagePath生成相对路径
                path: '/login'
            },
            {
                child: [],
                componentPath:loadable(
                    function (){
                        return import('../../../src/pages//index.tsx')
                    }
                ),
                path: '/main'
            }
        ],
        path: '',
        component: Page
    }
]

export default router

路由要求所有路由文件夹都是 小写且不含特殊字符 ,且文件夹内必须有 index.jsx|index.tsx 为该路由的路由组件。

noLazy,路由默认都会生成为动态路由,会进行代码分片,加上这个配置之后的路由不会生成动态路由,而是使用 import 静态引入

default,默认路由,项目会以 pages 为根路由即/,往下都是其子路由,如果不使用根路由,直接将其视作引导页,其子路由中需要在某一个路由配置中加入 default, 如在 pages 文件夹下新建 login 文件夹,即 login 路由,添加配置 route.config,那么在访问/会被引导到/login

pages/login/route.config,/login路由的配置文件 route.config

{
    "default":true
}

如此在 pages,根路由下一般会取消动态路由,因为作为跟路由代码量本身没有必要分片加载,所以在配置中加入 noLazy: pages/route.config,/路由配置文件:

{
    "noLazy":true
}

ux-autoroute

在线 demo