Home

Awesome

broccoli-multifilter

Build Status Build status

This is a helper base class for Broccoli plugins similar to broccoli-filter. The broccoli-filter base class maps 1 input file into 1 output file at a time. As a result, plugins for compilers that have include directives to include other dependent files cannot use broccoli-filter, since broccoli-filter's caching logic cannot accomodate dependencies. By contrast, broccoli-multifilter allows you to provide a list of dependencies for each input file, thereby mapping m input files into n output files at a time.

Installation

npm install --save broccoli-multifilter

This package requires Node 6 or newer.

Usage example

let Multifilter = require("broccoli-multifilter");

class MyPlugin extends Multifilter {
  build() {
    let inputFiles = ["foo.js"];

    return this.buildAndCache(
      inputFiles,
      (inputFile, outputDirectory) => {
        let fullInputPath = path.join(this.inputPaths[0], inputFile);
        let fullOutputPath = path.join(outputDirectory, inputFile);

        // Compile into the outputDirectory
        fs.copyFileSync(fullInputPath, fullOutputPath);

        return {
          dependencies: [
            fullInputPath,
            path.join(this.inputPaths[0], "included.js")
          ]
        };
      }
    );
  }
}

The file "foo.js" will be rebuilt using the callback whenever "foo.js" or "included.js" change.

Reference