vite

In vite, is there a way to update the root html name from index.html


I'm trying to update an existing project to vite but i read in the docs Vite expects an index.html file to work from. Is there anyway to specify another file name from which vite should build? in my case main.html


Solution

  • The entry point is configured in build.rollupOptions.input:

    import { defineConfig } from 'vite'
    export default defineConfig({
      ⋮
      build: {
        rollupOptions: {
          input: {
            app: './index.html', // default
          },
        },
      },
    })
    

    You can change that to main.html, as shown below. When serving the app, you'll have to manually navigate to /main.html, but you could configure server.open to open that file automatically:

    import { defineConfig } from 'vite'
    
    export default defineConfig({
      ⋮
      build: {
        rollupOptions: {
          input: {
            app: './main.html',
          },
        },
      },
      server: {
        open: '/main.html',
      },
    })
    

    demo