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

@log1997/vite-plugin-console

v0.1.1

Published

A Vite plugin that rewrites console.log with custom styles in development mode.

Readme

@log1997/vite-plugin-console

A Vite plugin that overrides console.log with dynamic CSS styles driven by type prefixes inside the log message (e.g. [info], [warn], [error]). Dev-mode only.

Features

  • 🏷️ Type-prefix detectionconsole.log('[error] 服务器挂了') automatically picks the error style
  • 🎨 Configurable palette — map any type string (info, warn, error, success, debug …) to custom CSS
  • 🔤 Global prefix — prepend a shared label (e.g. 🎯) before every log line
  • 🔒 Dev-only — runtime guard checks NODE_ENV; zero cost in production
  • 📦 ESM + CJS + .d.ts — built with tsup

Installation

pnpm add -D @log1997/vite-plugin-console

Usage

// vite.config.ts
import { defineConfig } from 'vite';
import { vitePluginConsole } from '@log1997/vite-plugin-console';

export default defineConfig({
  plugins: [
    vitePluginConsole({
      prefix: '🎯',
      defaultStyles:
        'color: #333; background: #e0e0e0; padding: 2px 8px; border-radius: 4px;',
      typeStyles: {
        info:    'color: #0d6efd; background: #cfe2ff; font-weight: bold;',
        warn:    'color: #664d03; background: #fff3cd; border: 1px solid #ffc107;',
        error:   'color: #842029; background: #f8d7da; border: 1px solid #f5c2c7; font-weight: bold;',
        success: 'color: #0f5132; background: #d1e7dd;',
      },
    }),
  ],
});

Then in your app code:

console.log('[info] 用户已登录');       // → blue style
console.log('[warn] 磁盘空间不足');      // → yellow style
console.log('[error] 服务器无响应');     // → red style
console.log('普通日志');                 // → default gray style

Configuration

| Option | Type | Default | Description | | --------------- | --------------------------------------------- | ------------------------------------------ | ----------------------------------------------- | | enable | boolean | true | Enable / disable the plugin. | | prefix | string | '' | Global label prepended to every log. | | defaultStyles | string \| { prefix?, message? } | built-in blue palette | Fallback style when no type prefix matches. | | typeStyles | Record<string, string \| { prefix?, message? }> | {} | Per-type style overrides (case-sensitive). | | logLevel | 'log' \| 'warn' \| 'error' | 'log' | Which console method to override. |

Style object form

Both defaultStyles and each typeStyles entry accept an object with separate prefix and message keys to style the type tag and message body independently:

typeStyles: {
  error: {
    prefix:  'background: #dc3545; color: #fff; padding: 2px 6px; border-radius: 4px 0 0 4px;',
    message: 'background: #f8d7da; color: #842029; padding: 2px 6px; border-radius: 0 4px 4px 0;',
  },
}

Built-in default style

When defaultStyles is omitted the plugin uses:

color: #00a8ff; font-weight: bold; background: #f0f8ff;
padding: 2px 6px; border-radius: 4px;

How It Works

The plugin injects a small <script> at the end of <body> via Vite's transformIndexHtml hook. That script:

  1. Saves a reference to the original console.log.
  2. On each call, checks if the first argument starts with [word] .
  3. Looks up the captured word in the typeStyles map.
    • Found → applies the mapped CSS.
    • Not found → falls back to defaultStyles (or the built-in palette).
  4. If the first argument is not a string, the default style is used as well.
  5. The global prefix (if set) is rendered before everything with its own style.

Everything runs only when NODE_ENV === 'development' and enable is true.

License

MIT