vite-plugin-robots
raw JSON → 1.0.5 verified Mon Apr 27 auth: no javascript
Vite plugin for generating robots.txt files with separate configurations for production and development builds. Current stable version is 1.0.5, released with a consistent cadence. Key differentiator: it allows you to define different robots.txt rules based on build mode by reading `.robots.[mode].txt` or `.robots.[mode].txt.local` files from the project root, making it easy to block crawlers in development and allow them in production without manual file swapping.
Common errors
error SyntaxError: Unexpected token '.' ↓
cause Using CommonJS `require` to import ESM-only package (Vite plugins are ESM).
fix
Use
import { robots } from 'vite-plugin-robots' instead of const { robots } = require('vite-plugin-robots'). error Error: robots is not a function ↓
cause Default import instead of named import.
fix
Change to
import { robots } from 'vite-plugin-robots'. error Error: The plugin 'robots' does not provide a valid function ↓
cause Passing an object instead of calling the function in plugins array.
fix
Use
robots({...}) in the plugins array, not just robots. Warnings
gotcha Plugin only reads files named `.robots.[mode].txt` or `.robots.[mode].txt.local` from project root; custom paths not supported. ↓
fix Place your robots.txt files in the project root with the correct naming convention.
deprecated As of v1.0.0, the option `skip` has been removed; use a falsy config to disable the plugin. ↓
fix Remove `skip` property from config; instead omit the plugin or set `false` conditionally.
breaking From v0.x to v1.0.0, the import changed from default to named export. ↓
fix Change `import robots from 'vite-plugin-robots'` to `import { robots } from 'vite-plugin-robots'`.
gotcha Plugin does not merge multiple robots.txt files; it only outputs one per build mode. ↓
fix Ensure you have only one set of `.robots.*.txt` files or combine rules manually.
Install
npm install vite-plugin-robots yarn add vite-plugin-robots pnpm add vite-plugin-robots Imports
- robots wrong
import robots from 'vite-plugin-robots'correctimport { robots } from 'vite-plugin-robots' - type Plugin
import type { Plugin } from 'vite' - defineConfig
import { defineConfig } from 'vite'
Quickstart
import { robots } from 'vite-plugin-robots'
import { defineConfig } from 'vite'
export default defineConfig({
plugins: [
robots({
// Optional: override default file names or disable
})
]
})
// Create .robots.production.txt in project root:
// User-agent: *
// Allow: /
// Sitemap: https://example.com/sitemap.xml
// Create .robots.development.txt in project root:
// User-agent: *
// Disallow: /