-
Notifications
You must be signed in to change notification settings - Fork 8
/
index.js
78 lines (70 loc) · 2.06 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/* jshint node: true */
'use strict';
var Funnel = require('broccoli-funnel');
var treeJson = require("broccoli-tree-to-json");
var MergeTrees = require("broccoli-merge-trees");
var replace = require("broccoli-replace");
var path = require("path");
module.exports = {
name: 'ember-cli-lazy-load',
blueprintsPath: function() {
return path.join(__dirname, 'blueprints');
},
included: function(app, parentAddon) {
this._super.included(app,parentAddon);
var target = (parentAddon || app);
// Now you can modify the app / parentAddon. For example, if you wanted
// to include a custom preprocessor, you could add it to the target's
// registry:
//
var options;
//shortcut for disable this
if(this.app.options.bundles === false){
options = false;
}else {
options = this.app.options.bundles = this.app.options.bundles || {};
}
},
contentFor: function(type,config) {
if (type === 'head-footer') {
return '<meta name="ember-asset-map" content="@@assetMap"/>';
}
},
postprocessTree: function(type,tree) {
if(type != "all"){
return tree;
}
var assets = {}
var workingTree = new Funnel(tree, {
getDestinationPath: function(relativePath) {
var list = relativePath.split(".").map((name)=>{
if(name.indexOf("bundle")>-1){
return "bundle"
}else {
return name;
}
});
var indexOfBundleStr = list.indexOf("bundle");
if( indexOfBundleStr > -1 && list[indexOfBundleStr+1] != "map" )
assets[list[indexOfBundleStr-1]] = relativePath;
return relativePath;
}
});
var indexTree = replace(workingTree, {
files: [
'**/*.html' // replace only html files in src
],
patterns: [
{
match: 'assetMap',
replacement: function(){
return encodeURIComponent(JSON.stringify(assets))
}
}
]
});
return new MergeTrees([workingTree,indexTree], {
overwrite: true
});
}
};