LoginSignup
1
0

More than 3 years have passed since last update.

Viteでrobots.txtを公開する

Posted at

Viteでrobots.txtを公開する方法です。

本ページはReact + Typescriptのプロジェクトを作成した場合の例になります。

publicディレクトリーを作成してファイルを配置

:
├ my_app/
│ ├ dist/
│ ├ node_modules/
│ ├ public/
│ │ └ robots.txt
│ └ src/
:

vite.config.tsを編集

assetsInclude: ["robots.txt"]をコンフィグに追記します。
デフォルトではpublicディレクトリーを参照するようになっていますが、変更することもできます。

import { defineConfig } from "vite"
import reactRefresh from "@vitejs/plugin-react-refresh"

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [reactRefresh()],
  assetsInclude: ["robots.txt"],
})

確認

ローカル環境で確認するにはyarn devを実行してhttp://localhost:ポート番号/robots.txtrobots.txtの中身が表示されれば成功です。

補足

yarn buildを実行するとdistディレクトリーにファイルをコピーします。そのためdistディレクトリーにファイルがあるかどうかで確認することもできます。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0