forked from tete-chercheuse/smart-cart
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
98 lines (85 loc) · 2.58 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
var gulp = require('gulp'),
jshint = require('gulp-jshint'),
rename = require('gulp-rename'),
uglify = require('gulp-uglify'),
babel = require("gulp-babel"),
postcss = require('gulp-postcss'),
cleanCSS = require('gulp-clean-css'),
cssbeautify = require('gulp-cssbeautify'),
autoprefixer = require('autoprefixer'),
karma = require('karma'),
del = require('del'),
browserSync = require('browser-sync').create(),
path = require('path');
// Source files
var SRC_JS = 'src/js/*.js';
var SRC_CSS = 'src/css/*.css';
// Destination folders
var DEST_JS = 'dist/js';
var DEST_CSS = 'dist/css';
// JS TASKS
// Lint JS
gulp.task('lint', function() {
return gulp.src(SRC_JS)
.pipe(jshint())
.pipe(jshint.reporter('default'))
.pipe(jshint.reporter('fail'));
});
// Build JS
gulp.task('build:js', ['clean:js', 'lint'], function() {
return gulp.src(SRC_JS)
.pipe(babel())
.pipe(gulp.dest(DEST_JS))
.pipe(uglify({ preserveComments: 'license' }))
.pipe(rename({ suffix: '.min' }))
.pipe(gulp.dest(DEST_JS))
});
// CSS TASKS
gulp.task('build:css', ['clean:css'], function() {
return gulp.src(SRC_CSS)
.pipe(postcss([autoprefixer({ browsers: ['last 10 versions'] })]))
.pipe(cssbeautify({ autosemicolon: true }))
.pipe(gulp.dest(DEST_CSS))
.pipe(cleanCSS({ compatibility: 'ie8' }))
.pipe(rename({ suffix: '.min' }))
.pipe(gulp.dest(DEST_CSS));
});
// CLEAN files
gulp.task('clean', function() {
gulp.start('clean:js', 'clean:css');
});
gulp.task('clean:js', function() {
return del([DEST_JS]);
});
gulp.task('clean:css', function() {
return del([DEST_CSS]);
});
// WATCH for file changes and rerun the task
gulp.task('watch', function() {
gulp.watch('./src/js/*.js', ['build:js']);
gulp.watch('./src/css/*.css', ['build:css']);
});
// TEST
gulp.task('test', function(done) {
new karma.Server({
configFile: __dirname + '/karma.conf.js',
singleRun: true
}, function() {
done();
}).start();
});
gulp.task('browser-sync', ['watch'], function() {
browserSync.init({
startPath: "./examples",
server: {
baseDir: "./"
}
});
gulp.watch("./examples/**/*").on("change", browserSync.reload);
gulp.watch("./src/**/*").on("change", browserSync.reload);
gulp.watch("./dist/**/*").on("change", browserSync.reload);
});
// DEFAULT task
gulp.task('default', function() {
gulp.start('build:js', 'build:css');
});