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

brunch-static

v1.2.4

Published

Transform static files using brunch.

Downloads

1,314

Readme

Release

brunch-static

Transform static files using brunch.

Brunch is great for doing all sorts of transpiling, compiling, minifying, uglfying, combining, and other such activities on CSS and Javascript files. But what if you have a file that isn't CSS or Javascript (and doesn't transpile into those things), and you want to convert it into something else in your output? For example, maybe you don't want to write boring HTML when you could be using something more friendly (like jade). Brunch isn't really designed for that.

Enter brunch-static.

brunch-static is a plugin that makes it possible to write other plugins (called "processors") that can operate on files, outputting a "static" file (or files) in your output directory. Several brunch plugins attempt to solve this problem on their own, but they all suffer from some drawback. It is the aim of brunch-static to solve these problems, while making it easy to write a static plugin.

If you want to dive into writing your own processor, jump down. Otherwise, keep reading.

Installation

Install the plugin via npm with npm install --save-dev brunch-static

Or manually:

  • Add "brunch-static": "x.y.z" to package.json and run npm install
  • If you want to use the git version, add: "brunch-static": "git+ssh://[email protected]:bmatcuk/brunch-static.git"

Configuration

brunch-static's only config is a list of processors you want. In your brunch-config.coffee, you can add your static processors:

exports.config =
  ...
  plugins:
    static:
      pathTransform: ((filename) -> ...)
      processors: [
        ...
      ]
  • pathTransform (default: (f) -> f)

    pathTransform converts the input path into the output path. The input to this function will be the file's path, relative to one of Brunch's paths.watched directories. For example, if you've configured Brunch to watch the app directory and you have a file named app/pages/index.static.hbs, then pages/index.static.hbs will be passed into pathTransform. The value returned from this function will be joined with Brunch's paths.public to form the final output path. So, in the earlier example, if you wanted files under the pages subdirectory to appear in the root of the output, you might write a pathTransform such as: (f) -> path.relative 'pages', f. This would cause app/pages/index.static.hbs to output to public/index.html.

Available Processors

Below is a list of available processors. If you'd like your processor to be included in this list, create an issue with your project's URL and a description.

  • html-brunch-static

    Build static websites using brunch and your favorite templating language. Supports layouts and partial views and currently supports the following templating languages:

Writing brunch-static Processors

What Does brunch-static Do?

Ok, so, first, what do you get with brunch-static?

  1. brunch-static will write your output file(s), taking care to create subdirectories as necessary.
  2. brunch-static will not add any output to the brunch output files.

Processors

Processors are kind of similar to Brunch plugins theselves: an object that has certain members and methods. It's recommended that your project follows the naming scheme: whatever-brunch-static to make it easy to find in npm.

var MyStaticProcessor = function(config) { ... };

MyStaticProcessor.prototype = {
  handles: ...,
  compile: function(data, filename, callback) { ... }
};

// export a simple function to make it easier to include in brunch-config.coffee
module.exports = function(config) { return new MyStaticProcessor(config); };
  • handles

    handles is an anymatch that will be used to determine if your processor can handle a given file. This means it can either be a string (using globs), a regex, or a function that takes a single parameter (the filename) and returns true if your processor can handle it, or false otherwise.

  • compile

    compile is a function that will receive the contents of the file, the file's name, and a callback function. After you have finished processing the file's data, you will need to call the callback function with the following:

    • callback(err, files, dependencies)
      • err informs brunch-static when something goes wrong. If there were no issues, pass null.
      • files an array of objects in the form: [ {filename: "...", content: "..."}, {...}, ... ]
        • filename is the relative path of the output file. For example, if the input path was app/path/to/file.jade, filename might be something like app/path/to/file.html. brunch-static will automatically remove any of the "watched" paths from filename (like app in this example) and place it in the output directory. In this example, the final path might be public/path/to/file.html.
        • content is the result of your processor.
      • dependencies is an array of relative paths to any dependencies. For example, you might have dependencies on: [ 'app/path/to/layout.jade', 'app/path/to/partial.jade' ].

    If files is null or undefined, nothing will be written. If dependencies is null or undefined, no dependencies will be tracked.