forked from oscarotero/jquery-cheatsheet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
100 lines (89 loc) · 2.74 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
var gulp = require('gulp'),
path = require('path'),
stylecow = require('gulp-stylecow'),
imagemin = require('gulp-imagemin'),
htmlmin = require('gulp-htmlmin'),
rename = require('gulp-rename'),
requirejs = require('requirejs'),
browserSync = require('browser-sync').create();
gulp.task('css', function() {
var config = require('./stylecow.json');
config.files.forEach(function (file) {
gulp.src(file.input)
.pipe(stylecow(config))
.pipe(rename(file.output))
.pipe(gulp.dest('./'))
.pipe(browserSync.stream());
});
});
gulp.task('js', function (ready) {
requirejs.optimize({
appDir: "source/js",
baseUrl: '.',
mainConfigFile : 'source/js/main.js',
dir: 'build/js',
removeCombined: true,
modules: [
{
name: 'main',
include: ['../../bower_components/almond/almond.js']
}
]
}, function () {
ready();
}, function (error) {
console.error('requirejs task failed', JSON.stringify(error))
process.exit(1);
});
});
gulp.task('img', function() {
gulp.src('build/*')
.pipe(imagemin())
.pipe(gulp.dest('build'));
});
gulp.task('html', function () {
gulp.src('build/**/*.html')
.pipe(htmlmin({
removeComments: true,
collapseWhitespace: true,
collapseBooleanAttributes: true,
removeAttributeQuotes: true,
removeRedundantAttributes: true,
useShortDoctype: true,
removeEmptyAttributes: true,
removeScriptTypeAttributes: true,
removeStyleLinkTypeAttributes: true,
removeEmptyElements: true,
minifyJS: true,
minifyCSS: true,
minifyURLS: {
output: 'rootRelative',
removeEmptyQueries: true
}
}))
.pipe(gulp.dest('build'));
});
gulp.task('sync', ['default'], function () {
browserSync.watch('source/**/*', function (event, file) {
if (event !== 'change') {
return;
}
switch (path.extname(file)) {
case '.yml':
case '.php':
browserSync.reload('*.html');
return;
default:
browserSync.reload(path.basename(file));
return;
}
});
browserSync.init({
port: process.env.APP_SYNC_PORT || 3000,
proxy: process.env.APP_URL || 'http://127.0.0.1:8000'
});
gulp.watch('source/**/*.js', ['js']);
gulp.watch('source/**/*.css', ['css']);
});
gulp.task('default', ['css', 'js']);
gulp.task('build', ['default', 'img', 'html']);