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

closure-calculate-chunks

v3.1.1

Published

Analyze dependencies from entry points and split code for closure-compiler

Downloads

757

Readme

closure-calculate-chunks

A utility to parse JS files, determine dependencies and specify which output chunk source files appear in for closure-compiler. Uses node module resolution and determines split points from dynamic import statements.

Usage:

npx closure-calculate-chunks --entrypoint ./src/js/entry.js

Flags

--entrypoint path/toFile
Required flag. Initial entrypoint to the application. This flag may occur multiple times, but the first usage will be the true entrypoint and is where the language polyfills will be injected by closure-compiler. All other entrypoints will have a dependence on the first entrypoint.

--manual-entrypoint path/to/parent/chunk:path/to/entrypoint
Add a custom entrypoint for code that is not discoverable.

--closure-library-base-js-path path/to/google-closure-library/closure/goog/base.js
Path to closure-library's base.js file. This flag is only needed for projects which include Closure-Library style dependencies.

--deps-file path/to/closure/deps.js
Path to a Closure-Library style deps.js file. This flag may occur multiple times. This flag is only needed for projects which include Closure-Library style dependencies.

--extra-deps namespace:path/to/providing/src
Provided namespace and filepath for a Closure-Library style namespace. This flag may occur multiple times. This flag is only needed for projects which include Closure-Library style dependencies and for namespaces which are not found in a deps.js file.

--package-json-entry-names field1,field2,...
Ordered list of entries to look for in package.json files when resolving modules. Defaults to "browser,module,main".

--visualize
Instead of outputting the closure compiler flags, open an HTML page to visualize the graph.

--naming-style [entrypoint, numbered]
How the name of a chunk is determined. For "entrypoint", chunk names are derived from the imported file name. For "numbered", the entrypoint is named "main" and child chunks are numeric indexes.

--name-prefix prefix
Prefix string prepended to each chunk name.

Output

Outputs a JSON object with closure-compiler chunk definitions and source files in dependency order.

{
  "chunk": [
    "baseChunkName:numFiles",
    "childChunkName:numFiles:baseChunkName"
  ],
  "js": [
    "file1.js",
    "file2.js"
  ]
}

Why Sources End Up in Other Chunks

Closure Compiler will not duplicate code. If a source file is utilized in more than one output chunk, this utility will hoist the file up into the lowest common ancestor which is common to all paths.