Code Monkey home page Code Monkey logo

broccoli's Introduction

Broccoli

Build Status

A fast, reliable asset pipeline, supporting constant-time rebuilds and compact build definitions. Comparable to the Rails asset pipeline in scope, though it runs on Node and is backend-agnostic. For background and architecture, see the introductory blog post.

For the command line interface, see broccoli-cli.

This is 0.x beta software.

Installation

npm install --save-dev broccoli
npm install --global broccoli-cli

Getting Started

Check out broccoli-sample-app.

Brocfile.js

A Brocfile.js file in the project root contains the build specification. It should export a tree which may simply be the directory path (as a string). To build more advanced output trees you may want to use some of the plugins listed below.

The following would export the app/ subdirectory as a tree:

module.exports = 'app'

Alternatively, the following would export the app/ subdirectory as appkit/:

var pickFiles = require('broccoli-static-compiler')

module.exports = pickFiles('app', {
  srcDir: '/',
  destDir: 'appkit'
})

Plugins

More plugins may be found under the broccoli-plugin keyword on npm.

Running Broccoli, Directly or Through Other Tools

Helpers

Shared code for writing plugins.

Plugin API Specification

Broccoli defines a single plugin API: a tree. A tree object represents a tree (directory hierarchy) of files that can be regenerated on each build.

By convention, plugins will export a function that takes one or more input trees, and returns an output tree object.

A tree object must supply two methods that will be called by Broccoli:

tree.read(readTree)

The .read method must return a path or a promise for a path, containing the tree contents.

It receives a readTree function argument from Broccoli. If .read needs to read other trees, it must not call otherTree.read directly. Instead, it must call readTree(otherTree), which returns a promise for the path containing otherTree's contents. It must not call readTree again until the promise has resolved; that is, it cannot call readTree on multiple trees in parallel.

Broccoli will call the .read method repeatedly to rebuild the tree, but at most once per rebuild; that is, if a tree is used multiple times in a build definition, Broccoli will reuse the path returned instead of calling .read again.

The .read method is responsible for creating a new temporary directory to store the tree contents in. Subsequent invocations of .read should remove temporary directories created in previous invocations.

tree.cleanup()

For every tree whose .read method was called one or more times, the .cleanup method will be called exactly once. No further .read calls will follow .cleanup. The .cleanup method should remove all temporary directories created by .read.

Debugging

Errors

When it is know which file caused a given error, plugin authors can make errors easier to track down by setting the .file property on the generated error.

This .file property is used by both the console logging, and the server middleware to display more helpful error messages.

Descriptive Naming

As of 0.11 Broccoli prints a log of any trees that took a significant amount of the total build time to assist in finding which trees are consuming the largest build times.

To determine the name to be printed Broccoli will first look for a .description property on the plugin instance then fall back to using the plugin constructor's name.

Security

  • Do not run broccoli serve on a production server. While this is theoretically safe, it exposes a needlessly large amount of attack surface just for serving static assets. Instead, use broccoli build to precompile your assets, and serve the static files from a web server of your choice.

Get Help

  • IRC: #broccolijs on Freenode
  • Twitter: mention @jo_liss with your question
  • GitHub: Open an issue on a specific plugin repository, or on this repository for general questions.

License

Broccoli was originally written by Jo Liss and is licensed under the MIT license.

The Broccoli logo was created by Samantha Penner (Miric) and is licensed under CC0 1.0.

broccoli's People

Contributors

ericf avatar hinaria avatar jgwhite avatar jnicklas avatar joliss avatar jsphm avatar kaspertidemann avatar krisselden avatar mjackson avatar rwjblue avatar shanielh avatar simonexmachina avatar sindresorhus avatar stefanpenner avatar twokul avatar xulai avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.