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

@vuelify/vite-plugin-pages

v0.1.9

Published

Vite plugin for Vue that maps your page routes to the file system with easy over ride feature and layout configuration.

Downloads

8

Readme

Vuelify Pages

Vite plugin for Vue that maps your page routes to the file system with easy over ride feature and layout configuration.

I'm still working on a starter Vuelify template and it's not available publicly at the moment, but you can check out the live demo here

npm i @vuelify/vite-plugin-pages --save-dev

Initial Setup

// ./vite.config.ts

import { defineConfig } from 'vite';
import vue from '@vitejs/plugin-vue';
import Pages from '@vuelify/vite-plugin-pages';

export default defineConfig({
  plugins: [vue(), Pages()],
});
// ./src/routes.ts
import { fsRoutes } from 'virtual:vuelify-pages';
import { RouteRecordRaw, createRouter, createWebHistory } from 'vue-router';

const userRoutes: RouteRecordRaw[] = [];

const allRoutes = [...userRoutes, ...fsRoutes];

const routes = createRouter({
  history: createWebHistory(),
  routes: allRoutes,
});

export { routes };
// ./src/main.ts

import { createApp } from 'vue';
import App from './App.vue';
import { routes } from './routes';

createApp(App).use(routes).mount('#app');

Layout Setup

Inspired by Nuxt, just add the property to your page component

<!-- ./src/pages/index.vue -->
<template>
  <div>
    <h1>My Home Page</h1>
  </div>
</template>

<script lang="ts">
import { defineComponent } from 'vue';

export default defineComponent({
  // at run time the layouts will be added and the page will become a
  // a child route of the layout component.
  // If you don't specify this, default.vue will be used
  // If default.vue didn't exist in layout dir, Vue would throw an error
  layout: 'default',
  setup() {
    return {};
  },
});
</script>
<!-- ./src/layouts/default.vue -->

<template>
  <NavBar />
  <!-- the router view needs to exist so vue knows where to render the child components -->
  <router-view></router-view>
</template>

Extending Routes

The plugin accepts an extend option that is a function that receives the RouteObject as an argument. This can be used to alter any of the values in the route object by returning the desired values from this function.

Altering anything outside of the layout or meta values isn't a good idea unless you know what you're doing.

{
  extend: (route) => {
    const unauthenticated = ['Index', 'SignIn', 'SignUp'];

    if (unauthenticated.includes(route.name)) return {};

    return {
      meta: {
        auth: true,
      },
    };
  };
}

Ignoring Files

You can ignore specific files by placing them in the ignore array. If you have to files of the same name, but only want one to be ignored you can include the parent folder. This is useful when you want to still place pages in correct directly, but want to override the router with your own custom one.

{
  ignore: [':userSlug.vue', ':userSlug/settings.vue'];
}

Prerendering

This package can be used in conjunction with @vuelify/vite-plugin-prerender to pick and choose what routes you prerender.

COMING SOON

Options

pathToPages - the folder path for pages relative to your vite.config.ts file (default ./src/pages)

prerenderFolderName - the name of the folder containing your prerendered pages (default prerender)

prerender - when set to false turns off prerendering completely (default true)

layouts - disable layouts by setting this to false (default true)

pathToLayouts - This path is relative to your vite.config.ts (default ./src/layouts)

ignore - An array of file names to ignore in the FS system mapping (default [])

extend - Alter the route object manually eg. add meta data (default undefined)

Types

Add to vite-env.d.ts to get typings in your route file when using import { fsRoutes } from "virtual:vuelify-pages";

/// <reference types="@vuelify/vite-plugin-pages/client" />

To Do

  • HMR (At the moment you must manually restart the server when you change a pages layout. add/remove pages will automatically restart server)
  • Prerendering (At the moment this package will recognise what you want to prerender but @vuelify/cli & @vue/vite-plugin-prerender aren't completed, to have a play around with this feature see here )
  • Tests (More unit tests)
  • Catch All Route (At the moment you must configure a catch all route yourself)

Maintenance & Bugs

All @vuelify packages follow semantic versioning. There will be no breaking changes to the options the plugin accepts without major version upgrade. All the changes will happen under the hood.

I will be actively maintaining this package. If you'd like to help out with that, submit a pull request. If you find a bug, open an issue and I'll get to it ASAP.

This package only works with Vue & I have no intention of adding another framework any time soon.

It was designed to work best within the world of @vuelify and with typescript.