Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export async function staticPlugin<const Prefix extends string = '/prefix'>({
etag: useETag = true,
extension = true,
indexHTML = true,
bundleHTML = true,
decodeURI,
silent
}: StaticOptions<Prefix> = {}): Promise<Elysia> {
Expand Down Expand Up @@ -87,13 +88,13 @@ export async function staticPlugin<const Prefix extends string = '/prefix'>({
let pathName = normalizePath(path.join(prefix, relativePath))

if (isBun && absolutePath.endsWith('.html')) {
const htmlBundle = await import(absolutePath)
const htmlFile = bundleHTML ? (await import(absolutePath)).default : getFile(absolutePath)

app.get(pathName, htmlBundle.default)
app.get(pathName, htmlFile)
if (indexHTML && pathName.endsWith('/index.html'))
app.get(
pathName.replace('/index.html', ''),
htmlBundle.default
htmlFile
)

continue
Expand Down Expand Up @@ -233,13 +234,13 @@ export async function staticPlugin<const Prefix extends string = '/prefix'>({

let relativePath = absolutePath.replace(assetsDir, '')
const pathName = normalizePath(path.join(prefix, relativePath))
const htmlBundle = await import(absolutePath)
const htmlFile = bundleHTML ? (await import(absolutePath)).default : getFile(absolutePath)

app.get(pathName, htmlBundle.default)
app.get(pathName, htmlFile)
if (indexHTML && pathName.endsWith('/index.html'))
app.get(
pathName.replace('/index.html', ''),
htmlBundle.default
htmlFile
)
}
}
Expand Down
7 changes: 7 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,13 @@ export interface StaticOptions<Prefix extends string> {
*/
indexHTML?: boolean

/**
* @default true
*
* Enable bun bundle of *.html
*/
bundleHTML?: boolean

/**
* decodeURI
*
Expand Down