node.jsember-clibroccolijs

Removing some files from a broccoli tree


I am using ember-cli and broccoli.

A tree is generated containing all of the files from my application. This tree is passed to broccoli-manifest to generate a HTML5 application cache manifest file. However, I would like to exclude some of the files from being written to the manifest (they shouldn't be available offline - a FALLBACK is instead specified in the manifest).

My first thought was to submit a pull request to broccoli-manifest allowing you to pass an option containing a list of files to ignore (e.g. not output into the manifest).

Then it occurred to me that perhaps a more broccoli way to approach it would be to somehow filter the tree before passing it in to broccoli-manifest.

e.g. something like:

var completeTree = app.toTree();
var filteredTree = imaginaryFilteringFunction(completeTree, {
  exclude: ['assets/is-online.json']
});
module.exports = mergeTrees([completeTree, writeManifest(filteredTree, {
  fallback: ['assets/is-online.json assets/offline.json']
})]);

Does something like my imaginaryFilteringFunction exist in broccoli land? Should it? Or should I go about this in a different way?


Solution

  • I asked the same question on the ember.js discussion forum and rwjblue was kind enough to provide me with the answer which was to use broccoli-file-remover.

    e.g.

    var removeFile = require('broccoli-file-remover');
    
    var filteredTree = removeFile(completeTree, {
      paths: ['assets/is-online.json']
    });