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

vite-react-view

v1.0.0

Published

React's automatic generate your routes info by files path

Downloads

1

Readme

vite-react-view 是什么

vite-react-view 是一款基于 node 文件系统的契合 vite 生态的约定式路由插件。

vite-react-view 做了什么

通过文件系统监听指定路径下的视图文件变化并实时生成对应的路由文件,提供便捷的 hooks 供用户在逻辑代码中读取路由文件信息。

说人话就是:你只管写界面,插件帮你搞定路由

vite-react-view 约定了什么

  • src/config/routes-config.tsx(默认) 文件,为插件生成的约定路由表。

  • routes-config.tsx 文件将默认引入 ts 类型 与导出 fileRoutes 路由对象。

  • 你将会看到一对固定锚点 /* vite routes begin */ /* vite routes end */,被锚点包裹的对象将会在每次 vite 生命周期中被刷新覆盖,如有个性化字段需求请放置于 meta 字段中。

  • src/views(默认),路径下文件为视图层文件,所有非 ignore(默认为 ['/component?(s)', '/util?(s)', '/test?(s)']) 文件夹下 .(j|t)sx 文件将被创建为路由,例如:

存在此项目结构

├── src                     // 项目目录
│    └── views              // 视图层目录
│          └── Dashboard
│                  ├── index.tsx
│                  ├── Main.tsx
│                  └── Child
│                        ├── index.tsx
│                        └── SubChild.tsx

则 vite-react-view 将会生成如下内容

export const fileRoutes: VrpRouteConfig[] =
  /* vite routes begin */
  [
    {
      name: 'dashboard',
      path: '/dashboard',
      order: -1,
      routes: [
        {
          name: 'dashboard-index',
          path: '/dashboard',
          exact: true
        },
        {
          name: 'dashboard-main',
          path: '/dashboard/com',
          // 个性化字段
          meta: {
            auth: ['admin']
          }
        },
        {
          name: 'dashboard-child',
          path: '/dashboard/child',
          routes: [
            {
              name: 'dashboard-child-index',
              path: '/dashboard/child',
              exact: true
            },
            {
              name: 'dashboard-child-subChild',
              path: '/dashboard/child/subChild'
            }
          ]
        }
      ]
    }
  ];
/* vite routes end */

order 字段用于手动对路由结构进行排序,手动修改不会被覆盖。

快速上手

  1. 安装插件包
cd your-project
yarn add vite-react-view --dev
  1. vite.config.ts 中启用插件
import viteReactView from 'vite-react-view';

export default defineConfig({
  plugins: [
    // ...yourPlugins
    viteReactView({
      // 入口文件夹,默认为 ['/src']
      entryDir: ['/src', '/client']
      // 视图层文件夹,默认为 '/views'
      viewDir: '/views'
    })
  ]
});
  1. 在项目中使用
import useLiteRouter from 'virtual:vite-react-view';

const viteRouter = useLiteRouter(routeConfig);

启动后将在 entryDir 路径下自动生成 config/routes-config.tsx 文件以及 .vite/react-view/config.ts 文件。

FAQ