Ответ 1
ember-fetch делает это. Код немного сложный:
treeForVendor: function(tree) {
// Get the path of whatwg-fetch in node modules
var fetchPath = require.resolve('whatwg-fetch');
// use utility function to expand it into a pattern
var expandedFetchPath = expand(fetchPath);
// rename all the files in a tree containing files matching the pattern
var fetch = rename(find(expandedFetchPath), function(path) {
return 'whatwg-fetch/fetch.js'
});
// apply a template to each file in the tree and merge the trees
return mergeTrees([
new Template(fetch, templatePath, function variables(content) {
return {
moduleBody: content
};
})
]);
},
included: function(app) {
this.app = app;
this._super.included(app);
// import the tree created above in treeForVendor
app.import('vendor/whatwg-fetch/fetch.js', {
exports: {
default: [
'default',
'Headers',
'Request',
'Response'
]
}
});
}
Взято из https://github.com/stefanpenner/ember-fetch/blob/master/index.js
Надеюсь, что это поможет.