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.
npm install --save broccoli-multifilterThis package requires Node 6 or newer.
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.
-
class Multifilter: A Plugin subclass that implements a singlethis.buildAndCachehelper method, which you should call frombuild.-
Multifilter.buildAndCache(inputFilePaths, callback): For eachinputFilePat, callcallbackin sequence. This returns a promise, so be sure toreturnits return value frombuild.-
inputFilePaths: An array of strings identifying input files.While you will typically use input file paths relative to
this.inputPaths[0],Multifiltermakes no assumption about the meaning of these strings and simply treats them as opaque identifiers. -
callback(inputFilePath, outputDirectory): Your callback function to rebuild the file identified byinputFilePathand place the output file(s) intooutputDirectory. It is important that you write intooutputDirectoryand not intothis.outputPath.Every input file will get its own
outputDirectory, which will be empty on each rebuild. After calling your callbacks for eachinputFilePath,buildAndCachewill merge theoutputDirectoriesfor allinputFilePathsinto the plugin's output (this.outputPath), similar to broccoli-merge-trees with{ overwrite: false }.The
callbackfunction must return an object (or a promise to an object) of the form{ dependencies: dependencyPaths }
where
dependencyPathsis an array of paths to each file or directory that the compilation forinputFilePathdepends on.On rebuild,
buildAndCachemay re-use the output from the previous build instead of callingcallback, provided that none of the files or directories (and their contents, recursively) identified bydependencyPathshave changed.You must include the main input file itself in
dependencyPaths. Therefore,dependencyPathsmust always be non-empty. For example, if eachinputFilePathis the relative path to an input file (as is typical), you might return{ dependencies: [ [path.join(this.inputPaths[0], inputFilePath)].concat( dependenciesReturnedByTheCompiler ) ] }
-
-