Next.js Builder (@now/next)

This builder takes a Next.js application, defined as pages, next.config.js and optionally a package.json file (with next, react, react-dom, etc), and converts them into a series of individual Lambdas.

It features built-in caching of node_modules and all the compiler artifacts for very fast deployments.

@now/next is the ideal way to ship a fast, production-ready Next.js application that scales automatically.

Create a pages directory with some example pages, for example pages/index.js:

export default () => (
  <div>
    Hello world!
  </div>
)

For this example, we won't define a package.json with our dependencies. We'll let the builder automatically install them. We'll create a simple next.config.js file to use as our entrypoint for the build

module.exports = () => ({})

Then we'll define our build step in now.json:

{
  "version": 2,
  "builds": [
    { "src": "next.config.js", "use": "@now/next" }
  ]
}

Upon deployment, we'll get a URL like this: https://next-js-deployment-kbbzal0ha.now.sh/

The entrypoint of this builder is a next.config.js file or a package.json file.

The installation algorithm of dependencies works as follows:

  • If a package-lock.json is present, npm install is used
  • Otherwise, yarn is used.

To install private npm modules, define NPM_TOKEN as a build environment in now.json.

The Node.js version used is the latest in the 8 branch.

To help keep cold boot times low, the maximum output bundle size for a Next.js ouput lambda is, by default, 5mb. This limit is extendable up to 50mb.

Example maxLambdaSize configuration:
{
  "builds": [
    { "src": "next.config.js", "use": "@now/next", "config": { "maxLambdaSize": "10mb" } }
  ]
}