New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

nextjs-lambda-webpack-plugin

Package Overview
Dependencies
Maintainers
2
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

nextjs-lambda-webpack-plugin

Webpack plugin that generates a AWS Lambda compatible package for NextJS

latest
Source
npmnpm
Version
0.1.3
Version published
Maintainers
2
Created
Source

NextJS Lambda webpack plugin

This plugin modifies a serverless NextJS build to add in a compatibility layer for AWS Lambda together with a handler that handles routing.

The standard handler reacts to Application Load Balancer events but it also has an alternative handler for API Gateway V2.

Warning: this is still early software and only supports SSR pages, static generation is still a work in progress

Usage

Add this plugin to your NextJS project as a dev dependency with either of the following commands:

# npm
npm install nextjs-lambda-webpack-plugin --save-dev

# yarn
yarn add -D nextjs-lambda-webpack-plugin

Next up add the plugin to your next.config.js:

const NextJSLambdaWebpackPlugin = require('nextjs-lambda-webpack-plugin')

const isServerless = (target) => target === ('serverless' || 'experimental-serverless-trace')

module.exports = {
    webpack: (config, options) => {
        if (config.mode === 'production' && isServerless(options.config.target)) {
            config.plugins.push(new NextJSLambdaWebpackPlugin(options))
        }
    }
}

After the build two folders will be available in the default dist_lambda/ build folder.

  • lambda/ contains the code and should be uploaded to a lambda function
  • assets/ contains the assets that should be uploaded to a S3 bucket

Note: To properly access static files, it's best to set an asset prefix to your s3 bucket

Setting the correct handler

The build exports two lambda handlers

  • index.handler is the default and should be invocated by an Application Load Balancer
  • index.ApiGatewayHandler is an alternative that can be invocated by Api Gateway V2

Thanks

A lot of the code has been made available by the serverless-next.js project, major thanks for all their work.

Keywords

aws

FAQs

Package last updated on 18 Nov 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts