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

@octamap/bundle-raw

v1.0.3

Published

A plugin for bundling .raw imports

Readme

Bundle Raw

Bundle Raw is a Vite plugin that enhances HTML imports by automatically bundling and injecting JavaScript module dependencies found in <script type="module" src="..."> tags. This allows you to treat .html?raw imports as module-aware entry points in both development and production environments.


✨ Features

  • 📦 Transforms raw HTML imports into dynamic module bundles.
  • 🔍 Parses and rewrites HTML to inject generated JS chunks.
  • 🧠 Handles virtual module resolution and chunk mapping internally.
  • 🛠️ Works in both development (vite dev) and production (vite build) modes.
  • 🧽 Cleans up original <script> tags and replaces them with consolidated imports.

🚀 Install

npm install @octamap/bundle-raw --save-dev

Note: Replace the install command with the actual package name once published to npm.


🛠 Usage

In your vite.config.ts:

import { defineConfig } from 'vite';
import { BundleRaw } from '@octamap/bundle-raw';

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

Now when you import an HTML file with ?raw, the plugin will automatically:

  1. Parse the HTML and look for <script type="module" src="..."> tags.
  2. Bundle those scripts into a virtual module.
  3. Replace the original script tags with a new <script type="module"> tag that points to the generated bundle.

📁 Example

// main.ts
import htmlContent from './index.html?raw';
document.body.innerHTML = htmlContent;
<!-- index.html -->
<body>
  <script type="module" src="./foo.js"></script>
  <script type="module" src="./bar.js"></script>
</body>

This gets transformed to something like:

<body>
  <script type="module" src="/assets/index-bundle-raw.js"></script>
</body>

Where /assets/index-bundle-raw.js contains:

import "./foo.js";
import "./bar.js";

⚙ How It Works

  • During Transform:

    • Converts HTML-in-JS back to HTML using @octamap/html-js-convert.
    • Uses @octamap/cheerio-body to locate module script tags.
    • Extracts and resolves relative paths.
    • Generates a virtual JS chunk importing all those scripts.
    • Rewrites the original HTML with a new <script> referencing the chunk.
  • During Build:

    • Replaces placeholders with actual final asset paths after chunk hashing.
  • Virtual Modules:

    • Handled internally and resolved using resolveId and load.

🔍 Dev vs Build

| Mode | Behavior | | ---------- | ---------------------------------------------------------------------- | | Dev | Uses timestamped /virtual: paths for hot reload and freshness. | | Production | Outputs real chunks to /assets/ with stable naming and hashed paths. |


🧪 Caveats

  • Only processes HTML imports that:
    • End in .html?raw
    • Contain <script type="module" src="..."> tags.
  • Will not affect inline scripts or non-module scripts.
  • Avoid using dynamic paths in script src attributes.

📦 Dependencies


📝 License

MIT – Happy bundling!