-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathvite.config.ts
84 lines (78 loc) · 2.71 KB
/
vite.config.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import build from '@hono/vite-build/cloudflare-workers'
import devServer from '@hono/vite-dev-server'
import cloudflareAdapter from '@hono/vite-dev-server/cloudflare'
import { defineConfig } from 'vite'
import fs from 'fs'
import path from 'path'
import tailwindcss from '@tailwindcss/vite'
// Helper function to get page entries
function getPageEntries() {
const pagesDir = './plugins/interface/pages'
const entries: Record<string, string> = {}
if (fs.existsSync(pagesDir)) {
const folders = fs
.readdirSync(pagesDir, { withFileTypes: true })
.filter((dirent) => dirent.isDirectory())
folders.forEach((folder) => {
const indexPath = path.join(pagesDir, folder.name, 'index.tsx')
if (fs.existsSync(indexPath)) {
entries[folder.name] = indexPath
}
})
}
return entries
}
export default defineConfig(({ mode }) => {
if (mode === 'client') {
return {
build: {
rollupOptions: {
input: getPageEntries(),
output: {
entryFileNames: 'assets/[name].[hash].js',
chunkFileNames: 'assets/[name].[hash].js',
assetFileNames: 'assets/[name].[hash][extname]',
manualChunks: {
vendor: ['hono/jsx', 'hono/jsx/dom/client'],
components: [
'./plugins/interface/components/button/Button',
'./plugins/interface/components/input/Input',
'./plugins/interface/components/card',
'./plugins/interface/components/avatar',
],
},
},
},
outDir: './public',
copyPublicDir: true,
emptyOutDir: false,
manifest: true,
},
plugins: [tailwindcss()],
publicDir: './plugins/interface/public',
resolve: {
alias: {
'@interface': path.resolve(
__dirname,
'./plugins/interface'
),
},
},
}
}
const entry = './src/index.ts'
return {
assetsInclude: ['**/*.sql'],
server: { port: 8787 },
plugins: [
devServer({ adapter: cloudflareAdapter, entry }),
build({ entry }),
tailwindcss(),
],
build: {
rollupOptions: {
external: ['cloudflare:workers'],
},
},
}
})