Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
9 changes: 8 additions & 1 deletion packages/build/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@
"./vercel": {
"types": "./dist/adapter/vercel/index.d.ts",
"import": "./dist/adapter/vercel/index.js"
},
"./aws-lambda": {
"types": "./dist/adapter/aws-lambda/index.d.ts",
"import": "./dist/adapter/aws-lambda/index.js"
}
},
"typesVersions": {
Expand Down Expand Up @@ -74,6 +78,9 @@
],
"vercel": [
"./dist/adapter/vercel/index.d.ts"
],
"aws-lambda": [
"./dist/adapter/aws-lambda/index.d.ts"
]
}
},
Expand Down Expand Up @@ -103,4 +110,4 @@
"engines": {
"node": ">=18.14.1"
}
}
}
41 changes: 41 additions & 0 deletions packages/build/src/adapter/aws-lambda/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import type { Plugin } from 'vite'
import type { BuildOptions } from '../../base.js'
import buildPlugin from '../../base.js'
import { serveStaticHook } from '../../entry/serve-static.js'

export type AwsLambdaBuildOptions = {
staticRoot?: string | undefined
} & BuildOptions

const awsLambdaBuildPlugin = (pluginOptions?: AwsLambdaBuildOptions): Plugin => {
return {
...buildPlugin({
entryContentBeforeHooks: [
async (appName, options) => {
// eslint-disable-next-line quotes
let code = "import { serveStatic } from '@hono/node-server/serve-static'\n"
code += serveStaticHook(appName, {
filePaths: options?.staticPaths,
root: pluginOptions?.staticRoot,
})
return code
},
],
entryContentAfterHooks: [
async (appName) => {
// eslint-disable-next-line quotes
let code = "import { handle } from 'hono/aws-lambda'\n"
code += `export const handler = handle(${appName})\n`
return code
},
],
// To avoid `Runtime.UserCodeSyntaxError: SyntaxError: Cannot use import statement outside a module`,
// the output file is specified as .mjs.
output: 'index.mjs',
...pluginOptions,
}),
name: '@hono/vite-build/aws-lambda',
}
}

export default awsLambdaBuildPlugin