-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
125 lines (111 loc) · 3.48 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
'use strict';
// Include Gulp & Tools We'll Use
var gulp = require('gulp');
var $ = require('gulp-load-plugins')();
var browserSync = require('browser-sync');
var reload = browserSync.reload;
var merge = require('merge-stream');
// Lint JavaScript
gulp.task('jshint', function () {
return gulp.src([
'app/*.js',
'app/*.html'
])
.pipe(reload({stream: true, once: true}))
.pipe($.jshint.extract()) // Extract JS from .html files
.pipe($.jshint())
.pipe($.jshint.reporter('jshint-stylish'))
.pipe($.if(!browserSync.active, $.jshint.reporter('fail')));
});
// Copy All Files At The Root Level (app)
gulp.task('copy', function () {
var app = gulp.src([
'app/*',
'!app/test',
'!app/precache.json',
'!app/**/build.log',
'!app/**/bower.json',
'!app/*.swp',
'!app/*.*~'
], {
dot: true
}).pipe(gulp.dest('dist'));
var bower = gulp.src([
'bower_components/**/*',
'!bower_components/**/{test,demo}/*',
'!bower_components/**/build.log',
'!bower_components/**/{README,CONTRIBUTING}.md',
'!bower_components/**/{package,bower}.json'
]).pipe(gulp.dest('dist/bower_components'));
var elements = gulp.src(['app/elements/**/*.html'])
.pipe(gulp.dest('dist/elements'));
var readme = gulp.src(['Readme.md'])
.pipe(gulp.dest('dist'));
return merge(app, bower, elements)
.pipe($.size({title: 'copy'}));
});
// Scan Your HTML For Assets & Optimize Them
gulp.task('html', function () {
var assets = $.useref.assets({searchPath: ['.tmp', 'app', 'dist']});
return gulp.src(['app/*.html', 'app/**/*.html', '!app/{elements,test}/**/*.html'])
// Replace path for vulcanized assets
//.pipe($.if('*.html', $.replace('elements/elements.html', 'elements/elements.vulcanized.html'))) // das bringt bei mir gar nix
.pipe(assets)
// Concatenate And Minify JavaScript
.pipe($.if('*.html', $.uglify({preserveComments: 'some'})))
// Concatenate And Minify Styles
// In case you are still using useref build blocks
.pipe($.if('*.html', $.cssmin()))
.pipe(assets.restore())
.pipe($.useref())
// Minify Any HTML
.pipe($.if('*.html', $.minifyHtml({
quotes: true,
empty: true,
spare: true
})))
// Output Files
.pipe(gulp.dest('dist'))
.pipe($.size({title: 'html'}));
});
// Vulcanize imports, so macht das großen bullshit
gulp.task('vulcanize', function () {
var DEST_DIR = 'dist';
return gulp.src(['dist/*.html'])
.pipe($.vulcanize({
stripComments: true,
inlineCss: true,
inlineScripts: true
}))
.pipe(gulp.dest(DEST_DIR))
.pipe($.size({title: 'vulcanize'}));
});
// Watch Files For Changes & Reload
gulp.task('serve', function () {
browserSync({
notify: false,
snippetOptions: {
rule: {
match: '<span id="browser-sync-binding"></span>',
fn: function (snippet) {
return snippet;
}
}
},
// Run as an https by uncommenting 'https: true'
// Note: this uses an unsigned certificate which on first access
// will present a certificate warning in the browser.
// https: true,
server: {
baseDir: ['.tmp', 'app'],
routes: {
'/bower_components': 'bower_components'
}
}
});
gulp.watch(['app/**/*.html'], reload);
gulp.watch(['app/styles/**/*.css'], ['styles', reload]);
gulp.watch(['app/elements/**/*.css'], ['elements', reload]);
gulp.watch(['app/{scripts,elements}/**/*.js'], ['jshint']);
gulp.watch(['app/images/**/*'], reload);
});