【Vite】index.htmlをビルドの出力から除外する
2024-9-11 | TypeScript, Vite
Viteでindex.htmlをビルドの出力から除外したい!
概要
今回の記事では、Viteでindex.htmlを出力から除外する手順を掲載する。
仕様書
環境
- Node.js 20.15.0
- npm 10.8.1
- vite 5.4.1
手順書
諸事情でViteのプロジェクトの中のindex.htmlが不要なったのでビルド時に出力されないようしてみた。
vite.config.tsのbuild:rollupOptions:inputにビルドするエントリーポイントを明示的に設定する。
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react-swc'
// https://vitejs.dev/config/
export default defineConfig({
plugins: [
react(),
],
build: {
rollupOptions: {
input: {
index: 'src/index.tsx',
},
},
}
})
これでnpm run buildの出力にindex.htmlは含まれなくなる。
ちなみにnpm run devでは前述の設定の影響を受けずindex.htmlが使用される。
まとめ(感想文)
デフォルトのエンポリーポイントを書き換えてるからindex.htmlが出力されないようになるんだと思われ。
