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

concatenate-js

v0.1.0

Published

Concatenate JavaScript with awesome debuggability.

Downloads

3

Readme

concatenate.js

Implements a technique to bundle large numbers of JS files into a single file while maintaining the original file boundaries and names inside development tools. Use this to make your JavaScript serving system be awesome during development without the complexity of source maps.

The module rovides a single function to concatenate a list of JavaScript files into a single output stream in a way that, when executed in the browser, maintains the illusion in JS development tools, that the files had been loaded as individual script tags.

Demo: http://jsbin.com/isozid/1/quiet

When would you use it

  • When you have too many JS files to make loading via script tags feasible (because the HTTP requests take too long) during development.
  • As a component of a script loader to deliver slightly modified JS files in a single response while maintaining the original files. (i.e. to serve CommonJS files to the browser.)
  • ONLY FOR DEVELOPMENT, DO NOT USE THIS IN PRODUCTION!

Usage

var js = require('./concatenate')([
  {
    content: 'function foo() {alert("foo")}',
    filename: 'js/foo.js'
  },
  {
    content: 'function bar() {alert("bar")}',
    filename: 'js/bar.js',
    hostname: 'app2'
  }
]);

Specifying the hostname is optional, the default is 'app'. Chrome Dev Tools groups JS files under the hostname.

How does it work

This is using multiple eval calls with @sourceURL annotations in a single output stream.

How about source maps

This is better than source maps under these circumstances:

  • Your input language is JS
  • You are not working with obfuscated JS

Why is it better:

  • This is the real deal. The browser acts like there were real files. No leaky abstractions.
  • Also: This is just super simple, no special parsing or anything like that required at any point in the process.

Limitations

When you have a syntax error at least V8 based browsers will not show you a line number.

Browser support

(For the generated JS)

  • Chrome Dev Tools
  • Safari Dev Tools
  • Firebug (Not recommended. It gets really slow with large numbers of files)

Advanced Usage

The exported function supports a second param which is a function that gets to modify the output after the eval was added. You may find this useful for i.e. adding CommonJS module wrappers. For an example see example_common_js_simulator.js.

Fine print