-
Notifications
You must be signed in to change notification settings - Fork 0
/
ng2Inlinify.js
53 lines (49 loc) · 1.19 KB
/
ng2Inlinify.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
var ng2TemplateParser = require('gulp-inline-ng2-template/parser');
var through = require('through2');
var htmlMinifier = require('html-minifier');
var sass = require('node-sass');
//Setting options:
var ng2TemplateParserOptions = {
target: 'es5',
useRelativePaths: true,
templateProcessor: minifyTemplate,
styleProcessor: sassProcessor
};
module.exports = function (file) {
return through(function (buf, enc, next){
ng2TemplateParser({contents: buf, path: file}, ng2TemplateParserOptions)((err,result) => {
this.push(result);
process.nextTick(next);
});
});
};
function minifyTemplate(ext, file, cb) {
try {
var minifiedFile = htmlMinifier.minify(file, {
collapseWhitespace: true,
caseSensitive: true,
removeComments: true,
removeRedundantAttributes: true
});
cb(null, minifiedFile);
} catch (err) {
cb(err);
}
};
function sassProcessor(ext, file, cb) {
if (ext[0] === '.scss') {
sass.render({
data: file
}, (err, result) => {
if (err) {
console.log(err.status);
console.log(err.column);
console.log(err.message);
console.log(err.line);
cb(err);
} else {
cb(null, result.css);
}
});
}
};