NuxtJS module for robots.txt
A Nuxt.js module that injects a middleware to generate a robots.txt file
robots.txt
for static moderobots.txt
@nuxtjs/robots
dependency to your projectyarn add @nuxtjs/robots # or npm install @nuxtjs/robots
@nuxtjs/robots
to the modules
section of nuxt.config.js
export default {
modules: [
// Simple usage
'@nuxtjs/robots',
// With options
['@nuxtjs/robots', { /* module options */ }]
]
}
export default {
modules: [
'@nuxtjs/robots'
],
robots: {
/* module options */
}
}
String
robots.config
Object|Array
{
UserAgent: '*',
Disallow: ''
}
If you need to use function in any rule, you need to create a config file through the configPath
option
export default [
{ UserAgent: '*' },
{ Disallow: '/' },
{ BlankLine: true },
{ Comment: 'Comment here' },
// Be aware that this will NOT work on target: 'static' mode
{ Sitemap: (req) => `https://${req.headers.host}/sitemap.xml` }
]
output:
User-agent: *
Disallow: /
# Comment here
Sitemap: https://robots.nuxtjs.org/sitemap.xml
User-agent
Crawl-delay
Disallow
Disavow
Allow
Host
Sitemap
Clean-param
# Comment
Add blank line
Note: Don't worry, keys are parsed with case insensitivity and special characters.
You can contribute to this module online with CodeSandBox:
Or locally:
pnpm install
pnpm dev:prepare
pnpm build
pnpm dev
Copyright (c) - Nuxt Community