Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple Inputs with Vite

I'm having multiple inputs when building my app with vite. My config looks like this:

export default defineConfig({
  plugins: [
    react(),
    eslintPlugin()
  ],
  build: {
    rollupOptions: {
      input: {
        test1: resolve(__dirname, '/test1.html'),
        test2: resolve(__dirname, '/test2.html')
      }
    }
  }
});

The output looks like this:

dist
|-test1.html
|-test2.html
|-assets

What I actually want is something like this:

dist
|test1
  |-index.html
|test2
  |-index.html
|-assets

Is this possible?

Thanks

like image 511
Christian Avatar asked Mar 05 '26 02:03

Christian


2 Answers

You can use property names to define dest dirs (see docs)

...
: rollupOptions: {
    input: {
        'test1/index': resolve(__dirname, '/test1.html'),
        'test2/index': resolve(__dirname, '/test2.html')
    }
}
       
like image 160
Евгений Савин Avatar answered Mar 06 '26 17:03

Евгений Савин


The build output normally matches the directory structure of the input file, so in your case, you could move those files into the respective directories under the project root directory:

my-project/
 |- test1/
 | `- index.html
 `- test2/
   `- index.html

Then configure Vite's build.rollupOptions.input to point to those files:

// vite.config.js
import { defineConfig } from 'vite'
import { resolve } from 'path'

export default defineConfig({
  ⋮
  build: {
    rollupOptions: {
      input: {
        test1: resolve(__dirname, './test1/index.html'),
        test2: resolve(__dirname, './test2/index.html'),
      },
    },
  },
})

demo

like image 26
tony19 Avatar answered Mar 06 '26 16:03

tony19