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

asbundle

v2.7.0

Published

A minimalistic CommonJS bundler

Downloads

368

Readme

asbundle

donate License: ISC Build Status Greenkeeper badge

A minimalistic CommonJS bundler.


This module is a perfect ascjs companion to create CommonJS bundles.

Passing a single ESM/CJS source file as path name, it will produce a lightweight, optimized, and minifier friendly bundle, to consume right away without needing global require or runtime discovered CommonJS dependencies.

Goals

  • be as simple as possible, but not simpler
  • make creation of small modules written in ESM a no brainer
  • enable .js files as ESM everywhere, following a simple folder convention
  • produce files compatible with most common bundlers and tools (Babel, Webpack, UglifyJS, etc)

Example of a basic module based on ascjs and asbundle.

Non-Goals

  • replace Babel, Webpack, Rollup, or any other tool. Let them do complicated things when needed
  • transpile anything else than ESM import/export declarations

How to

You can use asbundle as binary utility or as module.

npm install -g asbundle

# to see what you can do
asbundle --help

As executable, you can use asbundle to output, or save, a bundle entry point.

asbundle source-file.js           # writes bundle contents to STDOUT
asbundle source-file.js bundle.js # outputs to bundle.js

As module, you can require it and use it to obtain a bundle string.

const asbundle = require('asbundle');

asbundle(sourceFileName);

Features

  • extremely lightweight, based on babylon for performance and reliability
  • it uses ascjs to automatically transform, when needed, ES2015+ modules into CommonJS code
  • understands both relative files and installed packages too (based on require.resolve(...))
  • reproduces a modern and minimalistic CommonJS environments ideal for browsers
  • compatible with Babel __esModule and .default convention

Constrains

  • same constrains of ascjs
  • Node core modules are not brought to the bundle, if a module cannot be resolved as file name it throws

Example

This module can transform main.js entry file via asbundle main.js out.js:

// main.js
import func, {a, b} from './module.js';
const val = 123;
export default function test() {
  console.log('asbundle');
};
export {func, val};

// module.js
export const a = 1, b = 2;
export default function () {
  console.log('module');
};

into the following bundle:

// out.js => 266 bytes minified & gzipped
(function (cache, modules) {
  function require(i) { return cache[i] || get(i); }
  function get(i) {
    var exports = {}, module = {exports: exports};
    modules[i].call(exports, window, require, module, exports);
    return (cache[i] = module.exports);
  }
  var main = require(0);
  return main.__esModule ? main.default : main;
}([],[function (global, require, module, exports) {
// main.js
'use strict';
const func = (m => m.__esModule ? m.default : m)(require(1));
const {a, b} = require(1);
const val = 123;
function test() {
  console.log('asbundle');
}
Object.defineProperty(exports, '__esModule', {value: true}).default = test;
exports.func = func;
exports.val = val;
},function (global, require, module, exports) {
// module.js
'use strict';
const a = 1, b = 2;
exports.a = a;
exports.b = b;
Object.defineProperty(exports, '__esModule', {value: true}).default = function () {
  console.log('module');
};
}]));

The main module is returned and executed as default entry so it becomes easy to publish as global variable for Web purposes too.

Add a const myModule = prefix to the bundled code and use it right away.