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-plugin-pages-solid

v0.0.2

Published

File system based routing for Vite + Solid

Downloads

5

Readme

vite-plugin-pages-solid

npm npm bundle size npm Codecov GitHub branch checks state CodeFactor GitHub

File system based routing for Solid applications using Vite

This is a kind of fork of vite-plugin-pages for Vue, but if I was about to add a Solid implementation to it, I will break a lot of things. Hence, it should be a good thing to create a new repository for it.

⚠️ Expect a lot of breaking changes, until at least 0.5.x

Getting Started

Solid

Install:

npm install -D vite-plugin-pages-solid
npm install solid-app-router

Add to your vite.config.js:

import { defineConfig } from 'vite';
import { solid } from 'vite-plugin-solid';
import pages from 'vite-plugin-pages-solid';

export default defineConfig({
  plugins: [solid(), pages()],
});

Overview

By default a page is a Solid component exported from a .jsx, .js, .ts or .tsx file in the src/pages directory.

You can access the generated routes by importing the virtual:generated-pages-solid module in your application.

Solid

import { useRoutes } from 'solid-app-router';
import routes from 'virtual:generated-pages-solid';

const Routes = useRoutes(routes);

<Routes {routes} />

Type

// vite-env.d.ts
/// <reference types="vite-plugin-pages-solid/client" />

File System Routing

Inspired by the routing from NuxtJS 💚

Basic Routing

Pages will automatically map files from your pages directory to a route with the same name:

  • src/pages/users.jsx -> /users
  • src/pages/users/profile.jsx -> /users/profile
  • src/pages/settings.jsx -> /settings

Index Routes

Files with the name index are treated as the index page of a route:

  • src/pages/index.jsx -> /
  • src/pages/users/index.jsx -> /users

Dynamic Routes

Dynamic routes are denoted using square brackets. Both directories and pages can be dynamic:

  • src/pages/users/[id].jsx -> /users/:id (/users/one)
  • src/pages/[user]/settings.jsx -> /:user/settings (/one/settings)

Any dynamic parameters will be passed to the page as props. For example, given the file src/pages/users/[id].jsx, the route /users/abc will be passed the following props:

{ "id": "abc" }

Nested Routes

We can make use of Solid router child routes to create nested layouts. The parent component can be defined by giving it the same name as the directory that contains your child routes.

For example, this directory structure:

src/pages/
  ├── users/
  │  ├── [id].jsx
  │  └── index.jsx
  └── users.jsx

Catch-all Routes

Catch-all routes are denoted with square brackets containing an ellipsis:

  • src/pages/[...all].jsx -> /*all (/non-existent-page)

The text after the ellipsis will be used both to name the route, and as the name of the prop in which the route parameters are passed.

Configuration

To use custom configuration, pass your options to Pages when instantiating the plugin:

// vite.config.js
import pages from 'vite-plugin-pages-solid';

export default {
  plugins: [
    pages({
      // Defaults to src/pages
      pagesDir: 'src/views',
    }),
  ],
};

pagesDir

  • Type: string
  • Default: 'src/pages'

Relative path to the pages directory. DOES NOT supports globs.

Can be:

  • single path: routes point to /

extensions

  • Type: string[]
  • Default: ['js', 'jsx', 'ts', 'tsx']

An array of valid file extensions for pages.

exclude

  • Type: string[]
  • Default: []

An array of string (not globs) patterns to exclude matches.

# folder structure
src/pages/
  ├── users/
  │  ├── components
  │  │  └── form.js
  │  ├── [id].jsx
  │  └── index.jsx
  └── home.jsx
// vite.config.js
export default {
  plugins: [
    Pages({
      exclude: ['.js'],
    }),
  ],
};

importMode

  • Type: "sync" | "async"
  • Default: "async"

Lets you choose whether to import everything dynamically or not.

License

MIT