This repository has been archived by the owner on Jun 27, 2018. It is now read-only.
forked from gpoitch/ember-cli-html-minifier
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
60 lines (49 loc) · 1.89 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
var Funnel = require('broccoli-funnel');
var Filter = require('broccoli-filter');
var mergeTrees = require('broccoli-merge-trees');
var minify = require('html-minifier').minify;
var extend = require('util-extend');
function HtmlMinifierFilter(inputTree, options) {
if (!(this instanceof HtmlMinifierFilter)) {
return new HtmlMinifierFilter(inputTree, options);
}
this.inputTree = inputTree;
this.minifierOptions = extend(defaultMinifierOptions, options);
}
HtmlMinifierFilter.prototype = Object.create(Filter.prototype);
HtmlMinifierFilter.prototype.constructor = HtmlMinifierFilter;
HtmlMinifierFilter.prototype.extensions = ['html'];
HtmlMinifierFilter.prototype.targetExtension = 'html';
HtmlMinifierFilter.prototype.processString = function(string) {
return minify(string, this.minifierOptions);
};
var defaultMinifierOptions = {
collapseWhitespace : true,
removeComments : true,
minifyJS : true,
minifyCSS : true
};
function EmberCliHtmlMinifier(project) {
this.name = 'ember-cli-html-minifier';
}
EmberCliHtmlMinifier.prototype.included = function(app) {
this.app = app;
this.options = app.options.minifyHTML || {};
this.enabled = typeof this.options.enabled !== 'undefined' ? this.options.enabled : app.env === 'production';
};
EmberCliHtmlMinifier.prototype.postprocessTree = function(type, tree) {
if (type === 'all' && this.enabled) {
var htmlFiles = this.options.htmlFiles;
if(!htmlFiles || !Array.isArray(htmlFiles)){
var htmlFilePath = this.app.options.outputPaths.app.html || 'index.html';
htmlFiles = [htmlFilePath];
}
var htmlFileTree = new Funnel( tree, {
files: htmlFiles
});
var minifiedHtml = HtmlMinifierFilter(htmlFileTree, this.options.minifierOptions);
return mergeTrees([tree, minifiedHtml], { overwrite: true });
}
return tree;
};
module.exports = EmberCliHtmlMinifier;