11ty / eleventy-plugin-vite

A plugin to use Vite with Eleventy
140 stars 10 forks source link

Load vite.config.js for configuration #29

Open jakewhiteley opened 1 year ago

jakewhiteley commented 1 year ago

I'm not sure of the technical issues behind it, but it seems that if there were a way to grab and load up the vite server using the defineConfig export from a vite.config.js (if present) then it would get around issues such as #24 .

As it stands I personally had to abandon using this plugin as my plugin requirement and general Vite setup is quite complicated.

I ended up just running the Vite/11ty commands sequentially in my package.json (which works kinda but causes race condition issues).

KiwiKilian commented 5 months ago

With the new upcoming version (already available in alpha) you can use ESM and it's quite easy to load plugins within the .eleventy.js. What other requirements do you have, which would make using vite.config.js easier?

This plugins needs to overwrite some vite options to properly work (e.g. define the input files to your emitted HTML pages, set mode to MPA). So from my point of view, reading a vite.config.js would only help with types and interchangeability. But the current setup shouldn't prevent any functionality which would be enabled by loading an external config.

If you like you can already delcare your vite.config.js as you normally would:

import { defineConfig } from 'vite';

export default defineConfig({
// ...
});

And import this into your .eleventy.js:

import viteConfig from './vite.config.js';

/** @param { import('@11ty/eleventy/src/UserConfig') } eleventyConfig */
export default function (eleventyConfig) {
  eleventyConfig.addPlugin(EleventyVitePlugin, {
    viteOptions: viteConfig,
  });
}