-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
53 lines (44 loc) · 1.34 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
'use strict';
const map = require('broccoli-stew').map;
const path = require('path');
const find = require('broccoli-stew').find;
const transform = require('fastboot-transform');
const mergeTrees = require('broccoli-merge-trees');
module.exports = {
name: require('./package').name,
included() {
this._super.included.apply(this, arguments);
let app = this._findHost();
this.addonOptions = app.options[this.name] || {};
this.plugins = this.addonOptions.plugins || [];
delete this.addonOptions.plugins;
this.plugins.forEach((plugin) => {
this.import(`vendor/plugins/${plugin}/ls.${plugin}.js`);
});
this.import(`vendor/lazysizes.js`);
},
treeForVendor(tree) {
let trees = [];
if (tree) {
trees.push(tree);
}
let lazyNodeTree = this.treeGenerator(
path.dirname(require.resolve('lazysizes'))
);
if (this.plugins.length > 0) {
let include = this.plugins.map(
(plugin) => `plugins/${plugin}/ls.${plugin}.js`
);
trees.push(transform(find(lazyNodeTree, { include })));
}
trees.push(
transform(
map(find(lazyNodeTree, 'lazysizes.js'), (content) => {
return `window.lazySizesConfig = ${JSON.stringify(this.addonOptions)};
${content}`;
})
)
);
return mergeTrees(trees, { overwrite: true });
},
};