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

@deijose/vite-plugin-nix-js

v1.0.0

Published

Vite plugin for Nix.js with Hot Module Replacement and full state preservation (signals, stores, routers, forms)

Readme

@deijose/vite-plugin-nix-js

Vite plugin for Nix.js that adds Hot Module Replacement (HMR) with state, scroll, and focus preservation.

Requirements

  • Vite ^8.0.0
  • @deijose/nix-js ^2.5.3

Installation

npm install -D @deijose/vite-plugin-nix-js
# or
pnpm add -D @deijose/vite-plugin-nix-js
# or
yarn add -D @deijose/vite-plugin-nix-js

Usage

// vite.config.ts
import { defineConfig } from "vite";
import nix from "@deijose/vite-plugin-nix-js";

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

No extra configuration is required.

What it does

  • Hot-reloads components without a full page refresh.
  • Preserves state of module-scoped stores, routers, forms, and signals.
  • Preserves scroll position and the currently focused element.
  • Works automatically — no manual import.meta.hot wrapping needed.

How it works

The plugin transforms source files at build time to wrap stable calls with a small runtime module:

| Call | Wrapped to | |------|------------| | signal(...) | __nixGetOrCreateSignal(id, factory) | | createForm(...) | __nixGetOrCreateForm(id, factory) | | createStore(...) | __nixGetOrCreateStore(id, factory) | | createRouter(...) | __nixGetOrCreateRouter(id, factory) | | mount(...) | __nixMount(id, factory, ...) |

For example, this developer-written code:

import { signal } from "@deijose/nix-js";
import { createForm } from "@deijose/nix-js/form";

const count = signal(0);
const form = createForm({ name: "" });
const cart = createStore({ items: [] }, { name: "cart" });
const router = createRouter(routes);
mount(App(), "#app", { router });

is transformed into:

import { __nixGetOrCreateSignal, __nixGetOrCreateForm, __nixGetOrCreateStore, __nixGetOrCreateRouter, __nixMount, __nixHmrAccept } from "@deijose/vite-plugin-nix-js/runtime";

const count = __nixGetOrCreateSignal("src/main.ts:count", () => signal(0));
const form = __nixGetOrCreateForm("src/main.ts:form", () => createForm({ name: "" }));
const cart = __nixGetOrCreateStore("src/main.ts:cart", () => createStore({ items: [] }, { name: "cart" }));
const router = __nixGetOrCreateRouter("src/main.ts:router", () => createRouter(routes));
__nixMount("src/main.ts", () => App(), "#app", { router });

if (import.meta.hot) {
  import.meta.hot.accept((newModule) => {
    __nixHmrAccept(newModule, "src/main.ts");
  });
}

The runtime keeps a global singleton on window.__nixHmrRuntime that re-uses existing stores, routers, and application mounts, while unmounting and re-mounting the changed component and restoring scroll/focus.

Supported cases

  • Multiple mount points in the same file.
  • Mount assigned to a variable (const handle = mount(...)) as well as bare mount(...) statements.
  • Module-scoped signals, forms, stores, and routers.
  • Named exports and aliased imports.
  • TypeScript annotations, as, satisfies and parenthesized expressions.
  • Async components (mount(await loadApp(), "#app")).

Signals, forms, stores, and routers declared inside functions are intentionally left untouched, so they still produce a fresh instance on each call.

Common patterns

Keep state at module scope so it is preserved across updates:

import { signal, html } from "@deijose/nix-js";

// ✅ Preserved
const count = signal(0);

function Counter() {
  return html`<button @click=${() => count.update((v) => v + 1)}>${() => count.value}</button>`;
}

Avoid declaring state inside the component if you want it to survive HMR:

function Counter() {
  // ❌ Reset on every update
  const count = signal(0);
  return html`<button @click=${() => count.update((v) => v + 1)}>${() => count.value}</button>`;
}

For class components, store shared state in a module-scoped createStore or signal.

Known limitations

  • NixComponent class instance state (private properties set in onInit/onMount) is not preserved across HMR updates.
  • HMR is module-granular: when a file changes, every mount point declared in that file is re-mounted.
  • Only module-scoped signal, createForm, createStore, createRouter, and mount calls are tracked; declarations nested inside functions are left untouched.

Development

cd vite-plugin-nix
npm install
npm run typecheck
npm run build

License

MIT