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

browserify-crawl

v0.3.8

Published

Recursively crawl and scan directories, compiling multiple js files into an output directory

Downloads

13

Readme

browserify-crawl

Recursively crawls a directory and browserifies, watches, source-maps, displays errors, minifies, and gzips multiple files based on filename matching. This is a pre-configured utility for developer convenience that is still very customizable.

const bcrawl = require('browserify-crawl')
const emitter = bcrawl({
   fileName: 'page.js',
   source: 'client/js',
   dest: 'public/js',
   watch: true,
   compress: true,
   browserify: {
     transforms: ['babelify']
   }
})

console.log('finding files')
emitter.on('build', (files) => console.log('finished initial build of', files.length, 'files'))
emitter.on('update', (file) => console.log('detected update on', file))
emitter.on('compile', (file) => console.log('compiled', file))
emitter.on('compress', (file) => console.log('compressed', file))
emitter.on('error', (err) => console.log('error', err.message))

The above will find all files named page.js in the client/js directory, even nested ones. It will then recreate a mirror directory structure in public/js with all the compiled files.

For example, if you have client/js/page.js and client/js/dashboard/page.js, then the compiler will create public/js/page.js and public/js/dashboard/page.js, which will be the built versions of the files. The compiler will also create public/js/page.js.map, public/js/page.js.gz, public/js/dashboard/page.js.map, and public/js/dashboard/page.js.gz.

bcrawl(options)

The options object can have these properties:

  • source: path of the input directory containing all your mainfiles (which may be in nested directories). Required.
  • dest: path of your output directory, typically public/js, dest, etc. Required.
  • fileName: name of the main-file(s) that you want to compile. Defaults to page.js. These are the root files that you actually want to include in your html in a script element.
  • browserify: an object of browserify options from the browserify api
  • watch: whether to run watchify on each file to recompile on any changes
  • compress: whether to uglify & gzip the compiled file (slower)
  • unassertify: whether to run unassertify (slower)
  • commonShakeify: whether to run common-shakeify (slower)
  • uglifyify: whether to run uglifyify (slower)

The return value is an event emitter that allows you to listen to the following events:

  • compile: a file has finished compling. Callback receives the full file path.
  • build: the full set of files have finished the initial build. Callback receives an array of all file paths
  • update: a file has been updated but not yet compiled
  • compress: a file has finished being minified and gzipped
  • error: an error has been caught, most likely a browserify parse error

Sample development watcher

const bcrawl = require('browserify-crawl')

const emitter = bcrawl({
  source: process.argv[2] || './client/js',
  dest: './public/client/js',
  compress: false,
  watch: true,
  fileName: 'page.js',
  browserify: {
    debug: true,
    paths: ['./client'],
    insertGlobals: true // minor speed-up
  }
})

const logTime = x => console.log(`[${new Date().toLocaleTimeString()}]`, x)
const time = new Date()
logTime('( ゚ヮ゚) compiling all files')
emitter.on('build', (files)  => logTime('(° ͜ʖ °) finished building ' + files + ' files in ' + (new Date() - time) / 1000 + ' seconds... now watching for changes'))
emitter.on('compile', (file) => logTime('compiled ' + file))
emitter.on('update', (file)  => logTime('updated  ' + file))
emitter.on('error', (err)  => logTime('error  ' + err.message))

Sample production builder

const bcrawl = require('browserify-crawl')

const emitter = bcrawl({
  source: process.argv[2] || './client/js',
  dest: './public/client/js',
  compress: true,
  watch: false,
  fileName: 'page.js',
  browserify: {
    transform: 'es2040',
    paths: ['./client']
  }
})

const logTime = x => console.log(`[${new Date().toLocaleTimeString()}]`, x)
const time = new Date()
logTime('( ゚ヮ゚) compiling all files')
emitter.on('build', (files)  => logTime('(° ͜ʖ °) finished building ' + files + ' files in ' + (new Date() - time) / 1000 + ' seconds!'))
emitter.on('compile', (file) => logTime('compiled ' + file))
emitter.on('error', (err)  => logTime('error  ' + err.message))