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

@vocoder/plugin

v0.21.0

Published

Build plugin for Vocoder — injects translations as virtual modules at build time

Downloads

417

Readme

@vocoder/plugin

Build plugin for Vocoder. Works with Vite, Next.js, Webpack, Rollup, and esbuild.

Installation

npm install @vocoder/plugin

Setup

Vite

// vite.config.ts
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
import vocoder from '@vocoder/plugin/vite'

export default defineConfig({
  plugins: [react(), vocoder()],
})

Next.js

// next.config.ts
import { withVocoder } from '@vocoder/plugin/next'
import type { NextConfig } from 'next'

const nextConfig: NextConfig = {}

export default withVocoder(nextConfig)

Webpack

// webpack.config.js
const { VocoderPlugin } = require('@vocoder/plugin/webpack')

module.exports = {
  plugins: [new VocoderPlugin()],
}

Rollup

// rollup.config.js
import vocoder from '@vocoder/plugin/rollup'

export default {
  plugins: [vocoder()],
}

esbuild

import { build } from 'esbuild'
import { vocoderPlugin } from '@vocoder/plugin/esbuild'

await build({
  plugins: [vocoderPlugin()],
})

Configuration

| Option | Type | Default | Description | |---|---|---|---| | localesDir | string | 'locales' | Path to locale files, relative to process.cwd() | | verbose | boolean | false | Log manifest loading details during build | | preview | boolean | false | Build in preview mode — SDK shows source text and disables locale switching |

vocoder({ localesDir: 'src/locales', verbose: true })

How It Works

The plugin performs three tasks at build time:

1. Injects the locale manifest

Reads localesDir/manifest.json and injects its contents as __VOCODER_MANIFEST__ — a compile-time constant the SDK reads to determine available locales, the source locale, and per-locale metadata (RTL flag, currency code, ordinal forms).

2. Generates a virtual locale loader

Intercepts @vocoder/react/locale-loader at build time and replaces it with a generated module containing a static switch statement:

// Generated at build time — one case per locale file found in localesDir
export async function loadLocale(locale) {
  switch (locale) {
    case 'en': return import('/abs/path/locales/en.json').then(m => m.default ?? m)
    case 'es': return import('/abs/path/locales/es.json').then(m => m.default ?? m)
    case 'fr': return import('/abs/path/locales/fr.json').then(m => m.default ?? m)
    default:   return {}
  }
}

Static string imports allow every bundler to analyze them and split each locale into its own lazy chunk. Only the active locale is loaded at runtime — the others are fetched on demand when the user switches.

Without the plugin, @vocoder/react/locale-loader resolves to a stub that returns {}.

3. Transforms JSX

Transforms natural <T> syntax into explicit message, values, and components props:

// You write:
<T>Hello {name}!</T>
<T>Read <a href="/docs">the docs</a> for help.</T>

// Plugin transforms to:
<T message="Hello {name}!" values={{ name }}>Hello {name}!</T>
<T message="Read <0>the docs</0> for help." components={[<a href="/docs" />]}>
  Read <a href="/docs">the docs</a> for help.
</T>

Injected Constants

| Constant | Type | Description | |---|---|---| | __VOCODER_MANIFEST__ | LocaleManifest \| null | Contents of localesDir/manifest.json. null when the file is missing. | | __VOCODER_PREVIEW__ | boolean | true when built with preview: true. |


locales/ Directory

The plugin reads locale files from localesDir. These files are committed to your repository by the Vocoder GitHub Action after each translation run.

locales/
  manifest.json     # Locale config — written by vocoder CLI
  en.json           # Source locale translations { hash: text }
  es.json           # Target locale translations
  fr.json

License

MIT