@basenative/favicon

中文文档
3.3.0发布于 2026/11/03Apache-2.0TypeScriptES Module零依赖构建来源已验证近 30 天下载 2111

SVG-first favicon generator + design primitives — apple-touch-icon, maskable, manifest, and the right tags for every DuganLabs project

原始使用文档
文档目录9 节
  1. The brand rule: SVG primary, raster only when iOS demands it
  2. <head> snippet
  3. CLI
  4. Programmatic API
  5. Presets
  6. Designing a new preset
  7. Test it at 16×16
  8. Modules
  9. License

@basenative/favicon

SVG-first favicon generator + design primitives for every DuganLabs project.

@basenative/favicon is the BaseNative answer to "yet another generic favicon." It produces a polished, distinct SVG mark for any project — plus the supporting apple-touch-icon, maskable, web app manifest, and the right <link> tags to drop into <head>. Pure SVG primary; PNG only when iOS or Android need it.

pnpm add -D @basenative/favicon

PNG fallbacks (apple-touch-icon.png, maskable.png, etc.) need @resvg/resvg-wasm, declared as an optionalDependency — most installs get it for free. If your install skips optional dependencies (--no-optional or similar) and you want PNGs, add it explicitly:

pnpm add -D @resvg/resvg-wasm

The brand rule: SVG primary, raster only when iOS demands it

Every modern browser (Chrome, Edge, Firefox, Safari ≥ 16) renders <link rel="icon" type="image/svg+xml"> natively, including in browser tabs. Use it. Save the PNG churn for the platforms that genuinely require it:

  • favicon.svg — the primary, served to every browser.
  • apple-touch-icon.png (180×180) — iOS home-screen.
  • icon-192.png / icon-512.png — Android Chrome.
  • maskable.png (512×512) — Android adaptive icons (with the 80% safe zone baked in).
  • favicon.ico — optional belt-and-suspenders for very old browsers; we don't generate it but the <head> snippet references it as an alternate.

<head> snippet

<link rel="icon" type="image/svg+xml" href="/favicon.svg">
<link rel="alternate icon" href="/favicon.ico">
<link rel="apple-touch-icon" href="/apple-touch-icon.png">
<link rel="mask-icon" href="/favicon.svg" color="#0C0B09">
<link rel="manifest" href="/manifest.json">
<meta name="theme-color" content="#0C0B09">

You don't need to memorize any of that — htmlTags() and defineFavicon().htmlTags() emit the strings for you.

CLI

# Interactive — picks a preset, writes public/favicon.svg + manifest + (optional) PNGs.
bn-favicon init

# Non-interactive, idempotent (asks before overwriting unless --force):
bn-favicon init --preset tabs --out public

# Render a preset to stdout:
bn-favicon render basenative > public/favicon.svg

# Print the recommended <head> tags:
bn-favicon html --theme-color "#0C0B09"

# List presets:
bn-favicon list

If @resvg/resvg-wasm is installed, init also writes apple-touch-icon.png, icon-192.png, icon-512.png, and maskable.png. Without it, you get the SVG-only set — which is fine for most sites until you decide you care about iOS home-screen icons — and the CLI prints one line telling you what's missing and how to install it.

By default the manifest's name/short_name use the preset's display name (e.g. basenative → "BaseNative"). Pass --name to override, or use defineFavicon(...).manifest({ name: ... }) programmatically.

Programmatic API

import { defineFavicon } from "@basenative/favicon";

const fav = defineFavicon({
  glyph: { kind: "monogram", text: "T", weight: 900, accentDot: true },
  palette: { bg: "#0C0B09", fg: "#FFF3E0", accent: "#E8920A" },
  shape: "rounded",
});

fav.svg;          // <svg>…</svg> — primary asset
fav.apple;        // square variant (no rounding) for iOS rasterization
fav.maskable;     // 80% safe-zone variant for Android adaptive icons
fav.htmlTags();   // string[] — drop into <head>
fav.manifest({ name: "T4BS", themeColor: "#0C0B09" });   // JSON

You can also pass a preset name directly:

defineFavicon("basenative");   // → uses the BaseNative house mark

Presets

Eight DuganLabs projects ship pre-built. Use them, fork them, or roll your own.

PresetGlyphShapeAccent
tabsmonogram T + accent dotrounded#E8920A
basenativesigil — concentric trianglesrounded#E8920A
duganlabsmonogram DLshield#E8920A
pendingbusinesssymbol — clockrounded#4EAF7C
greenputsymbol — leafcircle#4EAF7C
warrenduganmonogram W / D stacksquircle#E8920A
ralph-stationsigil — station markdiamond#5EA0E8
warren-syssymbol — terminal promptsquare#66E0A0

Every preset is rendered to a static SVG under templates/favicons/<preset>.svg so you can cp directly into your public/ if you don't want to install the runtime:

cp node_modules/@basenative/favicon/templates/favicons/tabs.svg public/favicon.svg

Designing a new preset

A preset is just an object:

export const myproject = {
  name: "myproject",
  description: "A one-line description for CLI help",
  glyph: { kind: "monogram", text: "MP", weight: 900, letterSpacing: -28 },
  palette: { bg: "#0C0B09", fg: "#F0EDE4", accent: "#E8920A" },
  shape: "rounded",
  themeColor: "#0C0B09",
};

The recipe — three knobs:

  1. Glyph kind

    • monogram — 1-3 letters. Knobs: text, weight, letterSpacing, stack, accentDot.
    • symbol — pick from the curated set: lightbulb, leaf, bolt, key, eye, asterisk, gear, terminal-prompt, calendar, beaker, clock, anchor.
    • sigil — abstract marks: concentric-square, intersecting-circles, hex-grid, signal-stack, station-mark.
    • wordmark — short word (≤ 8 chars) in a heavy condensed face.
  2. Palette — pass { bg, fg, accent }, or a single hex (treated as the accent, paired with the house charcoal). The fg is auto-derived from the bg luminance if omitted.

  3. Shape — square, rounded, circle, squircle, shield, or diamond. The shape clip-paths the glyph, so you can drop a square monogram into a circle shape and the corners get trimmed cleanly.

Test it at 16×16

The whole point is to look great as a browser tab favicon. Render the SVG into a <link rel="icon"> and look at the tab. If it reads as a solid blob, simplify — fewer strokes, more contrast.

Modules

PathWhat it is
@basenative/faviconPublic API: defineFavicon, htmlTags, presets.
@basenative/favicon/renderrenderFaviconSvg, shape, maskable + apple variants.
@basenative/favicon/glyphsGlyph library — monogram, symbol, sigil, wordmark.
@basenative/favicon/paletteColor helpers — resolvePalette, mix, luminance.
@basenative/favicon/manifestWeb App Manifest builder.
@basenative/favicon/pngOptional PNG rasterizer (optional dep: @resvg/resvg-wasm).
@basenative/favicon/presetsDuganLabs preset map.

License

Apache-2.0 © DuganLabs. Built with BaseNative — basenative.dev.

版本与发布记录

@basenative/favicon 共发布 14 个版本,首次发布于 2026/10/18;过去 12 个月发布了 14 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
3.3.0latest2026/11/035 天前
3.2.02026/11/035 天前
3.1.02026/11/017 天前
3.0.02026/10/317 天前
2.4.02026/10/2613 天前
2.3.22026/10/2217 天前

关于 @basenative/favicon 的常见问题

@basenative/favicon 是什么?

SVG-first favicon generator + design primitives — apple-touch-icon, maskable, manifest, and the right tags for every DuganLabs project

如何安装 @basenative/favicon?

在项目目录运行 npm install @basenative/favicon,或使用 pnpm add / yarn add / bun add。它还提供命令行工具 bn-favicon,可以用 npx bn-favicon 直接运行。

@basenative/favicon 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@basenative/favicon 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@basenative/favicon 可以商用吗?

@basenative/favicon 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@basenative/favicon 的下载量有多少?

根据 npm 官方下载统计,@basenative/favicon 在 2026/10/08 – 2026/11/06 这 30 天内被下载 2,111 次,日均约 70 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@basenative/favicon 还在维护吗?

最新版本 3.3.0 发布于 2026/11/03(5 天前);至今共发布 14 个版本,其中过去 12 个月发布了 14 个;首次发布于 2026/10/18。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。