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

@wakamejs/vite

v0.1.2

Published

Vite plugin for inserting semantic wbr elements with Wakame

Readme

@wakamejs/vite

Wakame を利用して HTML 内の日本語テキストに意味的な <wbr> 要素を自動挿入する Vite プラグインです。

画面幅に応じた自然な日本語の折り返しを実現し、スマートフォンやレスポンシブデザインにおける可読性を向上させます。

特徴

  • 構文木解析による安全な HTML 変換: parse5 を用いて HTML を解析し、テキストノードに対してのみ正確に <wbr> を挿入します。
  • 除外要素の自動スキップ: code, pre, script, style, textarea など、改行を挿入すべきでない要素は自動的にスキップされます。
  • CSS スタイルの自動適用: 対象ブロック要素に word-break: keep-all; overflow-wrap: break-word; をインラインスタイルとして付与(オプションで無効化可能)。
  • HTML 変換関数のエクスポート: Vite プラグインとしてだけでなく、スタンドアロンの transformHtml 関数としても使用可能。

インストール

pnpm add -D @wakamejs/vite @wakamejs/sudachi @wakamejs/core
# または
npm install -D @wakamejs/vite @wakamejs/sudachi @wakamejs/core
# または
yarn add -D @wakamejs/vite @wakamejs/sudachi @wakamejs/core

使い方

vite.config.ts での設定

@wakamejs/sudachi と組み合わせて使用する設定例です:

import { defineConfig } from "vite";
import wakame from "@wakamejs/vite";
import { createSudachiTokenizer } from "@wakamejs/sudachi";

export default defineConfig(async () => {
    const tokenizer = await createSudachiTokenizer({
        grouping: "bunsetsu",
        kinsoku: true,
    });

    return {
        plugins: [
            wakame({
                tokenizer,
                applyWrapStyle: true,
            }),
        ],
    };
});

プログラマティックな利用 (transformHtml)

Vite プラグインを介さずに、HTML 文字列を直接変換することも可能です。

import { createWakame } from "@wakamejs/core";
import { createSudachiTokenizer } from "@wakamejs/sudachi";
import { transformHtml } from "@wakamejs/vite";

const tokenizer = await createSudachiTokenizer({
    grouping: "bunsetsu",
    kinsoku: true,
});
const wakame = createWakame({ tokenizer });

const inputHtml = "<h1>美味しいお茶を飲みました。</h1>";
const outputHtml = await transformHtml(inputHtml, wakame, true);
console.log(outputHtml);
// => <h1 style="word-break: keep-all; overflow-wrap: break-word;">美味しい<wbr>お茶を<wbr>飲みました。</h1>

API リファレンス

wakamePlugin(options) (デフォルトエクスポート)

Vite の transformIndexHtml(order: "post")フックで動作する Vite プラグインを作成します。

オプション (WakamePluginOptions)

| オプション | 型 | デフォルト値 | 説明 | | :--------------- | :------------------ | :----------- | :-------------------------------------------------------------------------------------------------------------- | | tokenizer | Tokenizer<string> | 必須 | テキスト分割を行うトークナイザー実装 | | dictionary | DictionaryInput | undefined | トークナイザーに渡すカスタム辞書 | | applyWrapStyle | boolean | true | true の場合、変換対象要素に word-break: keep-all; overflow-wrap: break-word; をインラインスタイルとして付与 |

transformHtml(html, wakame, shouldApplyWrapStyle?, options?)

指定された HTML 文字列内のテキストをトークナイズし、<wbr> タグを挿入した HTML 文字列を返します。

引数

  • html: 変換対象の HTML 文字列
  • wakame: createWakame から返される Wakame インスタンス
  • shouldApplyWrapStyle: スタイルを付与するかどうか(デフォルト: true)
  • options: TransformHtmlOptions
    • preserveExistingWbr: 既存の <wbr> を保持するかどうか。false を指定すると既存の <wbr> を除去してから再計算します。

対応環境

  • Node.js: >= 20
  • Vite: ^7.0.0 || ^8.0.0

関連パッケージ

ライセンス

MIT