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

@kuaizi/vue-cli-plugin-auto-router

v1.0.2

Published

Vue Router route generator

Downloads

279

Readme

vue-cli-plugin-auto-router

使用了 vue-route-generator

单路由可以直接使用 vue-auto-routing

使用

vue add @kuaizi/vue-cli-plugin-auto-router

默认页面文件夹为 ./src/pages/*/views/,自定义需要添加配置 package.json 中的 autoRouterConf 字段

{
  //...
  autoRouterConf: {
    pages: ['./src/pages/**/views/'],
    importPrefix: './views'
  }
  //...
}

webpack默认不启动对文件增删进行watch监听,但我们可以手动增加设置

webpack 不能对添加的文件进行监听,内部使用watch 模块,性能暂无测试

example

> cd example
> yarn
> yarn dev

auto-router-webpack-plugin

多页面自动路由 webpack 插件

单页面可以直接使用 vue-route-generator

参数

  • options {Object} 配置参数
    • pages {String|Array} 支持globby的匹配,支持字符串或者数组 globbing-patterns
    • importPrefix {String} 默认是../views/, vue-route-generator默认的是@/pages, 异步组件的默认路径,eg:import('../views/account.vue')

参数 | 类型 | 描述

  • | - | - pages | String|Array | 支持globby的匹配,支持字符串或者数组 globbing-patterns importPrefix | String | 默认是./views/, vue-route-generator默认的是@/pages, 异步组件的默认路径,eg:import('./views/account.vue')

使用

# vue.config.js
export default {
  // ...
  configureWebpack: {
      cache: true,
      plugins: [
        new webpackPluginAutoRouter({ pages: './src/pages/*/views/'})
      ],
  },
  // ...
}

或者

# webpack.config.js
module.exports = {
  // ...
  plugins: [
    new webpackPluginAutoRouter({ pages: './src/pages/*/views/'})
  ],
  // ...
}

项目目录

.
├─assets
│  └─less
├─components
│  ├─charts
│  ├─count-to
│  └─info-card
├─i18n
├─lib
│  └─services
├─pages
│  ├─index
│  │  ├─components
│  │  │  └─common
│  │  ├─routes.js
│  │  ├─store
│  │  └─views
│  │      └─manage
│  │          └─word
│  └─login
│      └─views
└─store
    └─modules

indexlogin 分别是多页 pages 的单页目录,我们设置 pages: './src/pages/*/views/' 则可以匹配到 indexlogin, views是存放单页路由页面组件的目录

每个单页目录中 routes 是和 views 同级,生成的routes.js 文件应用 views的路由页面组件路径为 ./views/xxx.vue, 我们设置 importPrefix: './views'

支持 route-meta 标签

route-meta

动态生成 route 配置能否带上额外的meta配置,需要我们手动去添加支持 <route-meta> 标签的 loader

配置

{
  // ...
  module: {
    rules: [
      {
        resourceQuery: /blockType=route-meta/,
        loader: require.resolve('@kuaizi/vue-cli-auto-router/meta-loader.js')
      }
    ]
  }
  // ...
}

添加支持 <route-meta> 标签

使用

# index/views/manage/index.vue
<route-meta>
{
  "name": "manage-user-define",
  "sidebar": false
}
</route-meta>

<template>
  <Layout>
    <!-- more -->
  </Layout>
</template>

<route-meta> 包含一个 json 的内容, 其中 name字段会同步到 route.js 所在的路由配置

启动项目后生成文件index/routes.js

export default [
  //...
  {
    name: 'manage-user-define',
    path: '/manage',
    component: ManageIndex,
    meta: {
      "sidebar": false
    }
  }
  //...
]

vue-router direct

路由的跳转需要手动去添加

# index/main.js
// ...
import Router from '@/router'
import routes from './routes'
import App from './App'

// 定义跳转
routes.unshift({
  path: '/manage',
  redirect: '/manage/hello'
})

boostrap({ Router, Component: App, routes })