Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

edge-ssr: bundle next/dist as ESM for better tree-shaking (#40251) #40980

Merged
merged 1 commit into from Sep 28, 2022

Commits on Sep 28, 2022

  1. edge-ssr: bundle next/dist as ESM for better tree-shaking (vercel#40251)

    Edge SSR'd routes cold boot performances are proportional to the
    executed code size.
    
    In order to improve it, we are trying to optimize for the bundle size of
    a packed Edge SSR route.
    
    This PR adds ESM compilation targets for all Next.js dist packages and
    use them to bundle Edge SSR'd route.
    
    This allows us to leverage the better tree shaking/DCE for ESM modules
    in webpack in order to decrease the overall bundle size.
    
    This PR also enables minifying Edge SSR routes. Since we don't control
    which minifier might be used later (if any), it's best if we provide an
    already optimised bundle.
    
    <img width="903" alt="image"
    src="https://user-images.githubusercontent.com/11064311/190005211-b7cb2c58-a56a-44b0-8ee4-fd3f603e41bd.png">
    
    This is a 10ms cold boot win per my benchmarking script, which I'll put
    in a subsequent PR.
    
    Not done yet:
    - ~~swap exported requires in `next/link` (and others) etc to point them
    to the esm modules version~~
    
    <!--
    Thanks for opening a PR! Your contribution is much appreciated.
    In order to make sure your PR is handled as smoothly as possible we
    request that you follow the checklist sections below.
    Choose the right checklist for the change that you're making:
    -->
    
    - [ ] Related issues linked using `fixes #number`
    - [ ] Integration tests added
    - [ ] Errors have helpful link attached, see `contributing.md`
    
    - [x] Implements an existing feature request or RFC. Make sure the
    feature request has been accepted for implementation before opening a
    PR.
    - [ ] Related issues linked using `fixes #number`
    - [ ] Integration tests added
    - [ ] Documentation added
    - [ ] Telemetry added. In case of a feature if it's used or not.
    - [ ] Errors have helpful link attached, see `contributing.md`
    
    - [ ] Make sure the linting passes by running `pnpm lint`
    - [ ] The examples guidelines are followed from [our contributing
    doc](https://github.com/vercel/next.js/blob/canary/contributing.md#adding-examples)
    
    Co-authored-by: JJ Kasper <jj@jjsweb.site>
    Co-authored-by: Shu Ding <g@shud.in>
    3 people committed Sep 28, 2022
    Configuration menu
    Copy the full SHA
    b0c59e2 View commit details
    Browse the repository at this point in the history