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-prisma-hmr

v0.0.8

Published

This Vite plugin monitors changes to your Prisma schema file and ensures that the Prisma client is regenerated seamlessly, without needing to restart your development server. It automatically shuts down the Prisma binary process and regenerates the Prisma

Downloads

2

Readme

Prisma HMR Plugin for Vite

This Vite plugin monitors changes to your Prisma schema file and ensures that the Prisma client is regenerated seamlessly, without needing to restart your development server. It automatically shuts down the Prisma binary process and regenerates the Prisma client whenever the schema is updated, providing a smooth development experience.

Installation

To install the plugin, add it to your project dependencies:

npm i -D vite-plugin-prisma-hmr
yarn add -D vite-plugin-prisma-hmr
pnpm add -D vite-plugin-prisma-hmr

Usage

To use the plugin in your Vite project, add it to your Vite configuration file (vite.config.js or vite.config.ts):

import { defineConfig } from "vite";
import prismaHmrPlugin from "vite-plugin-prisma-hmr";

export default defineConfig({
  plugins: [prismaHmrPlugin("binary", true)],
});

Configuration

The plugin accepts the following optional configuration parameters:

  • generator: Name of the generator that has engineType = 'binary'. It can be omitted if it's the only generator in the schema.
  • refresh: Boolean flag to enable invalidation of files that import @prisma/client. Default is false.

Requirements

For HMR to work with this plugin, you need to have a binary generator configured in your Prisma setup. This generator is necessary to regenerate the Prisma client when changes to the schema are detected.

Example of prisma schema

generator library {
  provider   = "prisma-client-js"
  engineType = "library"
}

generator binary {
  provider   = "prisma-client-js"
  engineType = "binary"
}

How It Works

  1. The plugin listens for changes to the prisma/schema.prisma file.
  2. When a change is detected, it kills any running Prisma binaries.
  3. It regenerates the Prisma client using the specified binary generator.
  4. If refresh is enabled, it invalidates all of the files that import @prisma/client package.

Refresh

Usually refresh isn't required but for one specific use case in typia you need it to be able to transform the code on changes in Comment Tags.

Additional steps

Update package.json to regenerate the right client on build / start of dev server.

{
  "dev": "pnpm generate:bin && vite",
  "build": "pnpm generate:lib && vite build",
  "generate:lib": "prisma generate --generator library",
  "generate:bin": "prisma generate --generator binary"
}

Disable typia cache because it uses source and id as key and neither change when prisma schema is changed.

export default defineConfig({
  plugins: [
    UnpluginTypia({
      cache: {
        enable: false,
      },
    }),
    prismaHmrPlugin("binary", true),
  ],
});