-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgulpfile.js
93 lines (83 loc) · 2.72 KB
/
gulpfile.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
var gulp = require('gulp');
var esperanto = require('esperanto');
var plugins = require('gulp-load-plugins')({
rename: {
'gulp-angular-templatecache': 'templateCache',
'gulp-add-src': 'src'
}
});
var config = {
destination: 'dist',
baseDir: 'src/js',
entryFile: 'module.js',
templateFile: 'ribbon-templates.js',
outputFile: 'ribbon.js',
templateOutputFile: 'ribbon.tmpl.js',
path: function (file) {
return config.destination + '/' + file;
}
};
gulp.task('dev', ['build'], function () {
gulp.watch('src/js/**/*.js', ['build/javascript']);
gulp.watch('src/templates/*-template.html', ['build/javascript']);
gulp.watch('src/styles/*.css', ['build/styles']);
});
gulp.task('build', ['build/javascript', 'build/styles']);
gulp.task('build/javascript', ['build/templates'], function (cb) {
return esperanto
.bundle({
base: config.baseDir,
entry: config.entryFile
})
.then(function (result) {
var res = result.concat({
intro: '',
outro: ''
});
return plugins.file(config.outputFile, res.code, {src: true})
.pipe(plugins.babel())
.pipe(header())
.pipe(footer())
.pipe(gulp.dest(config.destination))
.pipe(plugins.src.append(config.path(config.templateFile)))
.pipe(plugins.concat(config.templateOutputFile))
.pipe(gulp.dest(config.destination));
});
});
gulp.task('build/templates', function () {
// TODO: Check https://github.com/kangax/html-minifier for additional options
return gulp
.src('src/**/*-template.html')
.pipe(plugins.htmlmin({
collapseWhitespace: true,
removeComments: true
}))
.pipe(plugins.templateCache({
filename: config.templateFile,
root: 'ribbon/',
standalone: true,
module: 'ribbon.templates'
}))
.pipe(header())
.pipe(footer())
.pipe(gulp.dest(config.destination));
});
gulp.task('build/styles', function () {
return gulp.src('src/styles/**/*.css')
.pipe(plugins.concat('ribbon.css'))
.pipe(gulp.dest(config.destination));
});
gulp.task('minify', ['build'], function () {
gulp.src([config.path(config.outputFile), config.path(config.templateOutputFile)])
.pipe(plugins.uglify())
.pipe(plugins.rename(function (path) {
path.extname = '.min.js';
}))
.pipe(gulp.dest(config.destination));
});
function header() {
return plugins.header('(function (angular) {\n');
}
function footer() {
return plugins.footer('\n}(angular));\n');
}