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

compilify

v0.1.0

Published

A tool to make a simple compiler transform for Browserify

Downloads

33

Readme

compilify

This package allows you to easily create a new Browserify transform for a compiler, where "compiler" means any tool that takes in a file and transforms it somehow. Compilify will wrap your compiler, passing it the raw file and then packing the compiled result into a Browserify module to be require()'d. This allows you to bypass all the streaming boilerplate when you are using a framework that only operates synchronously on a whole file.

The compiler can take in an options object, and a set of default options can be specified when making the compilify transform. Compilify will handle two options for you, extensions and excludeExtensions, to restrict or allow the types of files your compiler will act on.

API

var compilify = require( 'compilify' )

compilify( compilerFunction [, defaultOptions ] )

compilerFunction should be a function of this form:

function compilerFunction( file [, options ] ) {
	
	// Perform transformation

	return transformedFile

}

options will be an object containing options that are passed in when the Browserify transform is invoked. If an option is not set via Browserify, it will be populated from the defaultOptions object. If there are no options or default options, options will be an empty object.

Options handled by compilify

{
	extensions: [ Array of strings ],
	excludeExtensions: [ Array of strings ]
}

If neither of these options are set, your transform will operate on all files. If set, these options will also be passed through to your compiler function.

extensions:

Setting this option to an array of file extensions will restrict your transform to operating on files that end with one of those extensions.

excludeExtensions:

Setting this option to an array of file extensions will exclude files ending with one of those extensions from being operated on by your transform. If a file extension is set in both extensions and excludeExtensions, excludeExtensions will override.

Example

var compilify = require( 'compilify' )

compilify( myCompiler, { extensions: [ '.html', '.tmpl' ] } )

Usage

Creating a compiler transform

// package 'foobarify'

var compilify = require( 'compilify' )

function foobarCompiler( file ) {

	return file.replace( 'foo', 'bar' )

}

module.exports = compilify( foobarCompiler )

Creating a transform with options

// package 'foobarify'

var compilify = require( 'compilify' )

function foobarCompiler( file, options ) {

	return file.replace( 'foo', options.replacement )

}

// Setting default to be 'bar'
module.exports = compilify( foobarCompiler, { replacement: 'bar' } )

Using the transform

On the command line

$ browserify -t foobarify main.js

With the Browserify API

var foobarify = require( 'foobarify' )

var b = browserify( )
b.add( 'main.js' )
b.transform( foobarify )
b.bundle( ).pipe( process.stdout )

Passing options

$ browserify -t [ foobarify --replacement "baz" ] main.js
var foobarify = require( 'foobarify' )

var b = browserify( )
b.add( 'main.js' )
b.transform( { replacement: 'baz' }, foobarify )
b.bundle( ).pipe( process.stdout )