title: Vite - Multiple library entry points
body: <p>After a few hours, I managed to build my custom library with multiple entry points using vite.
  I want to know if there is a better way to solve this problem.</p>
  <pre><code>// vite.config.ts
  export default defineConfig({
    plugins: [react()],
    build: {
      rollupOptions: {
        input: {
          index: resolve(__dirname, 'src/index.ts'),
          hooks: resolve(__dirname, 'src/hooks.ts'),
        },
        external: [...Object.keys(peerDependencies), ...Object.keys(dependencies)],
        output: [
          {
            dir: resolve(__dirname, 'dist'),
            format: 'es',
            entryFileNames: &quot;[name].[format].js&quot;,
            globals: {
              react: 'React',
            },
          },
          {
            dir: resolve(__dirname, 'dist'),
            format: 'cjs',
            entryFileNames: &quot;[name].[format].js&quot;,
            globals: {
              react: 'React',
            },
          }
        ],
      },
      sourcemap: true,
    }
  })
  </code></pre>
  <p>The build generate this files:</p>
  <p><a href="https://i.stack.imgur.com/zZZDq.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/zZZDq.png" alt="bundle" /></a></p>