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

includer

v0.1.1

Published

Concat javascript with include statements

Downloads

7

Readme

Includer NPM version Build Status Dependency Status Code Climate

Concatenate JavaScript files with inline include statements.

Introduction

When writing an application, it is a good idea to keep source files separate for easier maintenance. However, when deploying an application, it's better to combine those files for fewer http requests.

Concatenation is a fairly simple problem, but what to concatenate where is a little trickier. When files require that other files proceed them, it becomes necessary to explicitly describe the concatenation order.

Maintaining a list of files in a build task or a config file is error prone and cumbersome. The heirarchy of which files depend on which other files must be maintained in the developer's head, and distract from development.

Rather than using external lists for concatenating files, Includer uses in-file include statements.

Installation

npm install includer --save-dev

Example

Suppose we want to concatenate these files together.

// app.js                    pages/home.js              pages/about.js
   var App = new Site();     App.home = new Page();     App.about = new Page();
   include('./pages/*');
   App.start();

When app.js is run through Includer, it will output the following.

(function(){
	var App = new Site();
	(function(){
		App.home = new Page();
	})();
	(function(){
		App.about = new Page();
	})();
	App.start();
})();

Usage

includer(filepath, [options], callback)

var includer = require('includer');

// options is optional
includer('path/to/entry.js', options, function (err, data) {
	// data is the concatenated and included file contents.
	// err is an Error object or null.
});

Include Syntax

include('./a.js');  // Paths are relative to the current file.
include('b.js');    // This is equivalent './b.js'.
include('./c');     // If no extension is found, '.js' will be used.
include("./d.js");  // Single or double quotes are supported.
include('../e.js'); // Upwards directory traversal is supported.
include('./f');
include('./f.js');  // Duplicates will only be included once.
include('./*.js');  // node-glob patterns are supported.

Options

separator

includer(filepath, {
	separator : '\n\n\n'
}, cb);

By default, all files are joined together by a \n. To change this, use the seperator option.

wrap

includer(filepath, {
	wrap : function (src) {
		return '(function(){' + src + '})()';
	}
}, cb);

Includer will wrap all files in an IIFE by default. To change the wrapping for files, use the wrap option.

The wrap option method will be called with the file's included contents as the only argument. It should return a string with the wrapped file contents.

To not wrap files, simply return the file's included contents as is.

includer(filepath, {
	wrap : function (src) {
		return src;
	}
}, cb);

debug

includer(filepath, {
	debug : true
}, cb);

Sometimes included globs have no matches. Includer will skip these globs silently.

If the debug option is true, a notification will be logged to the console when globs have no matches.

If the debug option is a function, it will be called with the debug message as the only parameter.

includer(filepath, {
	debug : function (message) {
		logs.push(message);
	}
}, cb);

paths

By default, all include() paths are relative to the current file.

However, relative paths become unwieldy when files are far apart.

include('../../../../../../scripts/src/config/file.js');

With the paths option, you can specify path mappings. These mappings are relative to the current working directory.

includer(filepath, {
	paths : {
		config : 'scripts/src/config'
		vendor : 'vendor/libs/js'
	}
}, cb);

To use the path mappings, prefix an include() with @ and the mapping name.

include('@config/file.js');   // CWD/scripts/src/config/file.js
include('@vendor/jquery.js'); // CWD/vendor/libs/js/jquery.js

A @base mapping to the current working directory is provided for free.

include('@base/file.js'); // CWD/file.js

Alternatives

For other tools that are tackling the same problem in different ways, see r.js, browserify, and grunt-neuter.

Credits

Includer was inspired by grunt-neuter.

Changelog

See the changelog

License

MIT License