npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@joulev/analyse-client-components

v1.0.0

Published

Check whether a file is included in the client bundle or not for the Next.js App Router

Downloads

11

Readme

analyse-client-components

Check whether a file is included in the client bundle or not for the Next.js App Router. Only supports Next.js projects written with TypeScript!

npx @joulev/analyse-client-components@latest ./path/to/file...

From the root of the Next.js app (same folder as package.json), run the command for any files that are server components by default (e.g. layout.tsx and page.tsx files). You will get an output that looks like this (run on this file):

$ npx @joulev/analyse-client-components@latest src/app/\(public\)/\(home\)/page.tsx

  src/app/(public)/(home)/page.tsx
    src/lib/cn.ts
    src/app/(public)/(home)/page.module.css
    src/components/ui/card.tsx
      src/lib/cn.ts
|   src/components/ui/lists.tsx
|     src/lib/cn.ts
|     src/components/ui/hooks/use-hover-background.ts
|     src/types/utils.ts
    src/components/ui/link.tsx
      src/lib/cn.ts
|   src/components/ui/button.tsx
|     src/lib/cn.ts
|     src/components/ui/hooks/use-hover-background.ts
|     src/components/ui/link.tsx
|       src/lib/cn.ts
    src/app/(public)/(home)/get-github-readme.ts
      src/app/(public)/(home)/octokit.ts
        src/env.mjs
    src/app/(public)/(home)/music-data.tsx
      src/env.mjs
      src/app/(public)/(home)/metadata-card.tsx
|       src/components/ui/button.tsx
|         src/lib/cn.ts
|         src/components/ui/hooks/use-hover-background.ts
|         src/components/ui/link.tsx
|           src/lib/cn.ts
    src/app/(public)/(home)/github-stats.tsx
      src/app/(public)/(home)/octokit.ts
        src/env.mjs
      src/app/(public)/(home)/metadata-card.tsx
|       src/components/ui/button.tsx
|         src/lib/cn.ts
|         src/components/ui/hooks/use-hover-background.ts
|         src/components/ui/link.tsx
|           src/lib/cn.ts

Files starting with the | are imported to at least one file with "use client" hence will be added to the client bundle. Other files are not added to the client bundle.

For example in the above, since src/lib/cn.ts has at least one entry with the |, it is available in the client bundle for src/app/(public)/(home)/page.tsx, whlie src/app/(public)/(home)/music-data.tsx doesn't have any entries with the |, the logic in that file stays in the server.

Installation and usage

Run directly with npx and similar commands (recommended)

As shown above, you can run it directly with

npx @joulev/analyse-client-components@latest ./path/to/file...
# or yarn dlx or pnpx

Install globally

npm install -g @joulev/analyse-client-components

# then
analyse-client-components ./path/to/file...
# or
acc ./path/to/file...

Install locally

npm install --save-dev @joulev/analyse-client-components

then add the CLI to package.json scripts:

{
  "scripts": {
    "acc": "acc"
    // other scripts, like "build": "next build"
  }
}

then run npm run acc or similar commands.

npm run acc -- ./path/to/file...

Programmatical usage

No.

Only use this as a CLI tool.

Notes

This is a project I finished in like one hour or two. It is very minimal and assumes the user uses it exactly according to the guide above (namely, it is run in the root of the Next.js app, it references a file that Next.js treats as a server component by default). There is no error handling here, I made this mainly for my own use so I'm too lazy to add sufficient error handlings. So yes, this tool could work but also could blow up if you use it in any ways not described in the guide above.