vite-plugin-aws-lambda

raw JSON →
1.0.4 verified Mon Apr 27 auth: no javascript

Vite plugin that simplifies building AWS Lambda functions by configuring Vite for library mode: defaults output to ES modules with .mjs extension, externalizes all Node.js built-in modules, and optionally zips the output directory into a Lambda-ready deployment package. Current version 1.0.4 requires Vite >=5.2.7. Key differentiators: zero-config setup for Vite users, handles common Lambda packaging tasks (externalization, zip) automatically, and ships TypeScript types. Release cadence appears low; no major breaking changes documented yet.

error Error: ""vite-plugin-aws-lambda"" transforms are not supported.
cause Using the plugin without specifying a library entry in build.lib.
fix
Set build.lib.entry in your Vite config.
error TypeError: lambda is not a function
cause Named import instead of default import: import { lambda } from 'vite-plugin-aws-lambda'.
fix
Use default import: import lambda from 'vite-plugin-aws-lambda'.
error Module not found: Error: Can't resolve 'vite-plugin-aws-lambda'
cause Missing dependency or incorrect package name.
fix
Run npm install vite-plugin-aws-lambda --save-dev.
gotcha Plugin must be placed last in the plugins array to avoid issues with other plugins modifying build config.
fix Ensure lambda() is the last item in the plugins array.
gotcha Relative paths in outFilename are resolved from config.outDir, not config.root.
fix Use absolute or outDir-relative paths for outFilename.
deprecated If using older Vite <5.2.7, the plugin will not work due to peer dependency requirement.
fix Upgrade Vite to >=5.2.7 or use an older version of the plugin (if available).
breaking No breaking changes documented yet; future versions may change default zip behavior.
fix Review changelog before upgrading.
npm install vite-plugin-aws-lambda
yarn add vite-plugin-aws-lambda
pnpm add vite-plugin-aws-lambda

Minimal Vite config integrating the plugin with a library entry for AWS Lambda deployment.

// vite.config.ts
import { defineConfig } from 'vite';
import lambda from 'vite-plugin-aws-lambda';

export default defineConfig({
  plugins: [lambda({
    outFilename: 'my-function.zip',
    quiet: false,
  })],
  build: {
    lib: {
      entry: 'src/lambda.ts',
    },
  },
});