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

vite-robots-txt

v1.0.0

Published

Vite plugin to generate robots.txt with presets, per-bot rules, and dev mode blocking

Downloads

631

Readme

vite-robots-txt

NPM Version

Vite plugin to generate robots.txt and inject <meta name="robots"> tags — with presets, per-bot rules, and dev mode blocking.

Install

bun add -d vite-robots-txt
# or
npm install -D vite-robots-txt

Usage

// vite.config.ts
import { defineConfig } from 'vite';
import robotsTxt from 'vite-robots-txt';

export default defineConfig({
	plugins: [
		robotsTxt({ preset: 'allowAll' }),
	],
});

Presets

| Preset | Description | | ------------- | ---------------------------------------------------- | | allowAll | Allow all crawlers | | disallowAll | Block all crawlers | | blockAI | Allow search engines, block AI/LLM training crawlers | | searchOnly | Allow only major search engines |

Block AI crawlers

robotsTxt({ preset: 'blockAI' });

Generates:

# Allow all crawlers by default
User-agent: *
Allow: /

# Block AI/LLM training crawlers
User-agent: GPTBot
User-agent: ChatGPT-User
User-agent: Claude-Web
User-agent: ClaudeBot
User-agent: anthropic-ai
User-agent: Google-Extended
User-agent: PerplexityBot
User-agent: Bytespider
User-agent: CCBot
User-agent: Cohere-ai
User-agent: Amazonbot
User-agent: YouBot
Disallow: /

Custom policies

robotsTxt({
	policies: [
		{ userAgent: '*', allow: '/', disallow: ['/admin', '/api'] },
		{ userAgent: 'GPTBot', disallow: '/' },
	],
	sitemap: 'https://example.com/sitemap.xml',
});

Merge preset + custom rules

robotsTxt({
	preset: 'blockAI',
	policies: { userAgent: 'Baiduspider', disallow: '/', crawlDelay: 10 },
});

Meta robots tags

Inject <meta name="robots"> tags into your HTML for indexing control. Works alongside or independently from robots.txt.

Derive from preset

// Automatically generates <meta> tags matching the preset
robotsTxt({ preset: 'blockAI', meta: true });
// → <meta name="GPTBot" content="noindex, nofollow">
// → <meta name="ClaudeBot" content="noindex, nofollow">
// → ... (all 12 AI bots)

Global directives

// Single directive
robotsTxt({ meta: 'noindex' });
// → <meta name="robots" content="noindex">

// Multiple directives
robotsTxt({ meta: ['noindex', 'nofollow'] });
// → <meta name="robots" content="noindex, nofollow">

Per-bot tags

robotsTxt({
	meta: [
		{ content: ['index', 'follow'] }, // <meta name="robots" ...>
		{ name: 'GPTBot', content: 'noindex' }, // <meta name="GPTBot" ...>
		{ name: 'googlebot', content: 'max-image-preview:large' }, // <meta name="googlebot" ...>
	],
});

Combined: robots.txt + meta tags

robotsTxt({
	preset: 'blockAI',
	meta: true,
	sitemap: 'https://example.com/sitemap.xml',
});

Options

| Option | Type | Default | Description | | ---------- | ---------------------------------------------------------- | --------------- | ---------------------------------------- | | preset | 'allowAll' \| 'disallowAll' \| 'blockAI' \| 'searchOnly' | — | Start from a preset | | policies | PolicyRule \| PolicyRule[] | — | Custom policy rules | | meta | boolean \| string \| string[] \| MetaTag \| MetaTag[] | — | Inject <meta> robots tags into HTML | | sitemap | string \| string[] \| boolean | — | Sitemap URL(s) or true for auto-detect | | host | string | — | Yandex Host: directive | | fileName | string | 'robots.txt' | Output file name | | devMode | 'disallowAll' \| 'same' \| false | 'disallowAll' | Dev server behavior | | header | string | — | Comment at top of file |

PolicyRule

| Field | Type | Description | | ------------ | -------------------- | -------------------------------------- | | userAgent | string \| string[] | Bot name(s), '*' for all | | allow | string \| string[] | Paths to allow | | disallow | string \| string[] | Paths to disallow | | crawlDelay | number | Seconds between requests (Bing/Yandex) | | comment | string \| string[] | Comments above the rule group |

MetaTag

| Field | Type | Default | Description | | --------- | -------------------- | ---------- | ------------------------------ | | name | 'robots' \| string | 'robots' | Bot name or 'robots' for all | | content | string \| string[] | — | Meta directives |

Available meta directives

index, noindex, follow, nofollow, all, none, noarchive, nocache, nosnippet, noimageindex, max-snippet:N, max-image-preview:none|standard|large, max-video-preview:N

Dev mode

By default, the plugin serves a Disallow: / robots.txt during development to prevent indexing of your dev server. Set devMode: 'same' to serve the same config as production, or false to disable.

Standalone utilities

import { metaTagsToHtml, normalizeMeta, serialize } from 'vite-robots-txt';

// Generate robots.txt string
const txt = serialize({
	preset: 'blockAI',
	sitemap: 'https://example.com/sitemap.xml',
});

// Normalize meta input to MetaTag[]
const tags = normalizeMeta(true, 'blockAI');

// Convert to Vite HtmlTagDescriptor[]
const html = metaTagsToHtml(tags);

Exports

| Export | Description | | --------------------- | ---------------------------------------- | | robotsTxt (default) | Vite plugin factory | | serialize | Standalone robots.txt serializer | | normalizeMeta | Normalize meta input to MetaTag[] | | metaTagsToHtml | Convert MetaTag[] to Vite HTML tags | | AI_BOTS | Array of known AI crawler user-agents | | SEARCH_ENGINES | Array of major search engine user-agents | | presetPolicies | Preset policy definitions |

License

MIT