|
|
|
import { defineConfig } from 'vite'
|
|
|
|
import { join } from 'path'
|
|
|
|
import preactPlugin from '@preact/preset-vite'
|
|
|
|
import { getBuildRoutesMetadata } from './meta/routes.js'
|
|
|
|
|
|
|
|
/** @type {import('vite').UserConfig} */
|
|
|
|
const sharedConfig = {
|
|
|
|
// all files processed by ViteJS are inside this folder
|
|
|
|
root: './frontend',
|
|
|
|
// for now the only plugin is Preact
|
|
|
|
plugins: [preactPlugin()],
|
|
|
|
}
|
|
|
|
|
|
|
|
export default defineConfig(async config => {
|
|
|
|
if (config.command === 'build') {
|
|
|
|
const routes = await getBuildRoutesMetadata('out/routes.json')
|
|
|
|
|
|
|
|
const allHtmlEntrypoints = [...Object.values(routes.static), ...Object.values(routes.dynamic)].map(file =>
|
|
|
|
join(__dirname, 'frontend', file)
|
|
|
|
)
|
|
|
|
|
|
|
|
console.dir(allHtmlEntrypoints)
|
|
|
|
|
|
|
|
return {
|
|
|
|
...sharedConfig,
|
|
|
|
build: {
|
|
|
|
outDir: '../out/frontend',
|
|
|
|
rollupOptions: {
|
|
|
|
input: allHtmlEntrypoints,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return {
|
|
|
|
...sharedConfig,
|
|
|
|
server: {
|
|
|
|
port: 3000,
|
|
|
|
proxy: {
|
|
|
|
'/api': 'http://localhost:4000/',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|