This repository has been archived by the owner on Jan 12, 2024. It is now read-only.
/
inline-ng-templates.js
65 lines (60 loc) · 1.81 KB
/
inline-ng-templates.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
const gulp = require('gulp');
const inliner = require('gulp-inline-ng2-template');
const pug = require('pug');
const sass = require('node-sass');
const autoprefixer = require('autoprefixer');
const postcss = require('postcss');
const {dirname} = require('path');
const seq = require('gulp-sequence');
const conf = {
src: './src/**/*.ts',
dest: './.tmp/src-inlined-templates',
autoprefixer: {
browsers: 'last 1000 versions',
grid: true
},
inliner: {
useRelativePaths: true,
templateExtension: '.pug',
indent: 0,
removeLineBreaks: true,
templateProcessor(path, ext, contents, cb) {
try {
const rendered = pug.render(contents, {
filename: path,
doctype: 'html'
});
setImmediate(cb, null, rendered.trim());
} catch (e) {
setImmediate(cb, e);
}
},
styleProcessor(path, ext, contents, cb) {
sass.render({
data: contents,
outputStyle: 'compressed',
includePaths: [dirname(path)],
linefeed: 'lf'
}, (err, sassOutput) => {
if (err) {
return cb(err);
}
postcss(autoprefixer(conf.autoprefixer)).process(sassOutput.css)
.then(r => cb(null, r.css))
.catch(cb);
});
}
}
};
gulp.task('inline-templates', ['clean:tmp:src-inlined-templates'], () => {
return gulp.src(conf.src)
.pipe(inliner(conf.inliner))
.pipe(gulp.dest(conf.dest));
});
gulp.task('inline:compile', cb => {
seq(
'inline-templates',
['compile:esm5', 'compile:esm2015'],
cb
);
});