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 🙏

© 2026 – Pkg Stats / Ryan Hefner

ssr-tools

v0.0.40

Published

A collection of tools to use in SSR rendering

Readme

ssr-tools

Some tools to use in SSR-rendered apps, designed primarily around islands, vite, and a next-style file router.

Using vite:

import preact from '@preact/preset-vite'
import { islands, fileRouter, client } from 'ssr-tools'

defineConfig({
   plugins: [
      preact(),
      islands(),
      fileRouter(),
      client(),
   ],
   build: {
      ssr: true 
   }
})

Plugins

islands()

Import components as islands with a simple import:

import { ComplexComponent } from './button.ts?island'

// basic props are automatically serialised and a client-side bundle is 
// added to the manifest, with only the used island components
<ComplexComponent name={'my-component'} />

By default this works with Preact only, but the provider interface is simple enough that you can build one yourself for other frameworks (see Preact example). Just pass in your provider in vite.config.ts:

islands({
   provider: {
     ssr: {
       name: 'name-of-export',
       importFrom: 'path/that/resolves/to/ssr/wrapper',
       importNamed: true || false
     },
     bundle: ({ imports, variables, code }) => `
       // client bundle content goes here
     `
   }
})

client()

Import anything directly into the client bundle:

import './client.ts?client'

fileRouter()

A Next-style file router. To start, add the plugin and define a route:

vite.config.ts

defineConfig({
   plugins: [
      fileRouter({
      	  // default options
         dir: 'src/pages',
         glob: '**/*.{ts,tsx,js,jsx}',
         removeTrailingSlash: true
      }),
   ],
   build: {
      ssr: true 
   }
})

src/pages/[slug].tsx


export default function page(ctx) {
   return `<html>
      <body>
         <h1>${ctx.params.slug}</h1>
      </body>
   </html>`
}

Then add the file router middleware to your server:

import http from 'node:http'
import { fileRouterMiddleware } from 'ssr-tools'

const fileRouter = await fileRouterMiddleware()
const app = http.createServer((req, res) => {
   fileRouter(req, res, () => res.end())
})
app.listen(port)	
	

Supported filename patterns:

| File name | Route pattern | Matching paths | | :-- | :-- | :-- | | /index.ts | /| / | | /about.ts | /about| /about | | /books/[slug].ts | /books/:slug| /books/foo /books/bar | | /books/[slug]/reviews | /blog/:slug/reviews| /blog/foo/reviews| | /api/[...all].ts | /api/*all| /api/search /api/docs/foo /api/docs/bar|

ctx

Context is an object passed to each route handler, with the following properties:

| Property | Description | Example/usage | | :-- | :-- | :-- | | params | Any route params from request | { slug: 'hello-world' } | | path | The relative path to the requested page | /blog/hello-world | | query | URLSearchParams object | query.get('category') |

Static rendering

To render static pages, Export a build object to your route:

src/pages/[slug].tsx


export default build = {
   // return an iterable, and a page will be generated for each entry
   from: () => await getPages()
   
   // specify your url params
   // (`props` is each entry from the `from` function)
   url: props => ({
      slug: slugify(props.title)
   })
}

// render the content from `ctx.props`
export default function page(ctx) {
   return `<html>
      <body>
         <h1>${ctx.props.title}</h1>
      </body>
   </html>`
}

Still to complete

  • Custom handlers for GET/HEAD/POST/PUT/DELETE/OPTIONS/PATCH
  • Web-standard Request/Response arguments in all middleware and route handlers
  • FormData handling
  • Set props for single pages in build.props
  • Route path override for custom routes
  • Render statically-generated pages from middleware
  • Ability to render routes outside of Vite
  • Multi-platform support
  • And more…

Contributing

Contributions welcome!

Acknowledgements

islands plugin adapted from vite-plugin-voie, and barelyhuman's preact-island-plugins.