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-indexify

v0.7.0

Published

Generate jsons that index all or some files output by vite.

Downloads

4

Readme

vite-plugin-indexify

Indexify is a plugin for vite that is used to generate index.json files amongst your output.

These files list all or some files in the output directory or subdirectories as entries in a json array.

This is useful for telling your front end what paths are available to fetch from.

Why

I wanted to create a simple static site generator and use some react components with remark. The components would ping the API for markdown data, then render it to the DOM. Using GitHub pages, I had no way to tell my front end what markdown files were available for it to ask for. Indexify solves that problem by giving me a single point where I can ask for information about what is available. Basically, it gives your front end a menu of options.

Indexify can help your front end find out

  • What text files are in some directory on the server
  • What image files are in some directory on the server
  • What subdirectories are in some directory on the server
  • What <insert file type> files are in some directory on the server

It works by waiting until vite/rollup output is finished, then reading the directory using fs.

Note I have not yet worked out how to generate the indexify bundles for the Vite live-reloading server. It will work for builds and previews, but not the live reload. I've been investigating, I need middleware function(s), but I haven't worked out how to do it. Open for PRs if anyone would like to assist.

Future Features

  1. Get it working on Vite dev server
  2. I'd like to be able to add additional information to the json entries, such as YAML front matter extracted from each file. You should be able to pass indexify a function that can take the file data as a parameter and generate additional fields for inclusion in the index entries.

Usage

Check out the example workspace for some usage.

The plugin takes an array as a parameter. If nothing is passed, by default, it will produce a file named 'index.json' for every subfolder in your output.

Each item in the array is an option for one or more index.jsons to be produced.

export default defineConfig({
	plugins: [
		indexify([
            {
                directory: "posts",
                recurse: true,
            },
        ]),
	],
    //...

The full option is as follows:

export interface IndexifyDirectoryOptions {
	/** The directory, relative to 'public', to indexify. */
	directory: string;
	/** The output file name. Defaults to 'index.json' */
	indexFileName?: string;
	/** Only filenames matching this pattern will be indexified. Defaults to all. */
	include?: RegExp;
	/** Filenames matching this pattern will not be indexified. Defaults to none. */
	exclude?: RegExp;
	/** Whether to recurse into and indexify subdirectories. They will have the same indexFileName. */
	recurse?: boolean;
	/* Whether to put an entry in the index for subdirectories or not. */
	includeSubdirectories?: boolean;
}