-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
70 lines (54 loc) · 1.89 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
var gulp = require('gulp');
var serve = require('gulp-serve');
var domSrc = require('gulp-dom-src');
var concat = require('gulp-concat');
var uglify = require('gulp-uglify');
var cheerio = require('gulp-cheerio');
var htmlMin = require('gulp-htmlmin');
var cleanCSS = require('gulp-clean-css');
var autoprefixer= require('gulp-autoprefixer');
var jshint = require('gulp-jshint');
var browserSync = require('browser-sync').create();
gulp.task('serve', ['browser-sync']);
gulp.task('css', function () {
domSrc({ file:'index.html', selector:'link', attribute:'href' })
.pipe(concat('app.full.min.css'))
.pipe(cleanCSS({debug: true}, function(details) {
console.log(details.name + ': ' + details.stats.originalSize);
console.log(details.name + ': ' + details.stats.minifiedSize);
}))
.pipe(gulp.dest('dist/'))
});
gulp.task('js', function () {
gulp.src(['js/**/*.js', '!js/**/*.min.js', '!bower_components/**/*.js'])
.pipe(jshint())
.pipe(jshint.reporter('default'))
.pipe(uglify())
.pipe(concat('app.full.min.js'))
.pipe(gulp.dest('dist/'));
});
gulp.task('html', function () {
gulp.src('index.html')
.pipe(cheerio(function ($) {
$('link').remove();
$('script[src^="js/"]').remove();
$('head').append('<link rel="stylesheet" href="app.full.min.css">');
$('body').append('<script src="app.full.min.js"></script>');
}))
.pipe(htmlMin({ collapseWhitespace:true }))
.pipe(gulp.dest('dist/'));
});
gulp.task('browser-sync', function () {
var files = [
'*.html',
'css/**/*.css',
//'/imgs/**/*.png',
'js/**/*.js'
];
browserSync.init(files, {
server: {
baseDir: './'
}
});
});
gulp.task('build', ['css', 'js', 'html']);