最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Exclude folders from builds in Brocfile - Stack Overflow

programmeradmin3浏览0评论

Is there a way to exclude a folder from a build in a Brocfile (or any other place). The use case is packaging, where I have an app made of sub-apps within pods. eg.

/app/modules/ponents
/app/modules/app1
/app/modules/app2
/app/modules/app3

I'd like to build them all when environment is set to 'development' or only eg. 'app1' when environment is 'app1'. Any suggestions?

I have tried different binations of broccoli-file-remover, broccoli-funnel and broccoli-merge-trees to no avail.

var removeFile = require('broccoli-file-remover');

module.exports = removeFile(app.toTree(), {
    paths: ['app/modules/pod1/', 'app/modules/pod2/']
});

Is there a way to exclude a folder from a build in a Brocfile (or any other place). The use case is packaging, where I have an app made of sub-apps within pods. eg.

/app/modules/ponents
/app/modules/app1
/app/modules/app2
/app/modules/app3

I'd like to build them all when environment is set to 'development' or only eg. 'app1' when environment is 'app1'. Any suggestions?

I have tried different binations of broccoli-file-remover, broccoli-funnel and broccoli-merge-trees to no avail.

var removeFile = require('broccoli-file-remover');

module.exports = removeFile(app.toTree(), {
    paths: ['app/modules/pod1/', 'app/modules/pod2/']
});
Share Improve this question asked Jun 6, 2015 at 18:43 WooDzuWooDzu 4,8666 gold badges33 silver badges62 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 4

Ah, so after actually thinking about this clearly, everything is actually working exactly as expected in my previous example.

I clearly wasn't paying enough attention. app.toTree() is far too late to perform this operation, as everything has already been built and concated.

Luckily, ember-cli does enable addons to modify the appropriate trees at various life cycle milestones.

See: https://github./ember-cli/ember-cli/blob/master/ADDON_HOOKS.md for more details on which hooks are currently available.

The hook that should do the trick is Addon.prototype.postprocessTree. Now we have two choices, we can build a standalone addon, via ember addon or we can create a light-weight in-repo addon via ember g in-repo-addon. Typically for these types of situations, I prefer in-repo-addons as they don't require a second project, but otherwise they are the same.

  1. ember g in-repo-addon remove
  2. we need to install broccoli-stew via npm install --save broccoli-stew
  3. include it var stew = require('broccoli-stew');
  4. add hook postprocessTree to the add-on
  5. when the postprocessTree is for the type we care about, use broccoli-stew to remove the directories we no longer care care.

The resulting pull request: https://github./WooDzu/ember-exclude-pod/pull/1

Note: I noticed template wasn't one of the types available in postprocess, so I added it: https://github./ember-cli/ember-cli/pull/4263 (should be part of the next ember-cli release)

Note: we really do want an additional hook Addon.prototype.preprocessTree, as to ignore the files before we even build them. I have opened a related issue: https://github./ember-cli/ember-cli/issues/4262

output of the above steps

var stew = require('broccoli-stew');

module.exports = {
  name: 'remove',

  isDevelopingAddon: function() {
    return true;
  },

  postprocessTree: function(type, tree){
    if (type === 'js' || type === 'template')   {
      return stew.rm(tree, '*/modules/pod{1,2}/**/*');
    } else {
      return tree;
    }
  }

};

I am pretty confident broccoli-stew's rm will handle this correctly.

https://github./stefanpenner/broccoli-stew/blob/master/lib/rm.js#L4-L40 there are even tests that test a very similar scenario: https://github./stefanpenner/broccoli-stew/blob/master/tests/rm-test.js#L48-L57

var stew = require('broccoli-stew');
module.exports = stew.rm(app.tree(), 'app/modules/{pod1,pod2}');

If this doesn't work, feel free to open an issue on broccoli-stew. Be sure to provide a running example though

This is really late, but I created a Broccoli plugin to do just this. It's available at https://www.npmjs./package/broccoli-rm.

(The trick is to detect whether an excluded path is a folder, and then use a glob match to make sure that none of the children of the folder get symlinked during copying.)

var rm = require('broccoli-rm');
var input = app.toTree();
module.exports = output = rm([input], {
   paths: ['app/modules/pod1', 'app/modules/pod2']
});
发布评论

评论列表(0)

  1. 暂无评论