You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
45 lines
1.2 KiB
JavaScript
45 lines
1.2 KiB
JavaScript
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/',
|
|
},
|
|
},
|
|
}
|
|
}
|
|
})
|