UNPKG

1.17 kBJavaScriptView Raw
1/* jshint node: true */
2'use strict';
3
4var path = require('path');
5var Webpack = require('broccoli-webpack');
6var mergeTrees = require('broccoli-merge-trees');
7
8module.exports = {
9 name: 'emberfire',
10
11 included: function included(app) {
12 this._super.included(app);
13
14 // make sure app is correctly assigned when being used as a nested addon
15 if (app.app) {
16 app = app.app;
17 }
18 this.app = app;
19
20 this.app.import('vendor/firebase.amd.js');
21 this.app.import('vendor/shims/firebase.js');
22 },
23
24 treeForVendor: function(tree) {
25 var trees = [];
26
27 var firebase;
28
29 try {
30 var resolve = require('resolve');
31 firebase = resolve.sync('firebase/package.json', {
32 basedir: this.project.root
33 });
34 } catch (e) {
35 firebase = require.resolve('firebase/package.json');
36 }
37
38 trees.push(new Webpack([
39 path.dirname(firebase)
40 ], {
41 entry: './firebase-browser.js',
42 output: {
43 library: 'firebase',
44 libraryTarget: 'amd',
45 filename: 'firebase.amd.js'
46 }
47 }));
48
49 if (tree) {
50 trees.push(tree);
51 }
52
53 return mergeTrees(trees, { overwrite: true });
54 }
55};