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

v0.6.0

Published

A vite plugin to integrate with bruh

Downloads

10

Readme

vite-plugin-bruh - A vite plugin to integrate with bruh

Install

npm i -D vite-plugin-bruh or use npm init bruh with the vite template to quickly get started.

Use

Example vite.config.mjs file:

import { defineConfig } from "vite"
import bruh from "vite-plugin-bruh"

export default defineConfig({
  plugins: [
    bruh({
      // Regex for the page render file extention
      // Defaults to /\.html\.(mjs|jsx?|tsx?)$/
      htmlRenderFileExtention,
      // Absolute path of the root pages directory
      // Defaults to vite's root
      root,
      // Options for the MDX compiler (xdm)
      // Documentation at https://github.com/wooorm/xdm#compilefile-options
      // e.g. for adding syntax highlighting by setting to { rehypePlugins: [ await import("@mapbox/rehype-prism") ] }
      xdmOptions
    })
  ]
})

This allows you to use the typical vite for development and vite build for production. vite-plugin-bruh will automatically allow you to prerender html files before vite sees them.

Here is an example project structure:

.
├── index.css
├── index.html.jsx
├── index.mjs
├── package-lock.json
├── package.json
└── vite.config.mjs

How it works

Upon a page request for /x in dev:

  1. The x.html.mjs (or x/index.html.mjs, ...js/jsx/ts/tsx) file is imported
  2. The default export is called and awaited
  3. The returned string is exposed to vite as if it were from x.html (or x/index.html)

At build time, all x.html.mjs files are automatically included as entry points (as if they were x.html)

If this is index.html.mjs:

export default async () =>
`<!doctype html>
<html>
  <head>
    ...
  </head>

  <body>
    ...
  </body>
</html>
`

Vite sees this as if index.html existed and contained:

<!doctype html>
<html>
  <head>
    ...
  </head>

  <body>
    ...
  </body>
</html>

During dev, vite will automatically and quickly reload the page as index.html.mjs and its imports are edited.

JSX/TSX

This plugin automatically includes jsx support for bruh, meaning that you can freely write jsx content in both render files (x.html.jsx) and hydrate files (x.jsx, what vite typically handles).

Current Caveats

For MDX support, there is a workaround that replaces (in mdx files) any className strings with class. You probably won't run into that problem before it is fixed in a more correct way, but it can be solved by just writing "class" + "Name", "class\u004eame", class&#78;ame or something similar.