serverless-next.js icon indicating copy to clipboard operation
serverless-next.js copied to clipboard

🚧 feat: add `build.outputStandalone` option

Open iiroj opened this issue 3 years ago • 4 comments

This is an experimental Work-In-Progress PR for adding support for the new experimental.outputStandalone setting introduced in Next.js 12 https://github.com/vercel/next.js/pull/31003

There's a new minimal next-handler Lambda that currently doesn't support any of the existing serverless-nextjs features.

The build process is also very simple:

  1. build Next.js with experimental.outputStandalone: true
  2. copy entire .next/standalone as the default-lambda
  3. remove the included .next/standalone/server.js
  4. emit new handler, which creates a Next.js NextServer and handles the lambda request

What do you think @dphang ? How should we integrate this into the existing stack? Should we make a completely new lambda, or maybe a setting into the default-handler that uses this new file instead of importing pages and using their render method?

iiroj avatar Feb 05 '22 08:02 iiroj

Handler Size Report

No changes to handler sizes.

Base Handler Sizes (kB) (commit e31d928e5ceaf093b3eea74420fce49b4cb816d7)

{
    "Lambda": {
        "Default Lambda": {
            "Standard": 1524,
            "Minified": 668
        },
        "Image Lambda": {
            "Standard": 1488,
            "Minified": 800
        }
    },
    "Lambda@Edge": {
        "Default Lambda": {
            "Standard": 1534,
            "Minified": 673
        },
        "Default Lambda V2": {
            "Standard": 1526,
            "Minified": 670
        },
        "API Lambda": {
            "Standard": 634,
            "Minified": 318
        },
        "Image Lambda": {
            "Standard": 1496,
            "Minified": 805
        },
        "Regeneration Lambda": {
            "Standard": 1187,
            "Minified": 546
        },
        "Regeneration Lambda V2": {
            "Standard": 1253,
            "Minified": 573
        }
    }
}

New Handler Sizes (kB) (commit 76f9b532b262c30bd981425650293d462c2ba3f8)

{
    "Lambda": {
        "Default Lambda": {
            "Standard": 1524,
            "Minified": 668
        },
        "Image Lambda": {
            "Standard": 1488,
            "Minified": 800
        }
    },
    "Lambda@Edge": {
        "Default Lambda": {
            "Standard": 1534,
            "Minified": 673
        },
        "Default Lambda V2": {
            "Standard": 1526,
            "Minified": 670
        },
        "API Lambda": {
            "Standard": 634,
            "Minified": 318
        },
        "Image Lambda": {
            "Standard": 1496,
            "Minified": 805
        },
        "Regeneration Lambda": {
            "Standard": 1187,
            "Minified": 546
        },
        "Regeneration Lambda V2": {
            "Standard": 1253,
            "Minified": 573
        }
    }
}

slsnextbot avatar Feb 05 '22 08:02 slsnextbot

Codecov Report

Merging #2333 (76f9b53) into master (d009f46) will decrease coverage by 0.40%. The diff coverage is 66.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2333      +/-   ##
==========================================
- Coverage   83.55%   83.14%   -0.41%     
==========================================
  Files         102      103       +1     
  Lines        3679     3709      +30     
  Branches     1176     1186      +10     
==========================================
+ Hits         3074     3084      +10     
- Misses        593      613      +20     
  Partials       12       12              
Impacted Files Coverage Δ
packages/libs/lambda-at-edge/src/next-handler.ts 0.00% <0.00%> (ø)
...rless-components/nextjs-component/src/component.ts 86.15% <75.00%> (-0.21%) :arrow_down:
packages/libs/lambda-at-edge/src/build.ts 92.67% <81.08%> (-3.41%) :arrow_down:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update d009f46...76f9b53. Read the comment docs.

codecov[bot] avatar Feb 05 '22 08:02 codecov[bot]

This is an experimental Work-In-Progress PR for adding support for the new experimental.outputStandalone setting introduced in Next.js 12 vercel/next.js#31003

There's a new minimal next-handler Lambda that currently doesn't support any of the existing serverless-nextjs features.

The build process is also very simple:

  1. build Next.js with experimental.outputStandalone: true
  2. copy entire .next/standalone as the default-lambda
  3. remove the included .next/standalone/server.js
  4. emit new handler, which creates a Next.js NextServer and handles the lambda request

What do you think @dphang ? How should we integrate this into the existing stack? Should we make a completely new lambda, or maybe a setting into the default-handler that uses this new file instead of importing pages and using their render method?

Maybe it can be a new lambda if it’s different? Not too familiar with the new handler yet, haven’t kept up with all new features unfortunately…

dphang avatar Feb 08 '22 05:02 dphang

Looking forward to this feature, thanks to @iiroj works! For now, Tim is removing target: 'serverless' in nextJS, so it's better we have another way deploying it!

jinqian1998 avatar Mar 23 '22 04:03 jinqian1998

Looking forward to this feature, thanks to @iiroj works! For now, Tim is removing target: 'serverless' in nextJS, so it's better we have another way deploying it!

Hi! Using the code provided here you managed to deploy the NextJS app using standalone output?

nike1v avatar Aug 04 '23 20:08 nike1v

HI @iiroj ! Are you using this solution right now? Or you found a way to deploy Next 12/13 in other way? Thanks.

nike1v avatar Aug 04 '23 20:08 nike1v

Hello @nike1v , we have abandoned this effort and went with Vercel... would look into OpenNext maybe: https://open-next.js.org/

iiroj avatar Aug 06 '23 19:08 iiroj