GithubHelp home page GithubHelp logo

x-oss-byte / nextjs-bundle-analysis Goto Github PK

View Code? Open in Web Editor NEW

This project forked from hashicorp/nextjs-bundle-analysis

0.0 0.0 1.0 336 KB

A github action that provides detailed bundle analysis on PRs for next.js apps

License: Mozilla Public License 2.0

JavaScript 100.00%

nextjs-bundle-analysis's Introduction

Next.js Bundle Analysis Github Action

Analyzes each PR's impact on your next.js app's bundle size and displays it using a comment. Optionally supports performance budgets.

screenshot of bundle analysis comment

Installation

It's pretty simple to get this set up, just run the following command and answer the prompts. The command will create a .github/workflows directory in your project root and add a next_bundle_analysis.yml file to it - that's all it takes!

$ npx -p nextjs-bundle-analysis generate

NOTE: Due to github actions' lack of support for more complex actions, the experience of getting this set up is unusual in that it requires a generation script which copies most of the logic into your project directly. As soon as github adds support for the features needed to properly package up this action, we'll put out an update that removes the extra boilerplate and makes usage much simpler. Until then, we all have no choice but to endure this unusual setup process.

Configuration

Config values are written to package.json under the key nextBundleAnalysis, and can be changed there any time. You can directly edit the workflow file if you want to adjust your default branch or the directory that your nextjs app lives in (especially if you are using a srcDir or something similar).

showDetails (boolean)

(Optional, defaults to true) This option renders a collapsed "details" section under each section of the bundle analysis comment explaining some of the finer details of the numbers provided. If you feel like this is not necessary and you and/or those working on your project understand the details, you can set this option to false and that section will not render.

buildOutputDirectory (string)

(Optional, defaults to .next) If your application builds to a custom directory, you can specify this with the key buildOutputDirectory. You will also need to replace all instances of .next in next_bundle_analysis.yml with your custom output directory.

For example, if you build to dist, you should:

  • Set package.json.nextBundleAnalysis.buildOutputDirectory to "dist".
  • In nextjs_bundle_analysis, replace all instances of .next with dist.

budget (number)

(Optional) The file size, in bytes, to budget for first page load size. For example, if budget was set to 358400 (350 KB) and a page's first load size was 248 KB, the report would list that page as having used 70% of the performance budget.

budgetPercentIncreaseRed (number)

(Optional, but required if budget is specified) If a page's first load size has increased more than budgetPercentIncreaseRed percent, display a ๐Ÿ”ด to draw attention to the change.

minimumChangeThreshold (number)

(Optional, defaults to 0) The threshold under which pages will be considered unchanged. For example, if minimumChangeThreshold was set to 500 and a page's size increased by 300 B, it will be considered unchanged.

skipCommentIfEmpty (boolean)

(Optional, defaults to false) When set to true, if no pages have changed size the generated comment will be an empty string.

Caveats

  • This plugin only analyzes the direct bundle output from next.js. If you have added any other scripts via the <script> tag, especially third party scripts and things like analytics or other tracking scripts, these are not included in the analysis. Scripts of this nature should probably be loaded in behind a consent manager and should not make an impact on your initial load, and as long as this is how you handle them it should make no difference, but it's important to be aware of this and account for the extra size added by these scripts if they are present in your app.
  • Since this plugin works by comparing the base bundle against each PR, the first time it is run, it will fail since it has no base to compare against. This is expected - ideally you can just commit the changes directly to your default branch, where it will run to generate the base bundle, then anything that branches off after that will have a valid comparison point and the script will work as expected.
  • This script assumes that running next build will successfully build your application. If you need additional scripts or logic to do so, you may need to update the action step called "Build next.js app" to the command needed to build your app. For example, if you have a npm run build step, that would be a good target to change it to. We plan to make this configurable via the generator in the future.

nextjs-bundle-analysis's People

Contributors

jescalan avatar dstaley avatar lunaticmuch avatar jzxhuang avatar alexcarpenter avatar dimamachina avatar tusbar avatar breadadams avatar isaachinman avatar jmfury avatar thiskevinwang avatar maxnowack avatar ssssota avatar github-actions[bot] avatar hashicorp-copywrite[bot] avatar

Forkers

renovate-bot

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.