-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
142 lines (119 loc) · 4.09 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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
//Experimental
/*jslint node: true */
var gulp = require('gulp');
var concat = require('gulp-concat');
var uglify = require('gulp-uglify');
var imagemin = require('gulp-imagemin');
var less = require('gulp-less');
var gCheerio = require('gulp-cheerio');
var ngHtml2js = require("gulp-ng-html2js");
var ngmin = require('gulp-ngmin');
var htmlmin = require('gulp-htmlmin');
var cssmin = require('gulp-cssmin');
var packagejson = require('./package.json');
var streamqueue = require('streamqueue');
var rimraf = require('rimraf');
var rename = require('gulp-rename');
var jshint = require('gulp-jshint');
var jasmine = require('gulp-jasmine');
var stylish = require('jshint-stylish');
var domSrc = require('gulp-dom-src');
var htmlminOptions = {
collapseBooleanAttributes: true,
collapseWhitespace: true,
removeAttributeQuotes: true,
removeComments: true,
removeEmptyAttributes: true,
// removeRedundantAttributes: true,
removeScriptTypeAttributes: true,
removeStyleLinkTypeAttributes: true
};
gulp.task('clean', function() {
rimraf.sync('dist');
});
gulp.task('css', ['clean'], function() {
return gulp.src('app.less')
.pipe(less())
.pipe(cssmin({keepSpecialComments: 0}))
.pipe(rename('app.full.min.css'))
.pipe(gulp.dest('dist/'));
});
gulp.task('js', ['clean'], function() {
var templateStream = gulp.src(['!node_modules/**','!index.html','!_SpecRunner.html','!.grunt/**','!dist/**','!bower_components/**','**/*.html'])
.pipe(htmlmin(htmlminOptions))
.pipe(ngHtml2js({
moduleName: packagejson.name
}));
var jsStream = domSrc({file:'index.html',selector:'script[data-build!="exclude"]',attribute:'src'});
var combined = streamqueue({ objectMode: true });
combined.queue(jsStream);
combined.queue(templateStream);
return combined.done()
.pipe(concat('app.full.min.js'))
.pipe(ngmin())
.pipe(uglify())
.pipe(gulp.dest('dist/'));
/*
Should be able to add to an existing stream easier, like:
gulp.src([... partials html ...])
.pipe(htmlmin())
.pipe(ngHtml2js())
.pipe(domSrc(... js from script tags ...)) <-- add new files to existing stream
.pipe(concat())
.pipe(ngmin())
.pipe(uglify())
.pipe(gulp.dest());
https://github.com/wearefractal/vinyl-fs/issues/9
*/
});
gulp.task('indexHtml', ['clean'], function() {
return gulp.src('index.html')
.pipe(gCheerio(function ($) {
$('script[data-remove!="exclude"]').remove();
$('link').remove();
$('body').append('<script src="app.full.min.js"></script>');
$('head').append('<link rel="stylesheet" href="app.full.min.css">');
}))
.pipe(htmlmin(htmlminOptions))
.pipe(gulp.dest('dist/'));
});
gulp.task('images', ['clean'], function(){
return gulp.src('img/**')
.pipe(imagemin())
.pipe(gulp.dest('dist/'));
});
gulp.task('fonts', ['clean'], function(){
return gulp.src('bower_components/font-awesome/fonts/**')
.pipe(gulp.dest('dist/bower_components/font-awesome/fonts/'));
});
gulp.task('jshint', function(){
gulp.src(['!node_modules/**','!.grunt/**','!dist/**','!bower_components/**','**/*.js'])
.pipe(jshint())
.pipe(jshint.reporter(stylish));
});
gulp.task('build', ['clean', 'css', 'js', 'indexHtml', 'images', 'fonts']);
/*
-specifying clean dependency on each task is ugly
https://github.com/robrich/orchestrator/issues/26
-gulp-jasmine needs a phantomjs option
https://github.com/sindresorhus/gulp-jasmine/issues/2
*/
/*
"gulp-dom-src": "~0.1.0",
"gulp-concat": "~2.1.7",
"gulp-uglify": "~0.2.1",
"gulp-cssmin": "~0.1.3",
"gulp-imagemin": "~0.1.5",
"gulp-less": "~1.2.2",
"gulp-cheerio": "~0.2.0",
"gulp-rename": "~1.2.0",
"gulp-ng-html2js": "~0.1.6",
"gulp-ngmin": "~0.1.2",
"gulp-htmlmin": "~0.1.2",
"gulp-jshint": "~1.5.0",
"gulp-jasmine": "~0.2.0",
"jshint-stylish": "~0.1.5",
"rimraf": "~2.2.6",
"streamqueue": "0.0.5",
"gulp": "~3.5.5"
*/