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

squash

v0.0.18

Published

Minimal NodeJS browser packager

Downloads

90

Readme

Squash

Why?

Squash was built to simplify building browser-compatible scripts from libraries written and tested with NodeJS.

How?

Squash locates your initial requires (the ones you want to execute in the browser) using the require.resolve algorithm used by Node. The code in that file is then searched for further dependencies and so on until all dependencies have been found. The code is then combined into a single script which will work as expected on the browser or even in Node.

Installation

npm install squash

Usage

Command Line

squash [options] <require[=alias]...>

Options

--coffee           Register the '.coffee' extension to support CoffeeScript
                   files (requires the 'coffeescript' module)
--compress     -c  Compress result with uglify-js (otherwise result is
                   beautified)
--help         -h  Print this notice
--file <file>  -f  A file to write the result to
--obfuscate    -o  Replaces all non-essential paths with dummy values
--relax        -r  Continues when modules cannot be found.  Useful if a
                   core module is required conditionally.
--watch        -w  Watch all found requires and rebuild on changes (for best
                   results an output file should be specified)

Example

To bundle src/index.coffee and all its dependencies to lib/project.js every time a dependency changes, and make it available as window.project (without the alias, it would be as window['./src']):

squash --coffee -f lib/project.js -w ./src=project

API

// build.js
var fs     = require('fs'),
    Squash = require('squash').Squash,
    squash = new Squash({ requires: {'./src': 'project'} });
fs.writeFileSync('lib/project.js', squash.squash(), 'utf8');

Browser

Having built your lib/project.js as above, you can run your project in the browser with:

<script src='lib/project.js'></script>
<script>
  project.do_awesome_things();
</script>

Node

You can also load packages with Node should you wish:

var project = require('./lib/project').project;
project.do_awesome_things();

Limitations

  • The 'compatibility layer' is currently very lightweight. Scripts are given global, module (= { exports: {} }), exports and require variables (also this === exports === modules.exports). Additional properties may be added to module to improve compatibility in future versions.

  • For the above reason, libraries such as jQuery that have vastly different dependencies on Node (jsdom etc.) than in the browser (DOM) do not work terribly well 'cross-platform' in this way. The easiest option here is to use the global variable to access the browser's window object, allowing you to include the library normally in the browser or attach it to global in Node.

  • There is no support for core Node modules such as path, fs, etc.

Bugs etc.

If you find a bug or think something could be done better don't hesitate to submit an issue and/or pull request.