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.
website/vite.config.js

45 lines
1.2 KiB
JavaScript

2 years ago
import { defineConfig } from 'vite'
import { join } from 'path'
2 years ago
import preactPlugin from '@preact/preset-vite'
import { getBuildRoutesMetadata } from './meta/routes.js'
2 years ago
/** @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()],
}
2 years ago
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,
2 years ago
},
},
}
} else {
return {
...sharedConfig,
server: {
port: 3000,
proxy: {
'/api': 'http://localhost:4000/',
2 years ago
},
},
}
2 years ago
}
})