forked from feimosi/baguetteBox.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
136 lines (121 loc) · 3.92 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
var gulp = require('gulp'),
plugins = require('gulp-load-plugins')(),
browserSync = require('browser-sync'),
runSequence = require('run-sequence');
var src = {
css: ['./src/*.scss', './src/*.css'],
js: './src/*.js'
},
build = {
css: './build/css/',
js: './build/js/',
html: './build/'
},
dist = {
css: './dist/',
js: './dist/',
};
// CSS tasks
gulp.task('css', function() {
return gulp.src(src.css)
// Compile Sass
.pipe(plugins.if(/.scss/, plugins.sass({ style: 'compressed', noCache: true })))
// parse CSS and add vendor-prefixed CSS properties
.pipe(plugins.autoprefixer(["last 2 version", "> 1%", "ie 8", "ie 7", 'ff 3.6', 'Opera 12.1', 'Firefox ESR']))
// Concatenate all styles
.pipe(plugins.concat('baguetteBox.css'))
// Where to store the finalized CSS
.pipe(gulp.dest(build.css));
});
gulp.task('css-min', function() {
return gulp.src(src.css)
// Compile Sass
.pipe(plugins.if(/.scss/, plugins.sass({ style: 'compressed', noCache: true })))
// parse CSS and add vendor-prefixed CSS properties
.pipe(plugins.autoprefixer(["last 2 version", "> 1%", "ie 8", "ie 7", 'ff 3.6', 'Opera 12.1', 'Firefox ESR']))
// Minify CSS
.pipe(plugins.cssmin())
// Concatenate all styles
.pipe(plugins.concat('baguetteBox.min.css'))
// Where to store the finalized CSS
.pipe(gulp.dest(dist.css));
});
// JS tasks
gulp.task('js', function () {
return gulp.src(src.js)
// Run JSHint for syntax errors
.pipe(plugins.jshint())
.pipe(plugins.jshint.reporter('jshint-stylish'))
// Concatenate all JS files into one
.pipe(plugins.concat('baguetteBox.js'))
// Where to store the finalized JS
.pipe(gulp.dest(build.js));
});
gulp.task('js-min', function() {
return gulp.src(src.js)
// Run JSHint for syntax errors
.pipe(plugins.jshint())
.pipe(plugins.jshint.reporter('jshint-stylish'))
// Concatenate all JS files into one
.pipe(plugins.concat('baguetteBox.min.js'))
// Minify JS
.pipe(plugins.uglify({preserveComments: 'some'}))
// Where to store the finalized JS
.pipe(gulp.dest(dist.js));
});
// Bump to a new version
gulp.task('bump-minor', function () {
return gulp.src(['./bower.json', './package.json'])
.pipe(plugins.bump({type:'minor'}))
.pipe(gulp.dest('./'));
});
// Bump to a new version
gulp.task('bump-patch', function () {
return gulp.src(['./bower.json', './package.json'])
.pipe(plugins.bump({type:'patch'}))
.pipe(gulp.dest('./'));
});
// Update version number in project files
gulp.task('update-version', function () {
return gulp.src([build.css + '*.css',
build.js + '*.js',
dist.css + '*.css',
dist.js + '*.js'
], {
base: './'
})
.pipe(plugins.injectVersion({
replace: '%%INJECT_VERSION%%',
prepend: { toString: function() { return ''; } }
}))
.pipe(gulp.dest('./'));
});
// Watch files for changes
gulp.task('watch', ['browser-sync'], function() {
// Watch Sass files
gulp.watch(src.css, ['css']);
// Watch JS files
gulp.watch(src.js, ['js']);
});
// Live browser reload
gulp.task('browser-sync', ['js', 'css'], function () {
var files = [
build.html + '*.html',
build.css + '*.css',
build.js + '*.js'
];
browserSync.init(files, {
server: {
baseDir: "./build/"
}
});
});
// Default task
gulp.task('default', ['css', 'js', 'watch', 'browser-sync']);
gulp.task('release', function() {
runSequence('bump-minor', 'build', 'update-version');
});
gulp.task('patch', function() {
runSequence('bump-patch', 'build', 'update-version');
});
gulp.task('build', ['css', 'js', 'css-min', 'js-min']);