我有一个插件,需要将一组JS文件从其Bower目录复制到Ember应用程序的/dist
根目录(这是用于确定与服务人员相关的规则)。我以为也许可以使用treeForApp
钩子(Hook),但是当我没有收到任何错误时,我也没有得到想要的结果。index.js
是:
const Funnel = require('broccoli-funnel');
module.exports = {
name: 'ember-upup',
treeForApp: function(tree) {
tree = new Funnel(tree, { include:
[
'bower_components/upup/dist/upup.min.js',
'bower_components/upup/dist/upup.sw.min.js'
]});
return this._super.treeForApp.call(this, tree);
},
最佳答案
看起来我的最初尝试还不是很遥远。为了使其正常工作,您需要像这样钩入treeForPublic
钩子(Hook):
const path = require('path');
const Funnel = require('broccoli-funnel');
const mergeTrees = require('broccoli-merge-trees');
const JS_FILES = ['upup.min.js', 'upup.sw.min.js'];
module.exports = {
treeForPublic: function() {
const upupPath = path.join(this.app.bowerDirectory, 'upup/dist');
const publicTree = this._super.treeForPublic.apply(this, arguments);
const trees = [];
if (publicTree) {
trees.push(publicTree);
}
trees.push(new Funnel(upupPath, {
include: JS_FILES,
destDir: '/'
}));
return mergeTrees(trees);
}
}
希望能有所帮助。