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

clay-build-js

v0.0.7

Published

Build JS for your Clay components.

Downloads

17

Readme

clay-build-js

Build JS for your Clay components.

Installation

npm install --save clay-build-js

Usage

Clay-cli

clay build-js

Programmatic

const buildJs = require('clay-build-js');

buildJs({
  // defaults
  watch: false,
  debug: false,
  verbose: false
})

What this does:

  • For each component's model and component JS file, creates a corresponding Javascript chunk file in public/js using browserify-splitter. These chunks can be combined arbitrarily by resolve-media within the context of a bundle.
  • Exported JS is minified using uglify and transpiled using Babel.
  • Exports client-env.json, which is an array of all env vars used

Options

  • watch: Boolean. Default: false. Watch for changes.
  • verbose: Boolean. Default: false. Log all files written.
  • debug: Boolean. Default: false. Disable bundle-collapser and uglifyify, allowing for easier debugging and faster builds.
  • preBundle: Function. Receives the Browserify bundler as the first argument and runs before bundling. Allows you to add additional dependencies, transforms, and plugins.
  • babelConf: Object. Configuration object for Babel.

Advanced Explanation

Usually, the JavaScript that any page needs is known beforehand, by the developer. For example, you might include a homepage.js script on your homepage and a section.js script on your section pages.

In Clay, a page is made up entirely of arbitrary data -- components. Some components need client-side JavaScript. Any page could theoretically have any combination of components.

So how do we get all the client.js that a page needs on to the page itself? The solution should:

  • Be scalable. It should work with hundreds of components. So we can't simply include all of our client-side Javascript on all of our pages.
  • Be performant on the server. The server shouldn't have to do a lot of legwork to generate pages with the right JS.
  • Be performant on the client. The client shouldn't have to perform dozens of asynchronous requests to fetch missing JS. The code should be minified.
  • Be convenient for devs. Devs shouldn't have to wait long to see their changes compiled.
  • Enables universal code. That means some require should work client-side and ES6 should be transpiled to ES5.

Clay-build-js resolves all these issues. It scans your Clay installation for component JS, traces their dependencies, and arranges those dependencies into a bundle via Browserify, but splits that bundle into separate chunks using browserify-splitter. It also extracts a dependency registry with browserify-extract-registry, transpiles to ES5 using Babel, and uglifies.

When Clay generates a page, it detects the components that a page contains, determines which module chunks the components need using the registry clay-build-js exported, and includes only those chunks on the page, nesting them in a context in which require works. As a result, a Clay server can effectively generate valid bundles on-the-fly without compromising performance.