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

common-bundler

v0.4.0

Published

Creates a common package from a collection of script bundles

Downloads

7

Readme

common-bundler

Creates a common package from a collection of scripts

Getting Started

$ npm i -D common-bundler

Example

The bundler is a little opinionated about how you structure your scripts but something like this is a good start:

.
└── src
    ├── bundles
    │   ├── bundleA
    │   │   ├── bundleADep.js
    │   │   └── main.js
    │   └── bundleB
    │       └── main.js
    └── common
        └── menu.js

Now just let the bundler do its thing

$ bundler src/bundles -o dist

The bundler will give you some info about what its doing and you’ll end up with a few scripts to include in whichever pages you want, this will let you include just what the page needs to work and not drag around kb of dependency unless you need them

.
└── dist
    ├── bundleA.js
    ├── bundleB.js
    └── common.js

In general you’ll need common and whichever bundle you need in a page, making sure common goes in first.

<script src="dist/common.js"></script>
<script src="dist/bundleA.js"></script>

Use npm scripts

You can use it a global module, but that kind-of sucks so add the build process to your npm scripts object in your package.json

{
    "scripts": {
        "build:scripts": "bundler src/bundles -o dist"
    }
}

Then let npm execute it

$ npm run build:scripts

API

Check the help to see the full list of options

$ bundler -h

-t --transform

Adds a transform to the browserify pipeline

Feel free to add multiple transforms, as usual the order is important

Note that there is generally no need to pass uglify, omitting the debug flag will tell the bundler to uglify up the scripts, currently just uses UglifyJS

$ bundler src/bundles -o dist -t flowcheck -t babelify

-d --debug

Sticks browserify into debug mode which leaves the build unminified and gives you source maps too

Having unminified and source maps is useful for something like babel that transpiles code as you’ll have access to human-readable transpiled code and the ES6 version that you’re writing

$ bundler src/bundles -o dist -d

--watch

Select a glob of files to watch for changes and run a build when they are updated

npm will tend to expand globs so specify it as a string and it’ll get passed through to glob and that’ll give a list of files to chokidar

To try and make sure the build isn’t stale the watcher will always try to fire a new bundle on save unless it’s already working, whereby it’ll wait until it’s finished and run a build sequentially to stop multiple builds if you’re saving quickly or updating multiple files concurrently.

$ bundler src/bundles -o dist --watch 'src/**/*.js'

-c --config

Specifies a configuration file to set up browserify

You can specify a custom file (such as .bundlerrc) if you like but using package.json will work just as well, just add a bundler key to your package config and they’ll get passed to browserify.

...,
"bundler": {
  "extensions": [
    ".js",
    ".jsx"
  ]
},
...
$ bundler src/bundles -o dist -c package.json

Enjoy responsibly!