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

vite-plugin-json5

v1.4.4

Published

Plugin for allowing .json5 and .jsonc files to be loaded.

Readme

Vite JSON5 (and JSONC) plugin

npm npm GitHub Workflow Status License GitHub Repo stars

A Vite plugin that wraps json5 to allow .json5 and .jsonc files to be loaded.

Installation

1. Install the package

# pnpm
pnpm add -D vite-plugin-json5

# yarn
yarn add -D vite-plugin-json5

# npm
npm install -D vite-plugin-json5

2. Add it to your Vite config

// vite.config.js
import json5Plugin from "vite-plugin-json5";
// or
import { json5Plugin } from "vite-plugin-json5";

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

3. Done

.json5 and .jsonc files can now be imported directly. They are parsed by the json5 package and transformed into standard JavaScript modules.

Options

This plugin accepts the same options as the default JSON parser, plus a dts option for automatic TypeScript type generation:

interface Json5Options {
    /**
     * Generate a named export for every property of the JSON object
     * @default true
     */
    namedExports?: boolean;
    /**
     * Generate performant output as JSON.parse("stringified").
     * Enabling this will disable namedExports.
     * @default false
     */
    stringify?: boolean;
    /**
     * Automatically generate TypeScript declarations for imported
     * JSON5/JSONC files. See the TypeScript types section below.
     */
    dts?:
        | boolean
        // Aggregated mode (default): all declarations in one file
        | { sidecar?: false; literals?: boolean; outFile?: string }
        // Sidecar mode: one .d.ts file next to each source file
        | { sidecar: true; literals?: boolean };
}

TypeScript types

[!NOTE] In Vite's dev server, type declarations are generated lazily — the file is written the first time a JSON5/JSONC module is actually requested. Open the page once and the file persists on disk across server restarts. Running vite build always generates types upfront.

Enable the dts option to have the plugin automatically generate TypeScript declarations for every JSON5/JSONC file you import. No more any — you get full type safety and autocompletion, inferred directly from the file's contents.

// vite.config.ts
json5Plugin({ dts: true });

There are two modes:


Aggregated mode (default) — all declarations are collected into a single file at node_modules/@types/__vite-plugin-json5__/index.d.ts. TypeScript picks this up automatically via its default type roots — no tsconfig.json changes needed. The file is already gitignored.

[!NOTE] If your tsconfig.json has an explicit "types" array (e.g. "types": ["vite/client"]), add "__vite-plugin-json5__" to it.


Sidecar mode — writes a .d.ts file next to each source file (e.g. config.json5.d.ts beside config.json5). TypeScript picks these up automatically via module resolution — no tsconfig.json changes needed.

Example:

src/
├── config.json5
├── config.json5.d.ts   ← generated
├── theme.jsonc
└── theme.jsonc.d.ts    ← generated

Enable it with sidecar: true and add the generated files to your .gitignore:

json5Plugin({ dts: { sidecar: true } });

Add the signature of the generated files to the git ignore to prevent them from being pushed to your repository:

*.json5.d.ts
*.jsonc.d.ts

Literal types — by default, values are widened to their primitive type (string, number, boolean). Pass literals: true to use exact literal types instead:

json5Plugin({ dts: { literals: true } });
// Without literals (default)
export declare const version: string;

// With literals: true
export declare const version: "1.0.0";

Custom output path (aggregated mode only) — change where the aggregated file is written using outFile, relative to the Vite root:

json5Plugin({ dts: { outFile: "src/types/json5.d.ts" } });

Contributing

A guide for setting up the development environment to allow for easy contributions.

This repo uses proto for toolchain management and moon as the task runner.

  1. Install proto by following the proto install guide. Then install the required tools (Node.js, pnpm, and moon) from the repo root:

    $ proto install
  2. Install dependencies:

    $ pnpm install
  3. Make changes

  4. Run tests

    $ moon run vite-plugin-json5:test
  5. Build when successful

    $ moon run vite-plugin-json5:build
  6. Run the playground to test the build

    $ moon run playground:dev